diff options
author | Tobias Markmann <tm@ayena.de> | 2017-05-16 15:26:38 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2017-05-17 08:04:04 (GMT) |
commit | c2abb2e8c248bb57c7478606f941223322983a8e (patch) | |
tree | d4c0f39c2933bcf4e3fb96230da60b09d9aabfdd | |
parent | edf519a67a28f9acb61af6d442d94f1aa43df688 (diff) | |
download | swift-c2abb2e8c248bb57c7478606f941223322983a8e.zip swift-c2abb2e8c248bb57c7478606f941223322983a8e.tar.bz2 |
Update 3rdParty/LibNATPMP to libnatpmp-20150609
Furthermore applied current patches.
Test-Information:
Builds on macOS 10.12.5 with Qt 5.4.2 and all unit and
integration tests pass.
Change-Id: I7a8a3b7e8b37b20532e3ed5fe32f1cef5b09b1f6
-rw-r--r-- | 3rdParty/LibNATPMP/src/libnatpmp/getgateway.c | 18 | ||||
-rw-r--r-- | 3rdParty/LibNATPMP/src/libnatpmp/getgateway.h | 8 | ||||
-rw-r--r-- | 3rdParty/LibNATPMP/src/libnatpmp/natpmp.c | 10 | ||||
-rw-r--r-- | 3rdParty/LibNATPMP/src/libnatpmp/natpmp.h | 14 |
4 files changed, 28 insertions, 22 deletions
diff --git a/3rdParty/LibNATPMP/src/libnatpmp/getgateway.c b/3rdParty/LibNATPMP/src/libnatpmp/getgateway.c index 3a3f9a6..dfb9f3e 100644 --- a/3rdParty/LibNATPMP/src/libnatpmp/getgateway.c +++ b/3rdParty/LibNATPMP/src/libnatpmp/getgateway.c @@ -1,34 +1,34 @@ -/* $Id: getgateway.c,v 1.24 2014/03/31 12:41:35 nanard Exp $ */ +/* $Id: getgateway.c,v 1.25 2014/04/22 10:28:57 nanard Exp $ */ /* libnatpmp -Copyright (c) 2007-2011, Thomas BERNARD +Copyright (c) 2007-2014, Thomas BERNARD All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 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. * The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 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. */ #include <stdio.h> #include <ctype.h> #ifndef WIN32 #include <netinet/in.h> #endif @@ -40,67 +40,60 @@ POSSIBILITY OF SUCH DAMAGE. * Parsing /proc/net/route is for linux. * sysctl is the way to access such informations on BSD systems. * Many systems should provide route information through raw PF_ROUTE * sockets. * In MS Windows, default gateway is found by looking into the registry * or by using GetBestRoute(). */ #ifdef __linux__ #define USE_PROC_NET_ROUTE #undef USE_SOCKET_ROUTE #undef USE_SYSCTL_NET_ROUTE #endif #if defined(BSD) || defined(__FreeBSD_kernel__) #undef USE_PROC_NET_ROUTE #define USE_SOCKET_ROUTE #undef USE_SYSCTL_NET_ROUTE #endif #ifdef __APPLE__ #undef USE_PROC_NET_ROUTE #undef USE_SOCKET_ROUTE #define USE_SYSCTL_NET_ROUTE #endif #if (defined(sun) && defined(__SVR4)) #undef USE_PROC_NET_ROUTE #define USE_SOCKET_ROUTE #undef USE_SYSCTL_NET_ROUTE #endif -#if !defined(USE_PROC_NET_ROUTE) && !defined(USE_SOCKET_ROUTE) && !defined(USE_SYSCTL_NET_ROUTE) && !defined(WIN32) -int getdefaultgateway(in_addr_t * addr) -{ - return -1; -} -#endif - #ifdef WIN32 #undef USE_PROC_NET_ROUTE #undef USE_SOCKET_ROUTE #undef USE_SYSCTL_NET_ROUTE //#define USE_WIN32_CODE #define USE_WIN32_CODE_2 #endif #ifdef __CYGWIN__ #undef USE_PROC_NET_ROUTE #undef USE_SOCKET_ROUTE #undef USE_SYSCTL_NET_ROUTE #define USE_WIN32_CODE #include <stdarg.h> #include <w32api/windef.h> #include <w32api/winbase.h> #include <w32api/winreg.h> #endif #ifdef __HAIKU__ #include <stdlib.h> #include <unistd.h> #include <net/if.h> #include <sys/sockio.h> #define USE_HAIKU_CODE #endif #ifdef USE_SYSCTL_NET_ROUTE #include <stdlib.h> #include <sys/sysctl.h> @@ -545,31 +538,36 @@ int getdefaultgateway(in_addr_t *addr) goto fail; } for (interface = buffer; (uint8_t *)interface < (uint8_t *)buffer + config.ifc_len; ) { struct route_entry route = interface->ifr_route; int intfSize; if (route.flags & (RTF_GATEWAY | RTF_DEFAULT)) { *addr = ((struct sockaddr_in *)route.gateway)->sin_addr.s_addr; ret = 0; break; } intfSize = sizeof(route) + IF_NAMESIZE; if (route.destination != NULL) { intfSize += route.destination->sa_len; } if (route.mask != NULL) { intfSize += route.mask->sa_len; } if (route.gateway != NULL) { intfSize += route.gateway->sa_len; } interface = (struct ifreq *)((uint8_t *)interface + intfSize); } fail: free(buffer); close(fd); return ret; } #endif /* #ifdef USE_HAIKU_CODE */ - +#if !defined(USE_PROC_NET_ROUTE) && !defined(USE_SOCKET_ROUTE) && !defined(USE_SYSCTL_NET_ROUTE) && !defined(USE_WIN32_CODE) && !defined(USE_WIN32_CODE_2) && !defined(USE_HAIKU_CODE) +int getdefaultgateway(in_addr_t * addr) +{ + return -1; +} +#endif diff --git a/3rdParty/LibNATPMP/src/libnatpmp/getgateway.h b/3rdParty/LibNATPMP/src/libnatpmp/getgateway.h index da98d1a..6eb1f93 100644 --- a/3rdParty/LibNATPMP/src/libnatpmp/getgateway.h +++ b/3rdParty/LibNATPMP/src/libnatpmp/getgateway.h @@ -1,54 +1,54 @@ -/* $Id: getgateway.h,v 1.7 2013/09/10 20:09:04 nanard Exp $ */ +/* $Id: getgateway.h,v 1.8 2014/04/22 09:15:40 nanard Exp $ */ /* libnatpmp -Copyright (c) 2007-2013, Thomas BERNARD +Copyright (c) 2007-2014, Thomas BERNARD All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 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. * The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 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. */ #ifndef __GETGATEWAY_H__ #define __GETGATEWAY_H__ #ifdef WIN32 #if !defined(_MSC_VER) || _MSC_VER >= 1600 #include <stdint.h> #else typedef unsigned long uint32_t; typedef unsigned short uint16_t; #endif #define in_addr_t uint32_t #endif -#include "declspec.h" +/* #include "declspec.h" */ #ifdef ANDROID #include <arpa/inet.h> #define in_addr_t uint32_t #endif /* getdefaultgateway() : * return value : * 0 : success * -1 : failure */ -LIBSPEC int getdefaultgateway(in_addr_t * addr); +/* LIBSPEC */int getdefaultgateway(in_addr_t * addr); #endif diff --git a/3rdParty/LibNATPMP/src/libnatpmp/natpmp.c b/3rdParty/LibNATPMP/src/libnatpmp/natpmp.c index a09f217..3a49812 100644 --- a/3rdParty/LibNATPMP/src/libnatpmp/natpmp.c +++ b/3rdParty/LibNATPMP/src/libnatpmp/natpmp.c @@ -1,33 +1,33 @@ -/* $Id: natpmp.c,v 1.18 2013/11/26 08:47:36 nanard Exp $ */ +/* $Id: natpmp.c,v 1.20 2015/05/27 12:43:15 nanard Exp $ */ /* libnatpmp -Copyright (c) 2007-2013, Thomas BERNARD +Copyright (c) 2007-2015, Thomas BERNARD All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 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. * The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 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. */ #ifdef __linux__ #define _BSD_SOURCE 1 #endif #include <string.h> #include <time.h> @@ -89,70 +89,70 @@ LIBSPEC int initnatpmp(natpmp_t * p, int forcegw, in_addr_t forcedgw) memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(NATPMP_PORT); addr.sin_addr.s_addr = p->gateway; if(connect(p->s, (struct sockaddr *)&addr, sizeof(addr)) < 0) return NATPMP_ERR_CONNECTERR; return 0; } LIBSPEC int closenatpmp(natpmp_t * p) { if(!p) return NATPMP_ERR_INVALIDARGS; if(closesocket(p->s) < 0) return NATPMP_ERR_CLOSEERR; return 0; } int sendpendingrequest(natpmp_t * p) { int r; /* struct sockaddr_in addr;*/ if(!p) return NATPMP_ERR_INVALIDARGS; /* memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(NATPMP_PORT); addr.sin_addr.s_addr = p->gateway; r = (int)sendto(p->s, p->pending_request, p->pending_request_len, 0, (struct sockaddr *)&addr, sizeof(addr));*/ - r = (int)send(p->s, p->pending_request, p->pending_request_len, 0); + r = (int)send(p->s, (const char *)p->pending_request, p->pending_request_len, 0); return (r<0) ? NATPMP_ERR_SENDERR : r; } int sendnatpmprequest(natpmp_t * p) { int n; if(!p) return NATPMP_ERR_INVALIDARGS; - /* TODO : check if no request is allready pending */ + /* TODO : check if no request is already pending */ p->has_pending_request = 1; p->try_number = 1; n = sendpendingrequest(p); gettimeofday(&p->retry_time, NULL); // check errors ! p->retry_time.tv_usec += 250000; /* add 250ms */ if(p->retry_time.tv_usec >= 1000000) { p->retry_time.tv_usec -= 1000000; p->retry_time.tv_sec++; } return n; } LIBSPEC int getnatpmprequesttimeout(natpmp_t * p, struct timeval * timeout) { struct timeval now; if(!p || !timeout) return NATPMP_ERR_INVALIDARGS; if(!p->has_pending_request) return NATPMP_ERR_NOPENDINGREQ; if(gettimeofday(&now, NULL) < 0) return NATPMP_ERR_GETTIMEOFDAYERR; timeout->tv_sec = p->retry_time.tv_sec - now.tv_sec; timeout->tv_usec = p->retry_time.tv_usec - now.tv_usec; if(timeout->tv_usec < 0) { timeout->tv_usec += 1000000; timeout->tv_sec--; } return 0; } @@ -177,61 +177,61 @@ LIBSPEC int sendnewportmappingrequest(natpmp_t * p, int protocol, p->pending_request[0] = 0; p->pending_request[1] = protocol; p->pending_request[2] = 0; p->pending_request[3] = 0; /* break strict-aliasing rules : *((uint16_t *)(p->pending_request + 4)) = htons(privateport); */ p->pending_request[4] = (privateport >> 8) & 0xff; p->pending_request[5] = privateport & 0xff; /* break stric-aliasing rules : *((uint16_t *)(p->pending_request + 6)) = htons(publicport); */ p->pending_request[6] = (publicport >> 8) & 0xff; p->pending_request[7] = publicport & 0xff; /* break stric-aliasing rules : *((uint32_t *)(p->pending_request + 8)) = htonl(lifetime); */ p->pending_request[8] = (lifetime >> 24) & 0xff; p->pending_request[9] = (lifetime >> 16) & 0xff; p->pending_request[10] = (lifetime >> 8) & 0xff; p->pending_request[11] = lifetime & 0xff; p->pending_request_len = 12; return sendnatpmprequest(p); } LIBSPEC int readnatpmpresponse(natpmp_t * p, natpmpresp_t * response) { unsigned char buf[16]; struct sockaddr_in addr; socklen_t addrlen = sizeof(addr); int n; if(!p) return NATPMP_ERR_INVALIDARGS; - n = recvfrom(p->s, buf, sizeof(buf), 0, + n = recvfrom(p->s, (char *)buf, sizeof(buf), 0, (struct sockaddr *)&addr, &addrlen); if(n<0) #ifdef WIN32 switch(WSAGetLastError()) { #else switch(errno) { #endif /*case EAGAIN:*/ case EWOULDBLOCK: n = NATPMP_TRYAGAIN; break; case ECONNREFUSED: n = NATPMP_ERR_NOGATEWAYSUPPORT; break; default: n = NATPMP_ERR_RECVFROM; } /* check that addr is correct (= gateway) */ else if(addr.sin_addr.s_addr != p->gateway) n = NATPMP_ERR_WRONGPACKETSOURCE; else { response->resultcode = ntohs(*((uint16_t *)(buf + 2))); response->epoch = ntohl(*((uint32_t *)(buf + 4))); if(buf[0] != 0) n = NATPMP_ERR_UNSUPPORTEDVERSION; else if(buf[1] < 128 || buf[1] > 130) n = NATPMP_ERR_UNSUPPORTEDOPCODE; else if(response->resultcode != 0) { switch(response->resultcode) { case 1: diff --git a/3rdParty/LibNATPMP/src/libnatpmp/natpmp.h b/3rdParty/LibNATPMP/src/libnatpmp/natpmp.h index 6791c76..41325c9 100644 --- a/3rdParty/LibNATPMP/src/libnatpmp/natpmp.h +++ b/3rdParty/LibNATPMP/src/libnatpmp/natpmp.h @@ -1,84 +1,92 @@ -/* $Id: natpmp.h,v 1.19 2014/04/01 09:39:29 nanard Exp $ */ +/* $Id: natpmp.h,v 1.20 2014/04/22 09:15:40 nanard Exp $ */ /* libnatpmp -Copyright (c) 2007-2013, Thomas BERNARD +Copyright (c) 2007-2014, Thomas BERNARD All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 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. * The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 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. */ #ifndef __NATPMP_H__ #define __NATPMP_H__ /* NAT-PMP Port as defined by the NAT-PMP draft */ #define NATPMP_PORT (5351) #include <time.h> #if !defined(_MSC_VER) #include <sys/time.h> #endif /* !defined(_MSC_VER) */ #ifdef WIN32 #include <winsock2.h> #if !defined(_MSC_VER) || _MSC_VER >= 1600 #include <stdint.h> #else /* !defined(_MSC_VER) || _MSC_VER >= 1600 */ typedef unsigned long uint32_t; typedef unsigned short uint16_t; #endif /* !defined(_MSC_VER) || _MSC_VER >= 1600 */ #define in_addr_t uint32_t #include "declspec.h" #else /* WIN32 */ +#define LIBSPEC #include <netinet/in.h> #endif /* WIN32 */ -#include "declspec.h" +/* causes problem when installing. Maybe should it be inlined ? */ +/* #include "declspec.h" */ + +#ifdef ANDROID +#include <arpa/inet.h> +#define in_addr_t uint32_t +#endif + #ifdef ANDROID #include <arpa/inet.h> #define in_addr_t uint32_t #endif typedef struct { int s; /* socket */ in_addr_t gateway; /* default gateway (IPv4) */ int has_pending_request; unsigned char pending_request[12]; int pending_request_len; int try_number; struct timeval retry_time; } natpmp_t; typedef struct { uint16_t type; /* NATPMP_RESPTYPE_* */ uint16_t resultcode; /* NAT-PMP response code */ uint32_t epoch; /* Seconds since start of epoch */ union { struct { //in_addr_t addr; struct in_addr addr; } publicaddress; struct { uint16_t privateport; uint16_t mappedpublicport; uint32_t lifetime; |