Fixed DevStudio 2003 build with memory check code.
[pwlib.git] / src / ptclib / udp.h
blob9275d7731a4eef3479246a6c2d3feb5a83434652
1 //
2 // stund/udp.h
3 //
4 // Copyright (c) 2002 Alan Hawrylyshen
5 //
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:
13 //
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
16 //
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 *******************/
28 #ifndef udp_h
29 #define udp_h
31 #ifdef WIN32
33 #include <errno.h>
35 #ifndef _WIN32_WCE
36 #include <winsock2.h>
37 #else
38 #include <winsock.h>
39 #endif
41 #include <io.h>
43 typedef int socklen_t;
44 #ifndef errno
45 #define errno WSAGetLastError()
46 #endif
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;
87 #else
89 typedef int Socket;
90 static const Socket INVALID_SOCKET = -1;
91 static const int SOCKET_ERROR = -1;
94 int closesocket( Socket fd );
96 #ifdef P_RTEMS
97 typedef int socklen_t;
98 extern "C" {
99 int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *tv);
101 #endif
103 #endif
107 const int udpMaxMessageLength=16*1024;
109 /// Take a name in the form "host.foo.com:5000" and return ip and port
110 void
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
114 Socket
115 openPort( unsigned short port=0, unsigned int interfaceIp=0 );
117 /// recive a UDP message
118 bool
119 getMessage( Socket fd, char* buf, int* len, unsigned int* srcIp, unsigned short* srcPort );
121 /// send a UDP message
122 bool
123 sendMessage( Socket fd, char* msg, int len,
124 unsigned int dstIp=0, unsigned short dstPort=0 );
126 /// set up network - does nothing in unix but needed for windows
127 void
128 initNetwork();
131 // Local Variables:
132 // mode:c++
133 // c-file-style:"bsd"
134 // c-file-offsets:((case-label . +))
135 // c-basic-offset:4
136 // indent-tabs-mode:nil
137 // End:
138 #endif