oRTP  0.20.0
stun_udp.h
1  /*
2  The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
3  Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 /* ====================================================================
21  * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>.
22  *
23  */
24 
25 #ifndef __STUN_UDP_H__
26 #define __STUN_UDP_H__
27 
28 #ifndef __cplusplus
29 //#define bool int
30 //#define false 0
31 //#define true 1
32 #endif
33 
34 #ifdef __MACH__
35 #include <sys/socket.h>
36 #ifndef _SOCKLEN_T
37 typedef int socklen_t;
38 #endif
39 #endif
40 
41 #include <ortp/port.h>
42 
43 #if !defined(_WIN32_WCE)
44 #include <errno.h>
45 #endif
46 
47 #if defined(WIN32) || defined(_WIN32_WCE)
48 #define snprintf _snprintf
49 
50 #include <winsock2.h>
51 /* #include <io.h> */
52 
53 typedef int socklen_t;
54 typedef SOCKET Socket;
55 
56 #ifndef EWOULDBLOCK
57 #define EWOULDBLOCK WSAEWOULDBLOCK
58 #endif
59 #ifndef EINPROGRESS
60 #define EINPROGRESS WSAEINPROGRESS
61 #endif
62 #ifndef EALREADY
63 #define EALREADY WSAEALREADY
64 #endif
65 #ifndef ENOTSOCK
66 #define ENOTSOCK WSAENOTSOCK
67 #endif
68 #ifndef EDESTADDRREQ
69 #define EDESTADDRREQ WSAEDESTADDRREQ
70 #endif
71 #ifndef EMSGSIZE
72 #define EMSGSIZE WSAEMSGSIZE
73 #endif
74 #ifndef EPROTOTYPE
75 #define EPROTOTYPE WSAEPROTOTYPE
76 #endif
77 #ifndef ENOPROTOOPT
78 #define ENOPROTOOPT WSAENOPROTOOPT
79 #endif
80 #ifndef EPROTONOSUPPORT
81 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
82 #endif
83 #ifndef ESOCKTNOSUPPORT
84 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
85 #endif
86 #ifndef EOPNOTSUPP
87 #define EOPNOTSUPP WSAEOPNOTSUPP
88 #endif
89 #ifndef EPFNOSUPPORT
90 #define EPFNOSUPPORT WSAEPFNOSUPPORT
91 #endif
92 #ifndef EAFNOSUPPORT
93 #define EAFNOSUPPORT WSAEAFNOSUPPORT
94 #endif
95 #ifndef EADDRINUSE
96 #define EADDRINUSE WSAEADDRINUSE
97 #endif
98 #ifndef EADDRNOTAVAIL
99 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
100 #endif
101 #ifndef ENETDOWN
102 #define ENETDOWN WSAENETDOWN
103 #endif
104 #ifndef ENETUNREACH
105 #define ENETUNREACH WSAENETUNREACH
106 #endif
107 #ifndef ENETRESET
108 #define ENETRESET WSAENETRESET
109 #endif
110 #ifndef ECONNABORTED
111 #define ECONNABORTED WSAECONNABORTED
112 #endif
113 #ifndef ECONNRESET
114 #define ECONNRESET WSAECONNRESET
115 #endif
116 #ifndef ENOBUFS
117 #define ENOBUFS WSAENOBUFS
118 #endif
119 #ifndef EISCONN
120 #define EISCONN WSAEISCONN
121 #endif
122 #ifndef ENOTCONN
123 #define ENOTCONN WSAENOTCONN
124 #endif
125 #ifndef ESHUTDOWN
126 #define ESHUTDOWN WSAESHUTDOWN
127 #endif
128 #ifndef ETOOMANYREFS
129 #define ETOOMANYREFS WSAETOOMANYREFS
130 #endif
131 #ifndef ETIMEDOUT
132 #define ETIMEDOUT WSAETIMEDOUT
133 #endif
134 #ifndef ECONNREFUSED
135 #define ECONNREFUSED WSAECONNREFUSED
136 #endif
137 #ifndef ELOOP
138 #define ELOOP WSAELOOP
139 #endif
140 #ifndef EHOSTDOWN
141 #define EHOSTDOWN WSAEHOSTDOWN
142 #endif
143 #ifndef EHOSTUNREACH
144 #define EHOSTUNREACH WSAEHOSTUNREACH
145 #endif
146 #ifndef EPROCLIM
147 #define EPROCLIM WSAEPROCLIM
148 #endif
149 #ifndef EUSERS
150 #define EUSERS WSAEUSERS
151 #endif
152 #ifndef EDQUOT
153 #define EDQUOT WSAEDQUOT
154 #endif
155 #ifndef ESTALE
156 #define ESTALE WSAESTALE
157 #endif
158 #ifndef EREMOTE
159 #define EREMOTE WSAEREMOTE
160 #endif
161 typedef LONGLONG Int64;
162 
163 #else
164 
165 typedef int Socket;
166 #ifndef INVALID_SOCKET
167 #define INVALID_SOCKET -1
168 #endif
169 #ifndef SOCKET_ERROR
170 #define SOCKET_ERROR -1
171 #endif
172 
173 #define closesocket(fd) close(fd)
174 
175 #define WSANOTINITIALISED EPROTONOSUPPORT
176 
177 #endif
178 
179 #ifdef __cplusplus
180 extern "C"{
181 #endif
182 
183 int getErrno(void);
184 
185 /* Open a UDP socket to receive on the given port - if port is 0, pick a a
186  port, if interfaceIp!=0 then use ONLY the interface specified instead of
187  all of them */
188 Socket
189 openPort( unsigned short port, unsigned int interfaceIp);
190 
191 
192 /* recive a UDP message */
193 bool_t
194 getMessage( Socket fd, char* buf, int* len,
195  unsigned int* srcIp, unsigned short* srcPort);
196 
197 
198 /* send a UDP message */
199 bool_t
200 sendMessage( Socket fd, char* msg, int len,
201  unsigned int dstIp, unsigned short dstPort);
202 
203 
204 /* set up network - does nothing in unix but needed for windows */
205 void
206 initNetwork(void);
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 
212 #endif