oRTP  0.16.1
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 #define EWOULDBLOCK WSAEWOULDBLOCK
57 #define EINPROGRESS WSAEINPROGRESS
58 #define EALREADY WSAEALREADY
59 #define ENOTSOCK WSAENOTSOCK
60 #define EDESTADDRREQ WSAEDESTADDRREQ
61 #define EMSGSIZE WSAEMSGSIZE
62 #define EPROTOTYPE WSAEPROTOTYPE
63 #define ENOPROTOOPT WSAENOPROTOOPT
64 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
65 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
66 #define EOPNOTSUPP WSAEOPNOTSUPP
67 #define EPFNOSUPPORT WSAEPFNOSUPPORT
68 #define EAFNOSUPPORT WSAEAFNOSUPPORT
69 #define EADDRINUSE WSAEADDRINUSE
70 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
71 #define ENETDOWN WSAENETDOWN
72 #define ENETUNREACH WSAENETUNREACH
73 #define ENETRESET WSAENETRESET
74 #define ECONNABORTED WSAECONNABORTED
75 #define ECONNRESET WSAECONNRESET
76 #define ENOBUFS WSAENOBUFS
77 #define EISCONN WSAEISCONN
78 #define ENOTCONN WSAENOTCONN
79 #define ESHUTDOWN WSAESHUTDOWN
80 #define ETOOMANYREFS WSAETOOMANYREFS
81 #define ETIMEDOUT WSAETIMEDOUT
82 #define ECONNREFUSED WSAECONNREFUSED
83 #define ELOOP WSAELOOP
84 #define EHOSTDOWN WSAEHOSTDOWN
85 #define EHOSTUNREACH WSAEHOSTUNREACH
86 #define EPROCLIM WSAEPROCLIM
87 #define EUSERS WSAEUSERS
88 #define EDQUOT WSAEDQUOT
89 #define ESTALE WSAESTALE
90 #define EREMOTE WSAEREMOTE
91 
92 typedef LONGLONG Int64;
93 
94 #else
95 
96 typedef int Socket;
97 #define INVALID_SOCKET -1
98 #define SOCKET_ERROR -1
99 
100 #define closesocket(fd) close(fd)
101 
102 #define WSANOTINITIALISED EPROTONOSUPPORT
103 
104 #endif
105 
106 #ifdef __cplusplus
107 extern "C"{
108 #endif
109 
110 int getErrno(void);
111 
112 /* Open a UDP socket to receive on the given port - if port is 0, pick a a
113  port, if interfaceIp!=0 then use ONLY the interface specified instead of
114  all of them */
115 Socket
116 openPort( unsigned short port, unsigned int interfaceIp);
117 
118 
119 /* recive a UDP message */
120 bool_t
121 getMessage( Socket fd, char* buf, int* len,
122  unsigned int* srcIp, unsigned short* srcPort);
123 
124 
125 /* send a UDP message */
126 bool_t
127 sendMessage( Socket fd, char* msg, int len,
128  unsigned int dstIp, unsigned short dstPort);
129 
130 
131 /* set up network - does nothing in unix but needed for windows */
132 void
133 initNetwork(void);
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 #endif