oRTP  0.22.0
include/ortp/stun_udp.h
00001  /*
00002   The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
00003   Copyright (C) 2001  Simon MORLAT simon.morlat@linphone.org
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 /* ====================================================================
00021  * 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/>.
00022  *
00023  */
00024 
00025 #ifndef __STUN_UDP_H__
00026 #define __STUN_UDP_H__
00027 
00028 #ifndef __cplusplus
00029 //#define bool int
00030 //#define false 0
00031 //#define true 1
00032 #endif
00033 
00034 #ifdef __MACH__
00035 #include <sys/socket.h>
00036 #ifndef _SOCKLEN_T
00037 typedef int socklen_t;
00038 #endif
00039 #endif
00040 
00041 #include <ortp/port.h>
00042 
00043 #if defined(WIN32) || defined(_WIN32_WCE)
00044 
00045 #if !defined(_WIN32_WCE)
00046 #include <errno.h>
00047 #endif
00048 
00049 
00050 
00051 #include <winsock2.h>
00052 /* #include <io.h> */
00053 
00054 typedef int socklen_t;
00055 typedef SOCKET Socket;
00056 
00057 #ifndef EWOULDBLOCK
00058 #define EWOULDBLOCK             WSAEWOULDBLOCK
00059 #endif
00060 #ifndef EINPROGRESS
00061 #define EINPROGRESS             WSAEINPROGRESS
00062 #endif
00063 #ifndef EALREADY
00064 #define EALREADY                WSAEALREADY
00065 #endif
00066 #ifndef ENOTSOCK
00067 #define ENOTSOCK                WSAENOTSOCK
00068 #endif
00069 #ifndef EDESTADDRREQ
00070 #define EDESTADDRREQ            WSAEDESTADDRREQ
00071 #endif
00072 #ifndef EMSGSIZE
00073 #define EMSGSIZE                WSAEMSGSIZE
00074 #endif
00075 #ifndef EPROTOTYPE
00076 #define EPROTOTYPE              WSAEPROTOTYPE
00077 #endif
00078 #ifndef ENOPROTOOPT
00079 #define ENOPROTOOPT             WSAENOPROTOOPT
00080 #endif
00081 #ifndef EPROTONOSUPPORT
00082 #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
00083 #endif
00084 #ifndef ESOCKTNOSUPPORT
00085 #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
00086 #endif
00087 #ifndef EOPNOTSUPP
00088 #define EOPNOTSUPP              WSAEOPNOTSUPP
00089 #endif
00090 #ifndef EPFNOSUPPORT
00091 #define EPFNOSUPPORT            WSAEPFNOSUPPORT
00092 #endif
00093 #ifndef EAFNOSUPPORT
00094 #define EAFNOSUPPORT            WSAEAFNOSUPPORT
00095 #endif
00096 #ifndef EADDRINUSE
00097 #define EADDRINUSE              WSAEADDRINUSE
00098 #endif
00099 #ifndef EADDRNOTAVAIL
00100 #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
00101 #endif
00102 #ifndef ENETDOWN
00103 #define ENETDOWN                WSAENETDOWN
00104 #endif
00105 #ifndef ENETUNREACH
00106 #define ENETUNREACH             WSAENETUNREACH
00107 #endif
00108 #ifndef ENETRESET
00109 #define ENETRESET               WSAENETRESET
00110 #endif
00111 #ifndef ECONNABORTED
00112 #define ECONNABORTED            WSAECONNABORTED
00113 #endif
00114 #ifndef ECONNRESET
00115 #define ECONNRESET              WSAECONNRESET
00116 #endif
00117 #ifndef ENOBUFS
00118 #define ENOBUFS                 WSAENOBUFS
00119 #endif
00120 #ifndef EISCONN
00121 #define EISCONN                 WSAEISCONN
00122 #endif
00123 #ifndef ENOTCONN
00124 #define ENOTCONN                WSAENOTCONN
00125 #endif
00126 #ifndef ESHUTDOWN
00127 #define ESHUTDOWN               WSAESHUTDOWN
00128 #endif
00129 #ifndef ETOOMANYREFS
00130 #define ETOOMANYREFS            WSAETOOMANYREFS
00131 #endif
00132 #ifndef ETIMEDOUT
00133 #define ETIMEDOUT               WSAETIMEDOUT
00134 #endif
00135 #ifndef ECONNREFUSED
00136 #define ECONNREFUSED            WSAECONNREFUSED
00137 #endif
00138 #ifndef ELOOP
00139 #define ELOOP                   WSAELOOP
00140 #endif
00141 #ifndef EHOSTDOWN
00142 #define EHOSTDOWN               WSAEHOSTDOWN
00143 #endif
00144 #ifndef EHOSTUNREACH
00145 #define EHOSTUNREACH            WSAEHOSTUNREACH
00146 #endif
00147 #ifndef EPROCLIM
00148 #define EPROCLIM                WSAEPROCLIM
00149 #endif
00150 #ifndef EUSERS
00151 #define EUSERS                  WSAEUSERS
00152 #endif
00153 #ifndef EDQUOT
00154 #define EDQUOT                  WSAEDQUOT
00155 #endif
00156 #ifndef ESTALE
00157 #define ESTALE                  WSAESTALE
00158 #endif
00159 #ifndef EREMOTE
00160 #define EREMOTE                 WSAEREMOTE
00161 #endif
00162 typedef LONGLONG Int64; 
00163 
00164 #else
00165 
00166 typedef int Socket;
00167 #ifndef INVALID_SOCKET 
00168 #define INVALID_SOCKET -1
00169 #endif
00170 #ifndef SOCKET_ERROR 
00171 #define SOCKET_ERROR -1
00172 #endif
00173 
00174 #define closesocket(fd) close(fd)
00175 
00176 #define WSANOTINITIALISED  EPROTONOSUPPORT
00177 
00178 #endif
00179 
00180 #ifdef __cplusplus
00181 extern "C"{
00182 #endif
00183 
00184 ORTP_PUBLIC int getErrno(void);
00185 
00186 /* Open a UDP socket to receive on the given port - if port is 0, pick a a
00187    port, if interfaceIp!=0 then use ONLY the interface specified instead of
00188    all of them  */
00189 ORTP_PUBLIC Socket
00190 openPort( unsigned short port, unsigned int interfaceIp);
00191 
00192 
00193 /* recive a UDP message */
00194 ORTP_PUBLIC bool_t
00195 getMessage( Socket fd, char* buf, int* len,
00196             unsigned int* srcIp, unsigned short* srcPort);
00197 
00198 
00199 /* send a UDP message */
00200 ORTP_PUBLIC bool_t
00201 sendMessage( Socket fd, char* msg, int len, 
00202              unsigned int dstIp, unsigned short dstPort);
00203 
00204 
00205 /* set up network - does nothing in unix but needed for windows */
00206 ORTP_PUBLIC void
00207 initNetwork(void);
00208 
00209 #ifdef __cplusplus
00210 }
00211 #endif
00212 
00213 #endif