4 // Copyright (c) 2002 Alan Hawrylyshen
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 /*************************** UDP networking stuff *******************/
43 typedef int socklen_t
;
45 #define errno WSAGetLastError()
47 typedef SOCKET Socket
;
49 #define EWOULDBLOCK WSAEWOULDBLOCK
50 #define EINPROGRESS WSAEINPROGRESS
51 #define EALREADY WSAEALREADY
52 #define ENOTSOCK WSAENOTSOCK
53 #define EDESTADDRREQ WSAEDESTADDRREQ
54 #define EMSGSIZE WSAEMSGSIZE
55 #define EPROTOTYPE WSAEPROTOTYPE
56 #define ENOPROTOOPT WSAENOPROTOOPT
57 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
58 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
59 #define EOPNOTSUPP WSAEOPNOTSUPP
60 #define EPFNOSUPPORT WSAEPFNOSUPPORT
61 #define EAFNOSUPPORT WSAEAFNOSUPPORT
62 #define EADDRINUSE WSAEADDRINUSE
63 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
64 #define ENETDOWN WSAENETDOWN
65 #define ENETUNREACH WSAENETUNREACH
66 #define ENETRESET WSAENETRESET
67 #define ECONNABORTED WSAECONNABORTED
68 #define ECONNRESET WSAECONNRESET
69 #define ENOBUFS WSAENOBUFS
70 #define EISCONN WSAEISCONN
71 #define ENOTCONN WSAENOTCONN
72 #define ESHUTDOWN WSAESHUTDOWN
73 #define ETOOMANYREFS WSAETOOMANYREFS
74 #define ETIMEDOUT WSAETIMEDOUT
75 #define ECONNREFUSED WSAECONNREFUSED
76 #define ELOOP WSAELOOP
77 #define EHOSTDOWN WSAEHOSTDOWN
78 #define EHOSTUNREACH WSAEHOSTUNREACH
79 #define EPROCLIM WSAEPROCLIM
80 #define EUSERS WSAEUSERS
81 #define EDQUOT WSAEDQUOT
82 #define ESTALE WSAESTALE
83 #define EREMOTE WSAEREMOTE
85 typedef LONGLONG Int64
;
90 static const Socket INVALID_SOCKET
= -1;
91 static const int SOCKET_ERROR
= -1;
94 int closesocket( Socket fd
);
97 typedef int socklen_t
;
99 int select(int nfds
, fd_set
*readfds
, fd_set
*writefds
, fd_set
*exceptfds
, struct timeval
*tv
);
107 const int udpMaxMessageLength
=16*1024;
109 /// Take a name in the form "host.foo.com:5000" and return ip and port
111 parseHostName( char* peerName
, unsigned int* ip
, unsigned short* portVal
, unsigned int defaultPort
= 10000 );
113 /// Open a UDP socket to receive on the given port - if port is 0, pick a a port, if interfaceIp!=0 then use ONLY the interface specified instead of all of them
115 openPort( unsigned short port
=0, unsigned int interfaceIp
=0 );
117 /// recive a UDP message
119 getMessage( Socket fd
, char* buf
, int* len
,
120 unsigned int* srcIp
, unsigned short* srcPort
);
122 /// send a UDP message
124 sendMessage( Socket fd
, char* msg
, int len
,
125 unsigned int dstIp
=0, unsigned short dstPort
=0 );
127 /// set up network - does nothing in unix but needed for windows
134 // c-file-style:"bsd"
135 // c-file-offsets:((case-label . +))
137 // indent-tabs-mode:nil