Added IsSupportingRTP function to simplify detecting when STUN supports RTP
[pwlib.git] / src / ptclib / udp.h
blobbe6140d64d8c1a9c48c3c9ac605cd82c91d7f585
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,
120 unsigned int* srcIp, unsigned short* srcPort );
122 /// send a UDP message
123 bool
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
128 void
129 initNetwork();
132 // Local Variables:
133 // mode:c++
134 // c-file-style:"bsd"
135 // c-file-offsets:((case-label . +))
136 // c-basic-offset:4
137 // indent-tabs-mode:nil
138 // End:
139 #endif