Statistics
| Branch: | Revision:

ml / stun_server / stund / udp.h @ 372c2c31

History | View | Annotate | Download (5.19 KB)

1
#ifndef udp_h
2
#define udp_h
3

    
4

    
5
#ifdef __MACH__
6
typedef int socklen_t;
7
#endif
8

    
9
#include <errno.h>
10

    
11
#ifdef _WIN32
12

    
13
#include <winsock2.h>
14
#include <io.h>
15

    
16
typedef int socklen_t;
17
typedef SOCKET Socket;
18

    
19
#define EWOULDBLOCK             WSAEWOULDBLOCK
20
#define EINPROGRESS             WSAEINPROGRESS
21
#define EALREADY                WSAEALREADY
22
#define ENOTSOCK                WSAENOTSOCK
23
#define EDESTADDRREQ            WSAEDESTADDRREQ
24
#define EMSGSIZE                WSAEMSGSIZE
25
#define EPROTOTYPE              WSAEPROTOTYPE
26
#define ENOPROTOOPT             WSAENOPROTOOPT
27
#define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
28
#define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
29
#define EOPNOTSUPP              WSAEOPNOTSUPP
30
#define EPFNOSUPPORT            WSAEPFNOSUPPORT
31
#define EAFNOSUPPORT            WSAEAFNOSUPPORT
32
#define EADDRINUSE              WSAEADDRINUSE
33
#define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
34
#define ENETDOWN                WSAENETDOWN
35
#define ENETUNREACH             WSAENETUNREACH
36
#define ENETRESET               WSAENETRESET
37
#define ECONNABORTED            WSAECONNABORTED
38
#define ECONNRESET              WSAECONNRESET
39
#define ENOBUFS                 WSAENOBUFS
40
#define EISCONN                 WSAEISCONN
41
#define ENOTCONN                WSAENOTCONN
42
#define ESHUTDOWN               WSAESHUTDOWN
43
#define ETOOMANYREFS            WSAETOOMANYREFS
44
#define ETIMEDOUT               WSAETIMEDOUT
45
#define ECONNREFUSED            WSAECONNREFUSED
46
#define ELOOP                   WSAELOOP
47
#define EHOSTDOWN               WSAEHOSTDOWN
48
#define EHOSTUNREACH            WSAEHOSTUNREACH
49
#define EPROCLIM                WSAEPROCLIM
50
#define EUSERS                  WSAEUSERS
51
#define EDQUOT                  WSAEDQUOT
52
#define ESTALE                  WSAESTALE
53
#define EREMOTE                 WSAEREMOTE
54

    
55
typedef LONGLONG Int64; 
56
inline int getErrno() { return WSAGetLastError(); }
57

    
58
#else
59

    
60
typedef int Socket;
61
static const Socket INVALID_SOCKET = -1;
62
static const int SOCKET_ERROR = -1;
63

    
64
inline int closesocket( Socket fd ) { return close(fd); };
65

    
66
inline int getErrno() { return errno; }
67

    
68
#define WSANOTINITIALISED  EPROTONOSUPPORT
69

    
70
#endif
71

    
72
/// Open a UDP socket to receive on the given port - if port is 0, pick a a
73
/// port, if interfaceIp!=0 then use ONLY the interface specified instead of
74
/// all of them  
75
Socket
76
openPort( unsigned short port, unsigned int interfaceIp,
77
          bool verbose);
78

    
79

    
80
/// recive a UDP message 
81
bool 
82
getMessage( Socket fd, char* buf, int* len,
83
            unsigned int* srcIp, unsigned short* srcPort,
84
            bool verbose);
85

    
86

    
87
/// send a UDP message 
88
bool 
89
sendMessage( Socket fd, char* msg, int len, 
90
             unsigned int dstIp, unsigned short dstPort,
91
             bool verbose);
92

    
93

    
94
/// set up network - does nothing in unix but needed for windows
95
void
96
initNetwork();
97

    
98

    
99
/* ====================================================================
100
 * The Vovida Software License, Version 1.0 
101
 * 
102
 * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
103
 * 
104
 * Redistribution and use in source and binary forms, with or without
105
 * modification, are permitted provided that the following conditions
106
 * are met:
107
 * 
108
 * 1. Redistributions of source code must retain the above copyright
109
 *    notice, this list of conditions and the following disclaimer.
110
 * 
111
 * 2. Redistributions in binary form must reproduce the above copyright
112
 *    notice, this list of conditions and the following disclaimer in
113
 *    the documentation and/or other materials provided with the
114
 *    distribution.
115
 * 
116
 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
117
 *    and "Vovida Open Communication Application Library (VOCAL)" must
118
 *    not be used to endorse or promote products derived from this
119
 *    software without prior written permission. For written
120
 *    permission, please contact vocal@vovida.org.
121
 *
122
 * 4. Products derived from this software may not be called "VOCAL", nor
123
 *    may "VOCAL" appear in their name, without prior written
124
 *    permission of Vovida Networks, Inc.
125
 * 
126
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
127
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
128
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
129
 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
130
 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
131
 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
132
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
133
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
134
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
135
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
136
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
137
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
138
 * DAMAGE.
139
 * 
140
 * ====================================================================
141
 * 
142
 * This software consists of voluntary contributions made by Vovida
143
 * Networks, Inc. and many individuals on behalf of Vovida Networks,
144
 * Inc.  For more information on Vovida Networks, Inc., please see
145
 * <http://www.vovida.org/>.
146
 *
147
 */
148

    
149
// Local Variables:
150
// mode:c++
151
// c-file-style:"ellemtel"
152
// c-file-offsets:((case-label . +))
153
// indent-tabs-mode:nil
154
// End:
155

    
156
#endif