a-oRTP  5.2.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
22  * 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,
23  * 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
24  * 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
25  * 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,
26  * 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
27  * 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
28  * 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. * *
29  * ==================================================================== * * 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
30  * Networks, Inc., please see * <http://www.vovida.org/>.
31  *
32  */
33 
34 #ifndef __STUN_UDP_H__
35 #define __STUN_UDP_H__
36 
37 #ifndef __cplusplus
38 //#define bool int
39 //#define false 0
40 //#define true 1
41 #endif
42 
43 #ifdef __MACH__
44 #include <sys/socket.h>
45 #ifndef _SOCKLEN_T
46 typedef int socklen_t;
47 #endif
48 #endif
49 
50 #include <ortp/port.h>
51 
52 #if !defined(_WIN32_WCE)
53 #include <errno.h>
54 #endif
55 
56 #if defined(WIN32) || defined(_WIN32_WCE)
57 #if (_MSC_VER < 1900)
58 #define snprintf _snprintf
59 #endif
60 
61 #include <winsock2.h>
62 /* #include <io.h> */
63 
64 typedef int socklen_t;
65 typedef SOCKET Socket;
66 
67 #else
68 
69 typedef int Socket;
70 #define INVALID_SOCKET -1
71 #define SOCKET_ERROR -1
72 
73 #define closesocket(fd) close(fd)
74 
75 #define WSANOTINITIALISED EPROTONOSUPPORT
76 
77 #endif
78 
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 
83 struct addrinfo;
84 
85 typedef struct {
86  uint16_t port;
87  uint32_t addr;
88 } StunAddress4;
89 
90 typedef struct {
91  uint16_t port;
92  uint8_t addr[16];
93 } StunAddress6;
94 
95 typedef struct {
96  uint8_t family;
97  union {
98  StunAddress4 ipv4;
99  StunAddress6 ipv6;
100  } addr;
101 } StunIPAddress;
102 
103 typedef struct {
104  unsigned char octet[12];
105 } StunTrId;
106 
107 void stunDecodeXorAddress(const StunIPAddress *xorAddress, StunIPAddress *destAddr, StunTrId *stunTrId);
108 
109 void stunEncodeXorAddress(const StunIPAddress *origAddress, StunIPAddress *xorAddress, StunTrId *stunTrId);
110 
111 char *stunIPAddressStr(const StunIPAddress *addr, char *tmp, size_t size_of_tmp);
112 
113 char *stunIPAddress_ntop(const StunIPAddress *addr, char *tmp, size_t size_of_tmp);
114 
115 /* convert a (numeric?) IP address string to StunIPAddress - return false is fails parse */
116 bool_t stunIPToStunIPAddress(const char *ipaddr, int srcport, StunIPAddress *cAddr);
117 
118 /* find the IP address of a the specified stun server - return false is fails parse */
119 bool_t stunParseServerName(const char *serverName, StunIPAddress *addr_ipv4_udp, StunIPAddress *addr_ipv6_udp, StunIPAddress *addr_ipv4_tcp, StunIPAddress *addr_ipv6_tcp);
120 
121 int stunGetaddrinfo(struct addrinfo **addrinfo, const char *hostname, int port, int protocol, int family);
122 
123 /* Open a UDP socket to receive on the given port - if port is 0, pick a a
124  port, if interfaceIp!=0 then use ONLY the interface specified instead of
125  all of them */
126 Socket openPort(StunIPAddress *ipaddr);
127 
128 /* recive a UDP message */
129 bool_t getMessage(Socket fd, char *buf, int *len, StunIPAddress *fromIP);
130 
131 /* send a UDP message */
132 bool_t sendMessage(Socket fd, char *msg, int len, StunIPAddress *dest);
133 
134 /* set up network - does nothing in unix but needed for windows */
135 void initNetwork(void);
136 
137 #ifdef __cplusplus
138 }
139 #endif
140 
141 #endif
Definition: stun_udp.h:85
Definition: stun_udp.h:90
Definition: stun_udp.h:95
Definition: stun_udp.h:103