oRTP 0.23.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
37typedef int socklen_t;
38#endif
39#endif
40
41#include <ortp/port.h>
42
43#if defined(WIN32) || defined(_WIN32_WCE)
44
45#if !defined(_WIN32_WCE)
46#include <errno.h>
47#endif
48
49
50
51#include <winsock2.h>
52/* #include <io.h> */
53
54typedef int socklen_t;
55typedef SOCKET Socket;
56
57#ifndef EWOULDBLOCK
58#define EWOULDBLOCK WSAEWOULDBLOCK
59#endif
60#ifndef EINPROGRESS
61#define EINPROGRESS WSAEINPROGRESS
62#endif
63#ifndef EALREADY
64#define EALREADY WSAEALREADY
65#endif
66#ifndef ENOTSOCK
67#define ENOTSOCK WSAENOTSOCK
68#endif
69#ifndef EDESTADDRREQ
70#define EDESTADDRREQ WSAEDESTADDRREQ
71#endif
72#ifndef EMSGSIZE
73#define EMSGSIZE WSAEMSGSIZE
74#endif
75#ifndef EPROTOTYPE
76#define EPROTOTYPE WSAEPROTOTYPE
77#endif
78#ifndef ENOPROTOOPT
79#define ENOPROTOOPT WSAENOPROTOOPT
80#endif
81#ifndef EPROTONOSUPPORT
82#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
83#endif
84#ifndef ESOCKTNOSUPPORT
85#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
86#endif
87#ifndef EOPNOTSUPP
88#define EOPNOTSUPP WSAEOPNOTSUPP
89#endif
90#ifndef EPFNOSUPPORT
91#define EPFNOSUPPORT WSAEPFNOSUPPORT
92#endif
93#ifndef EAFNOSUPPORT
94#define EAFNOSUPPORT WSAEAFNOSUPPORT
95#endif
96#ifndef EADDRINUSE
97#define EADDRINUSE WSAEADDRINUSE
98#endif
99#ifndef EADDRNOTAVAIL
100#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
101#endif
102#ifndef ENETDOWN
103#define ENETDOWN WSAENETDOWN
104#endif
105#ifndef ENETUNREACH
106#define ENETUNREACH WSAENETUNREACH
107#endif
108#ifndef ENETRESET
109#define ENETRESET WSAENETRESET
110#endif
111#ifndef ECONNABORTED
112#define ECONNABORTED WSAECONNABORTED
113#endif
114#ifndef ECONNRESET
115#define ECONNRESET WSAECONNRESET
116#endif
117#ifndef ENOBUFS
118#define ENOBUFS WSAENOBUFS
119#endif
120#ifndef EISCONN
121#define EISCONN WSAEISCONN
122#endif
123#ifndef ENOTCONN
124#define ENOTCONN WSAENOTCONN
125#endif
126#ifndef ESHUTDOWN
127#define ESHUTDOWN WSAESHUTDOWN
128#endif
129#ifndef ETOOMANYREFS
130#define ETOOMANYREFS WSAETOOMANYREFS
131#endif
132#ifndef ETIMEDOUT
133#define ETIMEDOUT WSAETIMEDOUT
134#endif
135#ifndef ECONNREFUSED
136#define ECONNREFUSED WSAECONNREFUSED
137#endif
138#ifndef ELOOP
139#define ELOOP WSAELOOP
140#endif
141#ifndef EHOSTDOWN
142#define EHOSTDOWN WSAEHOSTDOWN
143#endif
144#ifndef EHOSTUNREACH
145#define EHOSTUNREACH WSAEHOSTUNREACH
146#endif
147#ifndef EPROCLIM
148#define EPROCLIM WSAEPROCLIM
149#endif
150#ifndef EUSERS
151#define EUSERS WSAEUSERS
152#endif
153#ifndef EDQUOT
154#define EDQUOT WSAEDQUOT
155#endif
156#ifndef ESTALE
157#define ESTALE WSAESTALE
158#endif
159#ifndef EREMOTE
160#define EREMOTE WSAEREMOTE
161#endif
162typedef LONGLONG Int64;
163
164#else
165
166typedef int Socket;
167#ifndef INVALID_SOCKET
168#define INVALID_SOCKET -1
169#endif
170#ifndef SOCKET_ERROR
171#define SOCKET_ERROR -1
172#endif
173
174#define closesocket(fd) close(fd)
175
176#define WSANOTINITIALISED EPROTONOSUPPORT
177
178#endif
179
180#ifdef __cplusplus
181extern "C"{
182#endif
183
184ORTP_PUBLIC int getErrno(void);
185
186/* Open a UDP socket to receive on the given port - if port is 0, pick a a
187 port, if interfaceIp!=0 then use ONLY the interface specified instead of
188 all of them */
189ORTP_PUBLIC Socket
190openPort( unsigned short port, unsigned int interfaceIp);
191
192
193/* recive a UDP message */
194ORTP_PUBLIC bool_t
195getMessage( Socket fd, char* buf, int* len,
196 unsigned int* srcIp, unsigned short* srcPort);
197
198
199/* send a UDP message */
200ORTP_PUBLIC bool_t
201sendMessage( Socket fd, char* msg, int len,
202 unsigned int dstIp, unsigned short dstPort);
203
204
205/* set up network - does nothing in unix but needed for windows */
206ORTP_PUBLIC void
207initNetwork(void);
208
209#ifdef __cplusplus
210}
211#endif
212
213#endif