diff options
author | Riccardo Spagni <ric@spagni.net> | 2014-10-02 18:43:13 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2014-10-02 18:54:55 +0200 |
commit | 18281f4d205d9e320fad23ac3c28b66ea4bb2ff7 (patch) | |
tree | f007a38c98ad2f8d6e7b3cd85230b0ce4c5fcf02 | |
parent | fixed unbound static lib on mingw as libunbound.dll.a (diff) | |
download | monero-18281f4d205d9e320fad23ac3c28b66ea4bb2ff7.tar.xz |
remove dangling upnp port mappings, updated miniupnpc
Diffstat (limited to '')
71 files changed, 728 insertions, 221 deletions
diff --git a/external/miniupnpc/.gitignore b/external/miniupnpc/.gitignore new file mode 100644 index 000000000..c5103d2bd --- /dev/null +++ b/external/miniupnpc/.gitignore @@ -0,0 +1,25 @@ +deb_dist/ +build/ +*.o +*.a +*.so +*.dll +*.dylib +Makefile.bak +miniupnpcstrings.h +pythonmodule +pythonmodule3 +upnpc-shared +upnpc-static +minihttptestserver +minixmlvalid +testminiwget +validateminiwget +validateminixml +java/miniupnpc_*.jar +_jnaerator.* +out.errors.txt +jnaerator-*.jar +miniupnpc.h.bak +testupnpreplyparse +validateupnpreplyparse diff --git a/external/miniupnpc/CMakeLists.txt b/external/miniupnpc/CMakeLists.txt index 74aaa0509..4631725ec 100755..100644 --- a/external/miniupnpc/CMakeLists.txt +++ b/external/miniupnpc/CMakeLists.txt @@ -36,7 +36,7 @@ else (NOT WIN32) endif (NOT WIN32) if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") - add_definitions (-DMACOSX -D_DARWIN_C_SOURCE) + add_definitions (-D_DARWIN_C_SOURCE) endif () # Set compiler specific build flags @@ -86,16 +86,14 @@ endif (NOT WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "AmigaOS") if (WIN32) set_source_files_properties (${MINIUPNPC_SOURCES} PROPERTIES - COMPILE_DEFINITIONS STATICLIB + COMPILE_DEFINITIONS MINIUPNP_STATICLIB COMPILE_DEFINITIONS MINIUPNP_EXPORTS ) endif (WIN32) if (WIN32) -# find_library (WINSOCK2_LIBRARY NAMES ws2_32 WS2_32 Ws2_32) -# find_library (IPHLPAPI_LIBRARY NAMES iphlpapi) - set(WINSOCK2_LIBRARY ws2_32) - set(IPHLPAPI_LIBRARY iphlpapi) + find_library (WINSOCK2_LIBRARY NAMES ws2_32 WS2_32 Ws2_32) + find_library (IPHLPAPI_LIBRARY NAMES iphlpapi) set (LDLIBS ${WINSOCK2_LIBRARY} ${IPHLPAPI_LIBRARY} ${LDLIBS}) #elseif (CMAKE_SYSTEM_NAME STREQUAL "Solaris") # find_library (SOCKET_LIBRARY NAMES socket) @@ -167,6 +165,8 @@ install (FILES igd_desc_parse.h upnpreplyparse.h upnperrors.h + miniupnpctypes.h + portlistingparse.h declspec.h DESTINATION include/miniupnpc ) diff --git a/external/miniupnpc/Changelog.txt b/external/miniupnpc/Changelog.txt index 53e9a112b..4bfd77cba 100755..100644 --- a/external/miniupnpc/Changelog.txt +++ b/external/miniupnpc/Changelog.txt @@ -1,6 +1,21 @@ -$Id: Changelog.txt,v 1.193 2014/02/05 17:26:45 nanard Exp $ +$Id: Changelog.txt,v 1.198 2014/09/11 14:13:31 nanard Exp $ miniUPnP client Changelog. +2014/09/11: + use remoteHost arg of DeletePortMapping + +2014/09/06: + Fix python3 build + +2014/07/01: + Fix parsing of IGD2 root descriptions + +2014/06/10: + rename LIBSPEC to MINIUPNP_LIBSPEC + +2014/05/15: + Add support for IGD2 AddAnyPortMapping and DeletePortMappingRange + 2014/02/05: handle EINPROGRESS after connect() diff --git a/external/miniupnpc/LICENSE b/external/miniupnpc/LICENSE index ac89a7516..566f0c9e6 100755..100644 --- a/external/miniupnpc/LICENSE +++ b/external/miniupnpc/LICENSE @@ -1,5 +1,5 @@ MiniUPnPc -Copyright (c) 2005-2011, Thomas BERNARD +Copyright (c) 2005-2014, Thomas BERNARD All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/external/miniupnpc/MANIFEST.in b/external/miniupnpc/MANIFEST.in index 54b86f95e..54b86f95e 100755..100644 --- a/external/miniupnpc/MANIFEST.in +++ b/external/miniupnpc/MANIFEST.in diff --git a/external/miniupnpc/Makefile b/external/miniupnpc/Makefile index eaf42f053..5713a8f0a 100755..100644 --- a/external/miniupnpc/Makefile +++ b/external/miniupnpc/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.107 2014/01/31 14:19:12 nanard Exp $ +# $Id: Makefile,v 1.110 2014/09/06 08:24:12 nanard Exp $ # MiniUPnP Project # http://miniupnp.free.fr/ # http://miniupnp.tuxfamily.org/ @@ -85,7 +85,7 @@ LIBRARY = libminiupnpc.a ifeq ($(OS), Darwin) SHAREDLIBRARY = libminiupnpc.dylib SONAME = $(basename $(SHAREDLIBRARY)).$(APIVERSION).dylib - CFLAGS := -DMACOSX -D_DARWIN_C_SOURCE $(CFLAGS) + CFLAGS := -D_DARWIN_C_SOURCE $(CFLAGS) else ifeq ($(JARSUFFIX), win32) SHAREDLIBRARY = miniupnpc.dll @@ -174,9 +174,11 @@ validateupnpreplyparse: testupnpreplyparse testupnpreplyparse.sh clean: $(RM) $(LIBRARY) $(SHAREDLIBRARY) $(EXECUTABLES) $(OBJS) miniupnpcstrings.h + $(RM) $(EXECUTABLES_ADDTESTS) # clean python stuff $(RM) pythonmodule pythonmodule3 $(RM) validateminixml validateminiwget validateupnpreplyparse + $(RM) minihttptestserver minihttptestserver.o $(RM) -r build/ dist/ #python setup.py clean # clean jnaerator stuff diff --git a/external/miniupnpc/Makefile.mingw b/external/miniupnpc/Makefile.mingw index 60b3f1b15..7b00650fc 100755..100644 --- a/external/miniupnpc/Makefile.mingw +++ b/external/miniupnpc/Makefile.mingw @@ -50,11 +50,11 @@ dll/upnpc.o: upnpc.o echo $@ generated with $< .c.o: - $(CC) $(CFLAGS) -DSTATICLIB -c -o $@ $< + $(CC) $(CFLAGS) -DMINIUPNP_STATICLIB -c -o $@ $< $(CC) $(CFLAGS) -DMINIUPNP_EXPORTS -c -o dll/$@ $< upnpc.o: - $(CC) $(CFLAGS) -DSTATICLIB -c -o $@ $< + $(CC) $(CFLAGS) -DMINIUPNP_STATICLIB -c -o $@ $< $(CC) $(CFLAGS) -c -o dll/$@ $< # --enable-stdcall-fixup diff --git a/external/miniupnpc/README b/external/miniupnpc/README index b23478de9..b23478de9 100755..100644 --- a/external/miniupnpc/README +++ b/external/miniupnpc/README diff --git a/external/miniupnpc/VERSION b/external/miniupnpc/VERSION index 2e0e38c63..2e0e38c63 100755..100644 --- a/external/miniupnpc/VERSION +++ b/external/miniupnpc/VERSION diff --git a/external/miniupnpc/apiversions.txt b/external/miniupnpc/apiversions.txt index 69f61c799..69f61c799 100755..100644 --- a/external/miniupnpc/apiversions.txt +++ b/external/miniupnpc/apiversions.txt diff --git a/external/miniupnpc/bsdqueue.h b/external/miniupnpc/bsdqueue.h index c6afe1f7c..c6afe1f7c 100755..100644 --- a/external/miniupnpc/bsdqueue.h +++ b/external/miniupnpc/bsdqueue.h diff --git a/external/miniupnpc/codelength.h b/external/miniupnpc/codelength.h index d342bd141..50d460679 100755..100644 --- a/external/miniupnpc/codelength.h +++ b/external/miniupnpc/codelength.h @@ -1,4 +1,4 @@ -/* $Id: codelength.h,v 1.4 2012/09/27 15:40:29 nanard Exp $ */ +/* $Id: codelength.h,v 1.3 2011/07/30 13:10:05 nanard Exp $ */ /* Project : miniupnp * Author : Thomas BERNARD * copyright (c) 2005-2011 Thomas Bernard diff --git a/external/miniupnpc/connecthostport.c b/external/miniupnpc/connecthostport.c index d66ae315f..98f72535d 100755..100644 --- a/external/miniupnpc/connecthostport.c +++ b/external/miniupnpc/connecthostport.c @@ -1,4 +1,4 @@ -/* $Id: connecthostport.c,v 1.13 2014/03/31 12:36:36 nanard Exp $ */ +/* $Id: connecthostport.c,v 1.12 2014/02/05 17:26:46 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard * Copyright (c) 2010-2014 Thomas Bernard @@ -35,7 +35,6 @@ #ifndef USE_GETHOSTBYNAME #include <sys/types.h> #include <sys/socket.h> -#include <sys/select.h> #endif /* #ifndef USE_GETHOSTBYNAME */ #endif /* #else _WIN32 */ diff --git a/external/miniupnpc/connecthostport.h b/external/miniupnpc/connecthostport.h index 56941d6fa..f3b2d2a84 100755..100644 --- a/external/miniupnpc/connecthostport.h +++ b/external/miniupnpc/connecthostport.h @@ -1,4 +1,4 @@ -/* $Id: connecthostport.h,v 1.3 2012/09/27 15:42:10 nanard Exp $ */ +/* $Id: connecthostport.h,v 1.2 2012/06/23 22:32:33 nanard Exp $ */ /* Project: miniupnp * http://miniupnp.free.fr/ * Author: Thomas Bernard diff --git a/external/miniupnpc/declspec.h b/external/miniupnpc/declspec.h index 77299693b..560aa3a6c 100755..100644 --- a/external/miniupnpc/declspec.h +++ b/external/miniupnpc/declspec.h @@ -1,19 +1,19 @@ #ifndef DECLSPEC_H_INCLUDED #define DECLSPEC_H_INCLUDED -#if defined(_WIN32) && !defined(STATICLIB) +#if defined(_WIN32) && !defined(MINIUPNP_STATICLIB) /* for windows dll */ #ifdef MINIUPNP_EXPORTS - #define LIBSPEC __declspec(dllexport) + #define MINIUPNP_LIBSPEC __declspec(dllexport) #else - #define LIBSPEC __declspec(dllimport) + #define MINIUPNP_LIBSPEC __declspec(dllimport) #endif #else #if defined(__GNUC__) && __GNUC__ >= 4 /* fix dynlib for OS X 10.9.2 and Apple LLVM version 5.0 */ - #define LIBSPEC __attribute__ ((visibility ("default"))) + #define MINIUPNP_LIBSPEC __attribute__ ((visibility ("default"))) #else - #define LIBSPEC + #define MINIUPNP_LIBSPEC #endif #endif diff --git a/external/miniupnpc/igd_desc_parse.c b/external/miniupnpc/igd_desc_parse.c index 6c3e65677..0eaf21b6a 100755..100644 --- a/external/miniupnpc/igd_desc_parse.c +++ b/external/miniupnpc/igd_desc_parse.c @@ -1,8 +1,8 @@ -/* $Id: igd_desc_parse.c,v 1.14 2011/04/11 09:19:24 nanard Exp $ */ +/* $Id: igd_desc_parse.c,v 1.15 2014/07/01 13:01:17 nanard Exp $ */ /* Project : miniupnp * http://miniupnp.free.fr/ * Author : Thomas Bernard - * Copyright (c) 2005-2010 Thomas Bernard + * Copyright (c) 2005-2014 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. */ @@ -26,6 +26,8 @@ void IGDstartelt(void * d, const char * name, int l) } } +#define COMPARE(str, cstr) (0==memcmp(str, cstr, sizeof(cstr) - 1)) + /* End element handler : * update nesting level counter and update parser state if * service element is parsed */ @@ -36,23 +38,16 @@ void IGDendelt(void * d, const char * name, int l) /*printf("endelt %2d %.*s\n", datas->level, l, name);*/ if( (l==7) && !memcmp(name, "service", l) ) { - /* - if( datas->state < 1 - && !strcmp(datas->servicetype, - // "urn:schemas-upnp-org:service:WANIPConnection:1") ) - "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")) - datas->state ++; - */ - if(0==strcmp(datas->tmp.servicetype, - "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")) { + if(COMPARE(datas->tmp.servicetype, + "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:")) { memcpy(&datas->CIF, &datas->tmp, sizeof(struct IGDdatas_service)); - } else if(0==strcmp(datas->tmp.servicetype, - "urn:schemas-upnp-org:service:WANIPv6FirewallControl:1")) { + } else if(COMPARE(datas->tmp.servicetype, + "urn:schemas-upnp-org:service:WANIPv6FirewallControl:")) { memcpy(&datas->IPv6FC, &datas->tmp, sizeof(struct IGDdatas_service)); - } else if(0==strcmp(datas->tmp.servicetype, - "urn:schemas-upnp-org:service:WANIPConnection:1") - || 0==strcmp(datas->tmp.servicetype, - "urn:schemas-upnp-org:service:WANPPPConnection:1") ) { + } else if(COMPARE(datas->tmp.servicetype, + "urn:schemas-upnp-org:service:WANIPConnection:") + || COMPARE(datas->tmp.servicetype, + "urn:schemas-upnp-org:service:WANPPPConnection:") ) { if(datas->first.servicetype[0] == '\0') { memcpy(&datas->first, &datas->tmp, sizeof(struct IGDdatas_service)); } else { diff --git a/external/miniupnpc/igd_desc_parse.h b/external/miniupnpc/igd_desc_parse.h index 0a49b019d..f5864b5c1 100755..100644 --- a/external/miniupnpc/igd_desc_parse.h +++ b/external/miniupnpc/igd_desc_parse.h @@ -1,4 +1,4 @@ -/* $Id: igd_desc_parse.h,v 1.11 2012/10/16 16:49:02 nanard Exp $ */ +/* $Id: igd_desc_parse.h,v 1.10 2011/04/11 09:19:24 nanard Exp $ */ /* Project : miniupnp * http://miniupnp.free.fr/ * Author : Thomas Bernard diff --git a/external/miniupnpc/java/.gitignore b/external/miniupnpc/java/.gitignore new file mode 100644 index 000000000..8e9e79486 --- /dev/null +++ b/external/miniupnpc/java/.gitignore @@ -0,0 +1,2 @@ +*.class +*.jar diff --git a/external/miniupnpc/java/JavaBridgeTest.java b/external/miniupnpc/java/JavaBridgeTest.java index a7fa56d8f..a7fa56d8f 100755..100644 --- a/external/miniupnpc/java/JavaBridgeTest.java +++ b/external/miniupnpc/java/JavaBridgeTest.java diff --git a/external/miniupnpc/man3/miniupnpc.3 b/external/miniupnpc/man3/miniupnpc.3 index 1b1664740..1b1664740 100755..100644 --- a/external/miniupnpc/man3/miniupnpc.3 +++ b/external/miniupnpc/man3/miniupnpc.3 diff --git a/external/miniupnpc/mingw32make.bat b/external/miniupnpc/mingw32make.bat index c5d3cc4ff..c5d3cc4ff 100755..100644 --- a/external/miniupnpc/mingw32make.bat +++ b/external/miniupnpc/mingw32make.bat diff --git a/external/miniupnpc/minihttptestserver.c b/external/miniupnpc/minihttptestserver.c index b71936117..fb779650b 100755..100644 --- a/external/miniupnpc/minihttptestserver.c +++ b/external/miniupnpc/minihttptestserver.c @@ -1,7 +1,7 @@ -/* $Id: minihttptestserver.c,v 1.13 2012/05/29 13:03:07 nanard Exp $ */ +/* $Id: minihttptestserver.c,v 1.16 2014/04/01 15:08:28 nanard Exp $ */ /* Project : miniUPnP * Author : Thomas Bernard - * Copyright (c) 2011-2012 Thomas Bernard + * Copyright (c) 2011-2014 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. * */ @@ -28,20 +28,20 @@ volatile sig_atomic_t child_to_wait_for = 0; */ void handle_signal_chld(int sig) { - printf("handle_signal_chld(%d)\n", sig); + (void)sig; + /* printf("handle_signal_chld(%d)\n", sig); */ ++child_to_wait_for; } /** * signal handler for SIGINT (CRTL C) */ -#if 0 void handle_signal_int(int sig) { - printf("handle_signal_int(%d)\n", sig); + (void)sig; + /* printf("handle_signal_int(%d)\n", sig); */ quit = 1; } -#endif /** * build a text/plain content of the specified length @@ -94,7 +94,8 @@ void build_crap(char * p, int n) * build chunked response. * return a malloc'ed buffer */ -char * build_chunked_response(int content_length, int * response_len) { +char * build_chunked_response(int content_length, int * response_len) +{ char * response_buffer; char * content_buffer; int buffer_length; @@ -141,7 +142,115 @@ char * build_chunked_response(int content_length, int * response_len) { return response_buffer; } -enum modes { MODE_INVALID, MODE_CHUNKED, MODE_ADDCRAP, MODE_NORMAL }; +/* favicon.ico generator */ +#ifdef OLD_HEADER +#define FAVICON_LENGTH (6 + 16 + 12 + 8 + 32 * 4) +#else +#define FAVICON_LENGTH (6 + 16 + 40 + 8 + 32 * 4) +#endif +void build_favicon_content(char * p, int n) +{ + int i; + if(n < FAVICON_LENGTH) + return; + /* header : 6 bytes */ + *p++ = 0; + *p++ = 0; + *p++ = 1; /* type : ICO */ + *p++ = 0; + *p++ = 1; /* number of images in file */ + *p++ = 0; + /* image directory (1 entry) : 16 bytes */ + *p++ = 16; /* width */ + *p++ = 16; /* height */ + *p++ = 2; /* number of colors in the palette. 0 = no palette */ + *p++ = 0; /* reserved */ + *p++ = 1; /* color planes */ + *p++ = 0; /* " */ + *p++ = 1; /* bpp */ + *p++ = 0; /* " */ +#ifdef OLD_HEADER + *p++ = 12 + 8 + 32 * 4; /* bmp size */ +#else + *p++ = 40 + 8 + 32 * 4; /* bmp size */ +#endif + *p++ = 0; /* " */ + *p++ = 0; /* " */ + *p++ = 0; /* " */ + *p++ = 6 + 16; /* bmp offset */ + *p++ = 0; /* " */ + *p++ = 0; /* " */ + *p++ = 0; /* " */ + /* BMP */ +#ifdef OLD_HEADER + /* BITMAPCOREHEADER */ + *p++ = 12; /* size of this header */ + *p++ = 0; /* " */ + *p++ = 0; /* " */ + *p++ = 0; /* " */ + *p++ = 16; /* width */ + *p++ = 0; /* " */ + *p++ = 16 * 2; /* height x 2 ! */ + *p++ = 0; /* " */ + *p++ = 1; /* color planes */ + *p++ = 0; /* " */ + *p++ = 1; /* bpp */ + *p++ = 0; /* " */ +#else + /* BITMAPINFOHEADER */ + *p++ = 40; /* size of this header */ + *p++ = 0; /* " */ + *p++ = 0; /* " */ + *p++ = 0; /* " */ + *p++ = 16; /* width */ + *p++ = 0; /* " */ + *p++ = 0; /* " */ + *p++ = 0; /* " */ + *p++ = 16 * 2; /* height x 2 ! */ + *p++ = 0; /* " */ + *p++ = 0; /* " */ + *p++ = 0; /* " */ + *p++ = 1; /* color planes */ + *p++ = 0; /* " */ + *p++ = 1; /* bpp */ + *p++ = 0; /* " */ + /* compression method, image size, ppm x, ppm y */ + /* colors in the palette ? */ + /* important colors */ + for(i = 4 * 6; i > 0; --i) + *p++ = 0; +#endif + /* palette */ + *p++ = 0; /* b */ + *p++ = 0; /* g */ + *p++ = 0; /* r */ + *p++ = 0; /* reserved */ + *p++ = 255; /* b */ + *p++ = 255; /* g */ + *p++ = 255; /* r */ + *p++ = 0; /* reserved */ + /* pixel data */ + for(i = 16; i > 0; --i) { + if(i & 1) { + *p++ = 0125; + *p++ = 0125; + } else { + *p++ = 0252; + *p++ = 0252; + } + *p++ = 0; + *p++ = 0; + } + /* Opacity MASK */ + for(i = 16 * 4; i > 0; --i) { + *p++ = 0; + } +} + +enum modes { + MODE_INVALID, MODE_CHUNKED, MODE_ADDCRAP, MODE_NORMAL, MODE_FAVICON +}; + const struct { const enum modes mode; const char * text; @@ -149,6 +258,7 @@ const struct { {MODE_CHUNKED, "chunked"}, {MODE_ADDCRAP, "addcrap"}, {MODE_NORMAL, "normal"}, + {MODE_FAVICON, "favicon.ico"}, {MODE_INVALID, NULL} }; @@ -201,6 +311,8 @@ void handle_http_connection(int c) request_buffer + request_len, sizeof(request_buffer) - request_len); if(n < 0) { + if(errno == EINTR) + continue; perror("read"); return; } else if(n==0) { @@ -219,6 +331,7 @@ void handle_http_connection(int c) } if(!headers_found) { /* error */ + printf("no HTTP header found in the request\n"); return; } printf("headers :\n%.*s", request_len, request_buffer); @@ -292,6 +405,8 @@ void handle_http_connection(int c) case MODE_ADDCRAP: response_len = content_length+256; response_buffer = malloc(response_len); + if(!response_buffer) + break; n = snprintf(response_buffer, response_len, "HTTP/1.1 200 OK\r\n" "Server: minihttptestserver\r\n" @@ -303,9 +418,27 @@ void handle_http_connection(int c) build_content(response_buffer + n, content_length); build_crap(response_buffer + n + content_length, CRAP_LENGTH); break; + case MODE_FAVICON: + content_length = FAVICON_LENGTH; + response_len = content_length + 256; + response_buffer = malloc(response_len); + if(!response_buffer) + break; + n = snprintf(response_buffer, response_len, + "HTTP/1.1 200 OK\r\n" + "Server: minihttptestserver\r\n" + "Content-Type: image/vnd.microsoft.icon\r\n" + "Content-Length: %d\r\n" + "\r\n", content_length); + /* image/x-icon */ + build_favicon_content(response_buffer + n, content_length); + response_len = content_length + n; + break; default: response_len = content_length+256; response_buffer = malloc(response_len); + if(!response_buffer) + break; n = snprintf(response_buffer, response_len, "HTTP/1.1 200 OK\r\n" "Server: minihttptestserver\r\n" @@ -338,6 +471,7 @@ int main(int argc, char * * argv) { int child = 0; int status; const char * expected_file_name = NULL; + struct sigaction sa; for(i = 1; i < argc; i++) { if(argv[i][0] == '-') { @@ -364,10 +498,21 @@ int main(int argc, char * * argv) { } srand(time(NULL)); - signal(SIGCHLD, handle_signal_chld); -#if 0 - signal(SIGINT, handle_signal_int); -#endif + + memset(&sa, 0, sizeof(struct sigaction)); + + /*signal(SIGCHLD, handle_signal_chld);*/ + sa.sa_handler = handle_signal_chld; + if(sigaction(SIGCHLD, &sa, NULL) < 0) { + perror("sigaction"); + return 1; + } + /*signal(SIGINT, handle_signal_int);*/ + sa.sa_handler = handle_signal_int; + if(sigaction(SIGINT, &sa, NULL) < 0) { + perror("sigaction"); + return 1; + } s = socket(ipv6 ? AF_INET6 : AF_INET, SOCK_STREAM, 0); if(s < 0) { @@ -442,12 +587,12 @@ int main(int argc, char * * argv) { } --child_to_wait_for; } - /* TODO : add a select() call in order to handle the case - * when a signal is caught */ client_addrlen = sizeof(struct sockaddr_storage); c = accept(s, (struct sockaddr *)&client_addr, &client_addrlen); if(c < 0) { + if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) + continue; perror("accept"); return 1; } diff --git a/external/miniupnpc/minisoap.c b/external/miniupnpc/minisoap.c index e45a481ac..e45a481ac 100755..100644 --- a/external/miniupnpc/minisoap.c +++ b/external/miniupnpc/minisoap.c diff --git a/external/miniupnpc/minisoap.h b/external/miniupnpc/minisoap.h index 14c859d1e..60554f5c3 100755..100644 --- a/external/miniupnpc/minisoap.h +++ b/external/miniupnpc/minisoap.h @@ -1,4 +1,4 @@ -/* $Id: minisoap.h,v 1.5 2012/09/27 15:42:10 nanard Exp $ */ +/* $Id: minisoap.h,v 1.4 2010/04/12 20:39:41 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard * Copyright (c) 2005 Thomas Bernard diff --git a/external/miniupnpc/minissdpc.c b/external/miniupnpc/minissdpc.c index c4913fb89..8b7421b00 100755..100644 --- a/external/miniupnpc/minissdpc.c +++ b/external/miniupnpc/minissdpc.c @@ -1,4 +1,4 @@ -/* $Id: minissdpc.c,v 1.16 2012/03/05 19:42:46 nanard Exp $ */ +/* $Id: minissdpc.c,v 1.15 2012/01/21 13:30:31 nanard Exp $ */ /* Project : miniupnp * Web : http://miniupnp.free.fr/ * Author : Thomas BERNARD @@ -46,7 +46,7 @@ getDevicesFromMiniSSDPD(const char * devtype, const char * socketpath) { struct UPNPDev * tmp; struct UPNPDev * devlist = NULL; - unsigned char buffer[2048]; + unsigned char buffer[4*1024]; /* is that enough ? */ ssize_t n; unsigned char * p; unsigned char * url; diff --git a/external/miniupnpc/minissdpc.h b/external/miniupnpc/minissdpc.h index 915b0026f..2516f487a 100755..100644 --- a/external/miniupnpc/minissdpc.h +++ b/external/miniupnpc/minissdpc.h @@ -1,4 +1,4 @@ -/* $Id: minissdpc.h,v 1.2 2012/09/27 15:42:10 nanard Exp $ */ +/* $Id: minissdpc.h,v 1.1 2007/08/31 15:15:33 nanard Exp $ */ /* Project: miniupnp * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * Author: Thomas Bernard diff --git a/external/miniupnpc/miniupnpc.c b/external/miniupnpc/miniupnpc.c index f661c2e6f..1da230f52 100755..100644 --- a/external/miniupnpc/miniupnpc.c +++ b/external/miniupnpc/miniupnpc.c @@ -1,4 +1,4 @@ -/* $Id: miniupnpc.c,v 1.117 2014/01/31 14:19:13 nanard Exp $ */ +/* $Id: miniupnpc.c,v 1.116 2014/01/31 14:09:03 nanard Exp $ */ /* Project : miniupnp * Web : http://miniupnp.free.fr/ * Author : Thomas BERNARD @@ -6,7 +6,7 @@ * This software is subjet to the conditions detailed in the * provided LICENSE file. */ #define __EXTENSIONS__ 1 -#if !defined(MACOSX) && !defined(__sun) +#if !defined(__APPLE__) && !defined(__sun) #if !defined(_XOPEN_SOURCE) && !defined(__OpenBSD__) && !defined(__NetBSD__) #ifndef __cplusplus #define _XOPEN_SOURCE 600 @@ -17,7 +17,7 @@ #endif #endif -#if !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(MACOSX) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(__sun) +#if !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(__sun) && !defined(__GNU__) && !defined(__FreeBSD_kernel__) #define HAS_IP_MREQN #endif @@ -70,6 +70,9 @@ /* Amiga OS specific stuff */ #define TIMEVAL struct timeval #endif +#ifdef __GNU__ +#define MAXHOSTNAMELEN 64 +#endif #if defined(HAS_IP_MREQN) && defined(NEED_STRUCT_IP_MREQN) @@ -106,7 +109,7 @@ struct ip_mreqn #define SERVICEPREFIX2 'u' /* root description parsing */ -LIBSPEC void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data) +MINIUPNP_LIBSPEC void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data) { struct xmlparser parser; /* xmlparser object */ @@ -335,7 +338,7 @@ parseMSEARCHReply(const char * reply, int size, * no devices was found. * It is up to the caller to free the chained list * delay is in millisecond (poll) */ -LIBSPEC struct UPNPDev * +MINIUPNP_LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif, const char * minissdpdsock, int sameport, int ipv6, @@ -718,7 +721,7 @@ upnpDiscover(int delay, const char * multicastif, /* freeUPNPDevlist() should be used to * free the chained list returned by upnpDiscover() */ -LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist) +MINIUPNP_LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist) { struct UPNPDev * next; while(devlist) @@ -754,7 +757,7 @@ url_cpy_or_cat(char * dst, const char * src, int n) /* Prepare the Urls for usage... */ -LIBSPEC void +MINIUPNP_LIBSPEC void GetUPNPUrls(struct UPNPUrls * urls, struct IGDdatas * data, const char * descURL, unsigned int scope_id) { @@ -844,7 +847,7 @@ GetUPNPUrls(struct UPNPUrls * urls, struct IGDdatas * data, #endif } -LIBSPEC void +MINIUPNP_LIBSPEC void FreeUPNPUrls(struct UPNPUrls * urls) { if(!urls) @@ -891,7 +894,7 @@ UPNPIGD_IsConnected(struct UPNPUrls * urls, struct IGDdatas * data) * passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to * free allocated memory. */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetValidIGD(struct UPNPDev * devlist, struct UPNPUrls * urls, struct IGDdatas * data, diff --git a/external/miniupnpc/miniupnpc.def b/external/miniupnpc/miniupnpc.def index 334335606..60e0bbe42 100755..100644 --- a/external/miniupnpc/miniupnpc.def +++ b/external/miniupnpc/miniupnpc.def @@ -24,7 +24,9 @@ EXPORTS UPNP_GetExternalIPAddress UPNP_GetLinkLayerMaxBitRates UPNP_AddPortMapping + UPNP_AddAnyPortMapping UPNP_DeletePortMapping + UPNP_DeletePortMappingRange UPNP_GetPortMappingNumberOfEntries UPNP_GetSpecificPortMappingEntry UPNP_GetGenericPortMappingEntry diff --git a/external/miniupnpc/miniupnpc.h b/external/miniupnpc/miniupnpc.h index 3af109cf1..304de90f2 100755..100644 --- a/external/miniupnpc/miniupnpc.h +++ b/external/miniupnpc/miniupnpc.h @@ -1,4 +1,4 @@ -/* $Id: miniupnpc.h,v 1.35 2014/01/31 13:26:34 nanard Exp $ */ +/* $Id: miniupnpc.h,v 1.34 2014/01/31 13:18:25 nanard Exp $ */ /* Project: miniupnp * http://miniupnp.free.fr/ * Author: Thomas Bernard @@ -18,7 +18,7 @@ #define UPNPDISCOVER_MEMORY_ERROR (-102) /* versions : */ -#define MINIUPNPC_VERSION "1.9.20140401" +#define MINIUPNPC_VERSION "1.9" #define MINIUPNPC_API_VERSION 10 #ifdef __cplusplus @@ -54,19 +54,19 @@ struct UPNPDev { * multicast interface for sending SSDP discover packets. * If sameport is not null, SSDP packets will be sent from the source port * 1900 (same as destination port) otherwise system assign a source port. */ -LIBSPEC struct UPNPDev * +MINIUPNP_LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif, const char * minissdpdsock, int sameport, int ipv6, int * error); /* freeUPNPDevlist() * free list returned by upnpDiscover() */ -LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist); +MINIUPNP_LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist); /* parserootdesc() : * parse root XML description of a UPnP device and fill the IGDdatas * structure. */ -LIBSPEC void parserootdesc(const char *, int, struct IGDdatas *); +MINIUPNP_LIBSPEC void parserootdesc(const char *, int, struct IGDdatas *); /* structure used to get fast access to urls * controlURL: controlURL of the WANIPConnection @@ -94,7 +94,7 @@ struct UPNPUrls { * passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to * free allocated memory. */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetValidIGD(struct UPNPDev * devlist, struct UPNPUrls * urls, struct IGDdatas * data, @@ -105,21 +105,21 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, * return value : * 0 - Not ok * 1 - OK */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetIGDFromUrl(const char * rootdescurl, struct UPNPUrls * urls, struct IGDdatas * data, char * lanaddr, int lanaddrlen); -LIBSPEC void +MINIUPNP_LIBSPEC void GetUPNPUrls(struct UPNPUrls *, struct IGDdatas *, const char *, unsigned int); -LIBSPEC void +MINIUPNP_LIBSPEC void FreeUPNPUrls(struct UPNPUrls *); /* return 0 or 1 */ -LIBSPEC int UPNPIGD_IsConnected(struct UPNPUrls *, struct IGDdatas *); +MINIUPNP_LIBSPEC int UPNPIGD_IsConnected(struct UPNPUrls *, struct IGDdatas *); #ifdef __cplusplus diff --git a/external/miniupnpc/miniupnpcmodule.c b/external/miniupnpc/miniupnpcmodule.c index 4654c9870..ecddf7e84 100755..100644 --- a/external/miniupnpc/miniupnpcmodule.c +++ b/external/miniupnpc/miniupnpcmodule.c @@ -1,4 +1,4 @@ -/* $Id: miniupnpcmodule.c,v 1.22 2014/01/31 13:18:25 nanard Exp $*/ +/* $Id: miniupnpcmodule.c,v 1.24 2014/06/10 09:48:11 nanard Exp $*/ /* Project : miniupnp * Author : Thomas BERNARD * website : http://miniupnp.tuxfamily.org/ @@ -6,7 +6,7 @@ * This software is subjet to the conditions detailed in the * provided LICENCE file. */ #include <Python.h> -#define STATICLIB +#define MINIUPNP_STATICLIB #include "structmember.h" #include "miniupnpc.h" #include "upnpcommands.h" @@ -265,6 +265,42 @@ Py_END_ALLOW_THREADS } } +/* AddAnyPortMapping(externalPort, protocol, internalHost, internalPort, desc, + * remoteHost) + * protocol is 'UDP' or 'TCP' */ +static PyObject * +UPnP_addanyportmapping(UPnPObject *self, PyObject *args) +{ + char extPort[6]; + unsigned short ePort; + char inPort[6]; + unsigned short iPort; + char reservedPort[6]; + const char * proto; + const char * host; + const char * desc; + const char * remoteHost; + const char * leaseDuration = "0"; + int r; + if (!PyArg_ParseTuple(args, "HssHss", &ePort, &proto, &host, &iPort, &desc, &remoteHost)) + return NULL; +Py_BEGIN_ALLOW_THREADS + sprintf(extPort, "%hu", ePort); + sprintf(inPort, "%hu", iPort); + r = UPNP_AddAnyPortMapping(self->urls.controlURL, self->data.first.servicetype, + extPort, inPort, host, desc, proto, + remoteHost, leaseDuration, reservedPort); +Py_END_ALLOW_THREADS + if(r==UPNPCOMMAND_SUCCESS) { + return Py_BuildValue("i", atoi(reservedPort)); + } else { + /* TODO: have our own exception type ! */ + PyErr_SetString(PyExc_Exception, strupnperror(r)); + return NULL; + } +} + + /* DeletePortMapping(extPort, proto, removeHost='') * proto = 'UDP', 'TCP' */ static PyObject * @@ -291,6 +327,37 @@ Py_END_ALLOW_THREADS } } +/* DeletePortMappingRange(extPort, proto, removeHost='') + * proto = 'UDP', 'TCP' */ +static PyObject * +UPnP_deleteportmappingrange(UPnPObject *self, PyObject *args) +{ + char extPortStart[6]; + unsigned short ePortStart; + char extPortEnd[6]; + unsigned short ePortEnd; + const char * proto; + unsigned char manage; + char manageStr[1]; + int r; + if(!PyArg_ParseTuple(args, "HHsb", &ePortStart, &ePortEnd, &proto, &manage)) + return NULL; +Py_BEGIN_ALLOW_THREADS + sprintf(extPortStart, "%hu", ePortStart); + sprintf(extPortEnd, "%hu", ePortEnd); + sprintf(manageStr, "%hhu", manage); + r = UPNP_DeletePortMappingRange(self->urls.controlURL, self->data.first.servicetype, + extPortStart, extPortEnd, proto, manageStr); +Py_END_ALLOW_THREADS + if(r==UPNPCOMMAND_SUCCESS) { + Py_RETURN_TRUE; + } else { + /* TODO: have our own exception type ! */ + PyErr_SetString(PyExc_Exception, strupnperror(r)); + return NULL; + } +} + static PyObject * UPnP_getportmappingnumberofentries(UPnPObject *self) { @@ -429,9 +496,15 @@ static PyMethodDef UPnP_methods[] = { {"addportmapping", (PyCFunction)UPnP_addportmapping, METH_VARARGS, "add a port mapping" }, + {"addanyportmapping", (PyCFunction)UPnP_addanyportmapping, METH_VARARGS, + "add a port mapping, IGD to select alternative if necessary" + }, {"deleteportmapping", (PyCFunction)UPnP_deleteportmapping, METH_VARARGS, "delete a port mapping" }, + {"deleteportmappingrange", (PyCFunction)UPnP_deleteportmappingrange, METH_VARARGS, + "delete a range of port mappings" + }, {"getportmappingnumberofentries", (PyCFunction)UPnP_getportmappingnumberofentries, METH_NOARGS, "-- non standard --" }, @@ -526,7 +599,11 @@ initminiupnpc(void) UPnPType.tp_new = PyType_GenericNew; #endif if (PyType_Ready(&UPnPType) < 0) +#if PY_MAJOR_VERSION >= 3 + return 0; +#else return; +#endif #if PY_MAJOR_VERSION >= 3 m = PyModule_Create(&moduledef); @@ -537,7 +614,7 @@ initminiupnpc(void) Py_INCREF(&UPnPType); PyModule_AddObject(m, "UPnP", (PyObject *)&UPnPType); - + #if PY_MAJOR_VERSION >= 3 return m; #endif diff --git a/external/miniupnpc/miniupnpcstrings.h.cmake b/external/miniupnpc/miniupnpcstrings.h.cmake index 236b2dca6..236b2dca6 100755..100644 --- a/external/miniupnpc/miniupnpcstrings.h.cmake +++ b/external/miniupnpc/miniupnpcstrings.h.cmake diff --git a/external/miniupnpc/miniupnpcstrings.h.in b/external/miniupnpc/miniupnpcstrings.h.in index c32e3a133..93b8cbc66 100755..100644 --- a/external/miniupnpc/miniupnpcstrings.h.in +++ b/external/miniupnpc/miniupnpcstrings.h.in @@ -1,4 +1,4 @@ -/* $Id: miniupnpcstrings.h.in,v 1.5 2012/10/16 16:48:26 nanard Exp $ */ +/* $Id: miniupnpcstrings.h.in,v 1.4 2011/01/04 11:41:53 nanard Exp $ */ /* Project: miniupnp * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * Author: Thomas Bernard diff --git a/external/miniupnpc/miniupnpctypes.h b/external/miniupnpc/miniupnpctypes.h index 591c32fb6..307ce3969 100755..100644 --- a/external/miniupnpc/miniupnpctypes.h +++ b/external/miniupnpc/miniupnpctypes.h @@ -1,4 +1,4 @@ -/* $Id: miniupnpctypes.h,v 1.2 2012/09/27 15:42:10 nanard Exp $ */ +/* $Id: miniupnpctypes.h,v 1.1 2011/02/15 11:10:40 nanard Exp $ */ /* Miniupnp project : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org * Author : Thomas Bernard * Copyright (c) 2011 Thomas Bernard diff --git a/external/miniupnpc/miniwget.c b/external/miniupnpc/miniwget.c index 813db9324..4a4a9393d 100755..100644 --- a/external/miniupnpc/miniwget.c +++ b/external/miniupnpc/miniwget.c @@ -15,7 +15,6 @@ #include <ws2tcpip.h> #include <io.h> #define MAXHOSTNAMELEN 64 -#define MIN(x,y) (((x)<(y))?(x):(y)) #define snprintf _snprintf #define socklen_t int #ifndef strncasecmp @@ -40,9 +39,14 @@ #include <netdb.h> #define closesocket close #endif /* #else _WIN32 */ -#if defined(__sun) || defined(sun) +#ifdef __GNU__ +#define MAXHOSTNAMELEN 64 +#endif /* __GNU__ */ + +#ifndef MIN #define MIN(x,y) (((x)<(y))?(x):(y)) -#endif +#endif /* MIN */ + #include "miniupnpcstrings.h" #include "miniwget.h" diff --git a/external/miniupnpc/miniwget.h b/external/miniupnpc/miniwget.h index 31bcea322..04a8de2db 100755..100644 --- a/external/miniupnpc/miniwget.h +++ b/external/miniupnpc/miniwget.h @@ -1,4 +1,4 @@ -/* $Id: miniwget.h,v 1.8 2012/09/27 15:42:10 nanard Exp $ */ +/* $Id: miniwget.h,v 1.7 2012/06/23 22:35:59 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard * Copyright (c) 2005-2012 Thomas Bernard @@ -14,11 +14,11 @@ extern "C" { #endif -LIBSPEC void * getHTTPResponse(int s, int * size); +MINIUPNP_LIBSPEC void * getHTTPResponse(int s, int * size); -LIBSPEC void * miniwget(const char *, int *, unsigned int); +MINIUPNP_LIBSPEC void * miniwget(const char *, int *, unsigned int); -LIBSPEC void * miniwget_getaddr(const char *, int *, char *, int, unsigned int); +MINIUPNP_LIBSPEC void * miniwget_getaddr(const char *, int *, char *, int, unsigned int); int parseURL(const char *, char *, unsigned short *, char * *, unsigned int *); diff --git a/external/miniupnpc/minixml.c b/external/miniupnpc/minixml.c index 3e201ec2c..1f2227343 100755..100644 --- a/external/miniupnpc/minixml.c +++ b/external/miniupnpc/minixml.c @@ -1,4 +1,4 @@ -/* $Id: minixml.c,v 1.11 2014/02/03 15:54:12 nanard Exp $ */ +/* $Id: minixml.c,v 1.10 2012/03/05 19:42:47 nanard Exp $ */ /* minixml.c : the minimum size a xml parser can be ! */ /* Project : miniupnp * webpage: http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ diff --git a/external/miniupnpc/minixml.h b/external/miniupnpc/minixml.h index 9f43aa48c..19e6f513b 100755..100644 --- a/external/miniupnpc/minixml.h +++ b/external/miniupnpc/minixml.h @@ -1,4 +1,4 @@ -/* $Id: minixml.h,v 1.7 2012/09/27 15:42:10 nanard Exp $ */ +/* $Id: minixml.h,v 1.6 2006/11/30 11:47:21 nanard Exp $ */ /* minimal xml parser * * Project : miniupnp diff --git a/external/miniupnpc/minixmlvalid.c b/external/miniupnpc/minixmlvalid.c index 0a112bf89..0a112bf89 100755..100644 --- a/external/miniupnpc/minixmlvalid.c +++ b/external/miniupnpc/minixmlvalid.c diff --git a/external/miniupnpc/msvc/miniupnpc.sln b/external/miniupnpc/msvc/miniupnpc.sln index b3da1919e..b3da1919e 100755..100644 --- a/external/miniupnpc/msvc/miniupnpc.sln +++ b/external/miniupnpc/msvc/miniupnpc.sln diff --git a/external/miniupnpc/msvc/miniupnpc.vcproj b/external/miniupnpc/msvc/miniupnpc.vcproj index 12a55aaff..ca7a0821a 100755..100644 --- a/external/miniupnpc/msvc/miniupnpc.vcproj +++ b/external/miniupnpc/msvc/miniupnpc.vcproj @@ -41,7 +41,7 @@ <Tool Name="VCCLCompilerTool" Optimization="0" - PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS;WIN32;STATICLIB;DEBUG" + PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS;MINIUPNP_STATICLIB;DEBUG" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -104,7 +104,7 @@ Name="VCCLCompilerTool" Optimization="2" EnableIntrinsicFunctions="true" - PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS;WIN32;STATICLIB" + PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS;MINIUPNP_STATICLIB" RuntimeLibrary="2" EnableFunctionLevelLinking="true" UsePrecompiledHeader="0" diff --git a/external/miniupnpc/msvc/upnpc-static.vcproj b/external/miniupnpc/msvc/upnpc-static.vcproj index 294613877..c88c9a6e9 100755..100644 --- a/external/miniupnpc/msvc/upnpc-static.vcproj +++ b/external/miniupnpc/msvc/upnpc-static.vcproj @@ -41,7 +41,7 @@ <Tool Name="VCCLCompilerTool" Optimization="0" - PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;STATICLIB;DEBUG;_CRT_SECURE_NO_WARNINGS" + PreprocessorDefinitions="_DEBUG;_CONSOLE;MINIUPNP_STATICLIB;DEBUG;_CRT_SECURE_NO_WARNINGS" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -115,7 +115,7 @@ Name="VCCLCompilerTool" Optimization="2" EnableIntrinsicFunctions="true" - PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;STATICLIB" + PreprocessorDefinitions="NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;MINIUPNP_STATICLIB" RuntimeLibrary="2" EnableFunctionLevelLinking="true" UsePrecompiledHeader="0" diff --git a/external/miniupnpc/portlistingparse.c b/external/miniupnpc/portlistingparse.c index 19e3054eb..19e3054eb 100755..100644 --- a/external/miniupnpc/portlistingparse.c +++ b/external/miniupnpc/portlistingparse.c diff --git a/external/miniupnpc/portlistingparse.h b/external/miniupnpc/portlistingparse.h index bafa2a47c..a410202e3 100755..100644 --- a/external/miniupnpc/portlistingparse.h +++ b/external/miniupnpc/portlistingparse.h @@ -1,4 +1,4 @@ -/* $Id: portlistingparse.h,v 1.7 2012/09/27 15:42:10 nanard Exp $ */ +/* $Id: portlistingparse.h,v 1.5 2012/01/21 13:30:33 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * (c) 2011-2012 Thomas Bernard @@ -57,11 +57,11 @@ struct PortMappingParserData { portMappingElt curelt; }; -LIBSPEC void +MINIUPNP_LIBSPEC void ParsePortListing(const char * buffer, int bufsize, struct PortMappingParserData * pdata); -LIBSPEC void +MINIUPNP_LIBSPEC void FreePortListing(struct PortMappingParserData * pdata); #ifdef __cplusplus diff --git a/external/miniupnpc/receivedata.c b/external/miniupnpc/receivedata.c index ffbfbead6..f9b9901fc 100755..100644 --- a/external/miniupnpc/receivedata.c +++ b/external/miniupnpc/receivedata.c @@ -1,4 +1,4 @@ -/* $Id: receivedata.c,v 1.5 2013/10/07 09:48:36 nanard Exp $ */ +/* $Id: receivedata.c,v 1.4 2012/06/23 22:34:47 nanard Exp $ */ /* Project : miniupnp * Website : http://miniupnp.free.fr/ * Author : Thomas Bernard @@ -40,12 +40,7 @@ receivedata(int socket, int timeout, unsigned int * scope_id) { #if MINIUPNPC_GET_SRC_ADDR -#ifdef DEBUG - /* to shut up valgrind about uninit value */ - struct sockaddr_storage src_addr = {0}; -#else struct sockaddr_storage src_addr; -#endif socklen_t src_addr_len = sizeof(src_addr); #endif int n; diff --git a/external/miniupnpc/receivedata.h b/external/miniupnpc/receivedata.h index 0520a11d3..cb85c3317 100755..100644 --- a/external/miniupnpc/receivedata.h +++ b/external/miniupnpc/receivedata.h @@ -1,4 +1,4 @@ -/* $Id: receivedata.h,v 1.4 2012/09/27 15:42:10 nanard Exp $ */ +/* $Id: receivedata.h,v 1.3 2012/06/23 22:34:47 nanard Exp $ */ /* Project: miniupnp * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * Author: Thomas Bernard diff --git a/external/miniupnpc/setup.py b/external/miniupnpc/setup.py index 63a275cb3..f0b6ce1df 100755..100644 --- a/external/miniupnpc/setup.py +++ b/external/miniupnpc/setup.py @@ -1,6 +1,6 @@ #! /usr/bin/python # $Id: setup.py,v 1.9 2012/05/23 08:50:10 nanard Exp $ -# the MiniUPnP Project (c) 2007-2012 Thomas Bernard +# the MiniUPnP Project (c) 2007-2014 Thomas Bernard # http://miniupnp.tuxfamily.org/ or http://miniupnp.free.fr/ # # python script to build the miniupnpc module under unix @@ -10,9 +10,15 @@ from distutils.core import setup, Extension from distutils import sysconfig sysconfig.get_config_vars()["OPT"] = '' sysconfig.get_config_vars()["CFLAGS"] = '' -setup(name="miniupnpc", version="1.7", +setup(name="miniupnpc", + version=open('VERSION').read().strip(), + author='Thomas BERNARD', + author_email='miniupnp@free.fr', + license=open('LICENSE').read(), + url='http://miniupnp.free.fr/', + description='miniUPnP client', ext_modules=[ - Extension(name="miniupnpc", sources=["miniupnpcmodule.c"], - extra_objects=["libminiupnpc.a"]) - ]) + Extension(name="miniupnpc", sources=["miniupnpcmodule.c"], + extra_objects=["libminiupnpc.a"]) + ]) diff --git a/external/miniupnpc/setupmingw32.py b/external/miniupnpc/setupmingw32.py index cb23d1d3b..6dcfce799 100755..100644 --- a/external/miniupnpc/setupmingw32.py +++ b/external/miniupnpc/setupmingw32.py @@ -1,6 +1,6 @@ #! /usr/bin/python # $Id: setupmingw32.py,v 1.8 2012/05/23 08:50:10 nanard Exp $ -# the MiniUPnP Project (c) 2007-2012 Thomas Bernard +# the MiniUPnP Project (c) 2007-2014 Thomas Bernard # http://miniupnp.tuxfamily.org/ or http://miniupnp.free.fr/ # # python script to build the miniupnpc module under windows (using mingw32) @@ -9,10 +9,16 @@ from distutils.core import setup, Extension from distutils import sysconfig sysconfig.get_config_vars()["OPT"] = '' sysconfig.get_config_vars()["CFLAGS"] = '' -setup(name="miniupnpc", version="1.7", +setup(name="miniupnpc", + version=open('VERSION').read().strip(), + author='Thomas BERNARD', + author_email='miniupnp@free.fr', + license=open('LICENSE').read(), + url='http://miniupnp.free.fr/', + description='miniUPnP client', ext_modules=[ - Extension(name="miniupnpc", sources=["miniupnpcmodule.c"], - libraries=["ws2_32", "iphlpapi"], - extra_objects=["libminiupnpc.a"]) - ]) + Extension(name="miniupnpc", sources=["miniupnpcmodule.c"], + libraries=["ws2_32", "iphlpapi"], + extra_objects=["libminiupnpc.a"]) + ]) diff --git a/external/miniupnpc/testigddescparse.c b/external/miniupnpc/testigddescparse.c index 1c0028a02..1c0028a02 100755..100644 --- a/external/miniupnpc/testigddescparse.c +++ b/external/miniupnpc/testigddescparse.c diff --git a/external/miniupnpc/testminiwget.c b/external/miniupnpc/testminiwget.c index 8ae90320e..8ae90320e 100755..100644 --- a/external/miniupnpc/testminiwget.c +++ b/external/miniupnpc/testminiwget.c diff --git a/external/miniupnpc/testminixml.c b/external/miniupnpc/testminixml.c index d0fe794a4..d0fe794a4 100755..100644 --- a/external/miniupnpc/testminixml.c +++ b/external/miniupnpc/testminixml.c diff --git a/external/miniupnpc/testreplyparse/DeletePortMapping.namevalue b/external/miniupnpc/testreplyparse/DeletePortMapping.namevalue index 48ca0cccb..48ca0cccb 100755..100644 --- a/external/miniupnpc/testreplyparse/DeletePortMapping.namevalue +++ b/external/miniupnpc/testreplyparse/DeletePortMapping.namevalue diff --git a/external/miniupnpc/testreplyparse/DeletePortMapping.xml b/external/miniupnpc/testreplyparse/DeletePortMapping.xml index a955c53fc..a955c53fc 100755..100644 --- a/external/miniupnpc/testreplyparse/DeletePortMapping.xml +++ b/external/miniupnpc/testreplyparse/DeletePortMapping.xml diff --git a/external/miniupnpc/testreplyparse/GetExternalIPAddress.namevalue b/external/miniupnpc/testreplyparse/GetExternalIPAddress.namevalue index 5aa75f882..5aa75f882 100755..100644 --- a/external/miniupnpc/testreplyparse/GetExternalIPAddress.namevalue +++ b/external/miniupnpc/testreplyparse/GetExternalIPAddress.namevalue diff --git a/external/miniupnpc/testreplyparse/GetExternalIPAddress.xml b/external/miniupnpc/testreplyparse/GetExternalIPAddress.xml index db7ec1f9c..db7ec1f9c 100755..100644 --- a/external/miniupnpc/testreplyparse/GetExternalIPAddress.xml +++ b/external/miniupnpc/testreplyparse/GetExternalIPAddress.xml diff --git a/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.namevalue b/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.namevalue index 26b169c35..26b169c35 100755..100644 --- a/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.namevalue +++ b/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.namevalue diff --git a/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.xml b/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.xml index bbb540eac..bbb540eac 100755..100644 --- a/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.xml +++ b/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.xml diff --git a/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.namevalue b/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.namevalue index 2189789b4..2189789b4 100755..100644 --- a/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.namevalue +++ b/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.namevalue diff --git a/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.xml b/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.xml index 77e8d9c7c..77e8d9c7c 100755..100644 --- a/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.xml +++ b/external/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.xml diff --git a/external/miniupnpc/testreplyparse/SetDefaultConnectionService.namevalue b/external/miniupnpc/testreplyparse/SetDefaultConnectionService.namevalue index f78c7e2ae..f78c7e2ae 100755..100644 --- a/external/miniupnpc/testreplyparse/SetDefaultConnectionService.namevalue +++ b/external/miniupnpc/testreplyparse/SetDefaultConnectionService.namevalue diff --git a/external/miniupnpc/testreplyparse/SetDefaultConnectionService.xml b/external/miniupnpc/testreplyparse/SetDefaultConnectionService.xml index ac04c07a9..ac04c07a9 100755..100644 --- a/external/miniupnpc/testreplyparse/SetDefaultConnectionService.xml +++ b/external/miniupnpc/testreplyparse/SetDefaultConnectionService.xml diff --git a/external/miniupnpc/testreplyparse/readme.txt b/external/miniupnpc/testreplyparse/readme.txt index 3eb1f015f..3eb1f015f 100755..100644 --- a/external/miniupnpc/testreplyparse/readme.txt +++ b/external/miniupnpc/testreplyparse/readme.txt diff --git a/external/miniupnpc/testupnpreplyparse.c b/external/miniupnpc/testupnpreplyparse.c index 7ba7131ea..7ba7131ea 100755..100644 --- a/external/miniupnpc/testupnpreplyparse.c +++ b/external/miniupnpc/testupnpreplyparse.c diff --git a/external/miniupnpc/upnpc.c b/external/miniupnpc/upnpc.c index 70c9a5473..7c0692050 100755..100644 --- a/external/miniupnpc/upnpc.c +++ b/external/miniupnpc/upnpc.c @@ -1,4 +1,4 @@ -/* $Id: upnpc.c,v 1.102 2014/02/05 17:27:14 nanard Exp $ */ +/* $Id: upnpc.c,v 1.104 2014/09/11 14:13:30 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard * Copyright (c) 2005-2014 Thomas Bernard @@ -223,17 +223,19 @@ static void NewListRedirections(struct UPNPUrls * urls, * 3 - Add port mapping * 4 - get this port mapping from the IGD */ static void SetRedirectAndTest(struct UPNPUrls * urls, - struct IGDdatas * data, - const char * iaddr, - const char * iport, - const char * eport, - const char * proto, - const char * leaseDuration, - const char * description) + struct IGDdatas * data, + const char * iaddr, + const char * iport, + const char * eport, + const char * proto, + const char * leaseDuration, + const char * description, + int addAny) { char externalIPAddress[40]; char intClient[40]; char intPort[6]; + char reservedPort[6]; char duration[16]; int r; @@ -249,31 +251,41 @@ static void SetRedirectAndTest(struct UPNPUrls * urls, return; } - UPNP_GetExternalIPAddress(urls->controlURL, - data->first.servicetype, - externalIPAddress); - if(externalIPAddress[0]) - printf("ExternalIPAddress = %s\n", externalIPAddress); - else + r = UPNP_GetExternalIPAddress(urls->controlURL, + data->first.servicetype, + externalIPAddress); + if(r!=UPNPCOMMAND_SUCCESS) printf("GetExternalIPAddress failed.\n"); + else + printf("ExternalIPAddress = %s\n", externalIPAddress); - r = UPNP_AddPortMapping(urls->controlURL, data->first.servicetype, - eport, iport, iaddr, description, - proto, 0, leaseDuration); - if(r!=UPNPCOMMAND_SUCCESS) - printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", - eport, iport, iaddr, r, strupnperror(r)); + if (addAny) { + r = UPNP_AddAnyPortMapping(urls->controlURL, data->first.servicetype, + eport, iport, iaddr, description, + proto, 0, leaseDuration, reservedPort); + if(r==UPNPCOMMAND_SUCCESS) + eport = reservedPort; + else + printf("AddAnyPortMapping(%s, %s, %s) failed with code %d (%s)\n", + eport, iport, iaddr, r, strupnperror(r)); + } else { + r = UPNP_AddPortMapping(urls->controlURL, data->first.servicetype, + eport, iport, iaddr, description, + proto, 0, leaseDuration); + if(r!=UPNPCOMMAND_SUCCESS) + printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", + eport, iport, iaddr, r, strupnperror(r)); + } r = UPNP_GetSpecificPortMappingEntry(urls->controlURL, - data->first.servicetype, - eport, proto, NULL/*remoteHost*/, - intClient, intPort, NULL/*desc*/, - NULL/*enabled*/, duration); + data->first.servicetype, + eport, proto, NULL/*remoteHost*/, + intClient, intPort, NULL/*desc*/, + NULL/*enabled*/, duration); if(r!=UPNPCOMMAND_SUCCESS) printf("GetSpecificPortMappingEntry() failed with code %d (%s)\n", r, strupnperror(r)); - - if(intClient[0]) { + else { printf("InternalIP:Port = %s:%s\n", intClient, intPort); printf("external %s:%s %s is redirected to internal %s:%s (duration=%s)\n", externalIPAddress, eport, proto, intClient, intPort, duration); @@ -283,8 +295,9 @@ static void SetRedirectAndTest(struct UPNPUrls * urls, static void RemoveRedirect(struct UPNPUrls * urls, struct IGDdatas * data, - const char * eport, - const char * proto) + const char * eport, + const char * proto, + const char * remoteHost) { int r; if(!proto || !eport) @@ -298,10 +311,36 @@ RemoveRedirect(struct UPNPUrls * urls, fprintf(stderr, "protocol invalid\n"); return; } - r = UPNP_DeletePortMapping(urls->controlURL, data->first.servicetype, eport, proto, 0); + r = UPNP_DeletePortMapping(urls->controlURL, data->first.servicetype, eport, proto, remoteHost); printf("UPNP_DeletePortMapping() returned : %d\n", r); } +static void +RemoveRedirectRange(struct UPNPUrls * urls, + struct IGDdatas * data, + const char * ePortStart, char const * ePortEnd, + const char * proto, const char * manage) +{ + int r; + + if (!manage) + manage = "0"; + + if(!proto || !ePortStart || !ePortEnd) + { + fprintf(stderr, "invalid arguments\n"); + return; + } + proto = protofix(proto); + if(!proto) + { + fprintf(stderr, "protocol invalid\n"); + return; + } + r = UPNP_DeletePortMappingRange(urls->controlURL, data->first.servicetype, ePortStart, ePortEnd, proto, manage); + printf("UPNP_DeletePortMappingRange() returned : %d\n", r); +} + /* IGD:2, functions for service WANIPv6FirewallControl:1 */ static void GetFirewallStatus(struct UPNPUrls * urls, struct IGDdatas * data) { @@ -546,10 +585,12 @@ int main(int argc, char ** argv) || (command == 'D' && commandargc<1)) { fprintf(stderr, "Usage :\t%s [options] -a ip port external_port protocol [duration]\n\t\tAdd port redirection\n", argv[0]); - fprintf(stderr, " \t%s [options] -d external_port protocol [port2 protocol2] [...]\n\t\tDelete port redirection\n", argv[0]); + fprintf(stderr, " \t%s [options] -d external_port protocol <remote host>\n\t\tDelete port redirection\n", argv[0]); fprintf(stderr, " \t%s [options] -s\n\t\tGet Connection status\n", argv[0]); fprintf(stderr, " \t%s [options] -l\n\t\tList redirections\n", argv[0]); - fprintf(stderr, " \t%s [options] -L\n\t\tList redirections (using GetListOfPortMappings, IGD v2)\n", argv[0]); + fprintf(stderr, " \t%s [options] -L\n\t\tList redirections (using GetListOfPortMappings (for IGD:2 only)\n", argv[0]); + fprintf(stderr, " \t%s [options] -n ip port external_port protocol [duration]\n\t\tAdd (any) port redirection allowing IGD to use alternative external_port (for IGD:2 only)\n", argv[0]); + fprintf(stderr, " \t%s [options] -N external_port_start external_port_end protocol [manage]\n\t\tDelete range of port redirections (for IGD:2 only)\n", argv[0]); fprintf(stderr, " \t%s [options] -r port1 protocol1 [port2 protocol2] [...]\n\t\tAdd all redirections to the current host\n", argv[0]); fprintf(stderr, " \t%s [options] -A remote_ip remote_port internal_ip internal_port protocol lease_time\n\t\tAdd Pinhole (for IGD:2 only)\n", argv[0]); fprintf(stderr, " \t%s [options] -U uniqueID new_lease_time\n\t\tUpdate Pinhole (for IGD:2 only)\n", argv[0]); @@ -631,16 +672,28 @@ int main(int argc, char ** argv) break; case 'a': SetRedirectAndTest(&urls, &data, - commandargv[0], commandargv[1], - commandargv[2], commandargv[3], - (commandargc > 4)?commandargv[4]:"0", - description); + commandargv[0], commandargv[1], + commandargv[2], commandargv[3], + (commandargc > 4)?commandargv[4]:"0", + description, 0); break; case 'd': - for(i=0; i<commandargc; i+=2) - { - RemoveRedirect(&urls, &data, commandargv[i], commandargv[i+1]); - } + RemoveRedirect(&urls, &data, commandargv[0], commandargv[1], + commandargc > 2 ? commandargv[2] : NULL); + break; + case 'n': /* aNy */ + SetRedirectAndTest(&urls, &data, + commandargv[0], commandargv[1], + commandargv[2], commandargv[3], + (commandargc > 4)?commandargv[4]:"0", + description, 1); + break; + case 'N': + if (commandargc < 3) + fprintf(stderr, "too few arguments\n"); + + RemoveRedirectRange(&urls, &data, commandargv[0], commandargv[1], commandargv[2], + commandargc > 3 ? commandargv[3] : NULL); break; case 's': GetConnectionStatus(&urls, &data); @@ -650,9 +703,9 @@ int main(int argc, char ** argv) { /*printf("port %s protocol %s\n", argv[i], argv[i+1]);*/ SetRedirectAndTest(&urls, &data, - lanaddr, commandargv[i], - commandargv[i], commandargv[i+1], "0", - description); + lanaddr, commandargv[i], + commandargv[i], commandargv[i+1], "0", + description, 0); } break; case 'A': diff --git a/external/miniupnpc/upnpcommands.c b/external/miniupnpc/upnpcommands.c index ad6978105..42dacebb0 100755..100644 --- a/external/miniupnpc/upnpcommands.c +++ b/external/miniupnpc/upnpcommands.c @@ -20,7 +20,7 @@ my_atoui(const char * s) /* * */ -LIBSPEC UNSIGNED_INTEGER +MINIUPNP_LIBSPEC UNSIGNED_INTEGER UPNP_GetTotalBytesSent(const char * controlURL, const char * servicetype) { @@ -44,7 +44,7 @@ UPNP_GetTotalBytesSent(const char * controlURL, /* * */ -LIBSPEC UNSIGNED_INTEGER +MINIUPNP_LIBSPEC UNSIGNED_INTEGER UPNP_GetTotalBytesReceived(const char * controlURL, const char * servicetype) { @@ -68,7 +68,7 @@ UPNP_GetTotalBytesReceived(const char * controlURL, /* * */ -LIBSPEC UNSIGNED_INTEGER +MINIUPNP_LIBSPEC UNSIGNED_INTEGER UPNP_GetTotalPacketsSent(const char * controlURL, const char * servicetype) { @@ -92,7 +92,7 @@ UPNP_GetTotalPacketsSent(const char * controlURL, /* * */ -LIBSPEC UNSIGNED_INTEGER +MINIUPNP_LIBSPEC UNSIGNED_INTEGER UPNP_GetTotalPacketsReceived(const char * controlURL, const char * servicetype) { @@ -116,7 +116,7 @@ UPNP_GetTotalPacketsReceived(const char * controlURL, /* UPNP_GetStatusInfo() call the corresponding UPNP method * returns the current status and uptime */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetStatusInfo(const char * controlURL, const char * servicetype, char * status, @@ -181,7 +181,7 @@ UPNP_GetStatusInfo(const char * controlURL, /* UPNP_GetConnectionTypeInfo() call the corresponding UPNP method * returns the connection type */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetConnectionTypeInfo(const char * controlURL, const char * servicetype, char * connectionType) @@ -224,7 +224,7 @@ UPNP_GetConnectionTypeInfo(const char * controlURL, * One of the values can be null * Note : GetLinkLayerMaxBitRates belongs to WANPPPConnection:1 only * We can use the GetCommonLinkProperties from WANCommonInterfaceConfig:1 */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetLinkLayerMaxBitRates(const char * controlURL, const char * servicetype, unsigned int * bitrateDown, @@ -293,7 +293,7 @@ UPNP_GetLinkLayerMaxBitRates(const char * controlURL, * 402 Invalid Args - See UPnP Device Architecture section on Control. * 501 Action Failed - See UPnP Device Architecture section on Control. */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetExternalIPAddress(const char * controlURL, const char * servicetype, char * extIpAdd) @@ -333,15 +333,15 @@ UPNP_GetExternalIPAddress(const char * controlURL, return ret; } -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_AddPortMapping(const char * controlURL, const char * servicetype, - const char * extPort, - const char * inPort, - const char * inClient, - const char * desc, - const char * proto, - const char * remoteHost, - const char * leaseDuration) + const char * extPort, + const char * inPort, + const char * inClient, + const char * desc, + const char * proto, + const char * remoteHost, + const char * leaseDuration) { struct UPNParg * AddPortMappingArgs; char * buffer; @@ -394,7 +394,74 @@ UPNP_AddPortMapping(const char * controlURL, const char * servicetype, return ret; } -LIBSPEC int +MINIUPNP_LIBSPEC int +UPNP_AddAnyPortMapping(const char * controlURL, const char * servicetype, + const char * extPort, + const char * inPort, + const char * inClient, + const char * desc, + const char * proto, + const char * remoteHost, + const char * leaseDuration, + char * reservedPort) +{ + struct UPNParg * AddPortMappingArgs; + char * buffer; + int bufsize; + struct NameValueParserData pdata; + const char * resVal; + int ret; + + if(!inPort || !inClient || !proto || !extPort) + return UPNPCOMMAND_INVALID_ARGS; + + AddPortMappingArgs = calloc(9, sizeof(struct UPNParg)); + AddPortMappingArgs[0].elt = "NewRemoteHost"; + AddPortMappingArgs[0].val = remoteHost; + AddPortMappingArgs[1].elt = "NewExternalPort"; + AddPortMappingArgs[1].val = extPort; + AddPortMappingArgs[2].elt = "NewProtocol"; + AddPortMappingArgs[2].val = proto; + AddPortMappingArgs[3].elt = "NewInternalPort"; + AddPortMappingArgs[3].val = inPort; + AddPortMappingArgs[4].elt = "NewInternalClient"; + AddPortMappingArgs[4].val = inClient; + AddPortMappingArgs[5].elt = "NewEnabled"; + AddPortMappingArgs[5].val = "1"; + AddPortMappingArgs[6].elt = "NewPortMappingDescription"; + AddPortMappingArgs[6].val = desc?desc:"libminiupnpc"; + AddPortMappingArgs[7].elt = "NewLeaseDuration"; + AddPortMappingArgs[7].val = leaseDuration?leaseDuration:"0"; + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "AddAnyPortMapping", AddPortMappingArgs, + &bufsize))) { + free(AddPortMappingArgs); + return UPNPCOMMAND_HTTP_ERROR; + } + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + resVal = GetValueFromNameValueList(&pdata, "errorCode"); + if(resVal) { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(resVal, "%d", &ret); + } else { + char *p; + + p = GetValueFromNameValueList(&pdata, "NewReservedPort"); + if(p) { + strncpy(reservedPort, p, 6); + reservedPort[5] = '\0'; + ret = UPNPCOMMAND_SUCCESS; + } else { + ret = UPNPCOMMAND_INVALID_RESPONSE; + } + } + ClearNameValueList(&pdata); + free(AddPortMappingArgs); + return ret; +} + +MINIUPNP_LIBSPEC int UPNP_DeletePortMapping(const char * controlURL, const char * servicetype, const char * extPort, const char * proto, const char * remoteHost) @@ -438,7 +505,53 @@ UPNP_DeletePortMapping(const char * controlURL, const char * servicetype, return ret; } -LIBSPEC int +MINIUPNP_LIBSPEC int +UPNP_DeletePortMappingRange(const char * controlURL, const char * servicetype, + const char * extPortStart, const char * extPortEnd, + const char * proto, + const char * manage) +{ + struct UPNParg * DeletePortMappingArgs; + char * buffer; + int bufsize; + struct NameValueParserData pdata; + const char * resVal; + int ret; + + if(!extPortStart || !extPortEnd || !proto || !manage) + return UPNPCOMMAND_INVALID_ARGS; + + DeletePortMappingArgs = calloc(5, sizeof(struct UPNParg)); + DeletePortMappingArgs[0].elt = "NewStartPort"; + DeletePortMappingArgs[0].val = extPortStart; + DeletePortMappingArgs[1].elt = "NewEndPort"; + DeletePortMappingArgs[1].val = extPortEnd; + DeletePortMappingArgs[2].elt = "NewProtocol"; + DeletePortMappingArgs[2].val = proto; + DeletePortMappingArgs[3].elt = "NewManage"; + DeletePortMappingArgs[3].val = manage; + + if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "DeletePortMappingRange", + DeletePortMappingArgs, &bufsize))) { + free(DeletePortMappingArgs); + return UPNPCOMMAND_HTTP_ERROR; + } + ParseNameValue(buffer, bufsize, &pdata); + free(buffer); buffer = NULL; + resVal = GetValueFromNameValueList(&pdata, "errorCode"); + if(resVal) { + ret = UPNPCOMMAND_UNKNOWN_ERROR; + sscanf(resVal, "%d", &ret); + } else { + ret = UPNPCOMMAND_SUCCESS; + } + ClearNameValueList(&pdata); + free(DeletePortMappingArgs); + return ret; +} + +MINIUPNP_LIBSPEC int UPNP_GetGenericPortMappingEntry(const char * controlURL, const char * servicetype, const char * index, @@ -533,7 +646,7 @@ UPNP_GetGenericPortMappingEntry(const char * controlURL, return r; } -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetPortMappingNumberOfEntries(const char * controlURL, const char * servicetype, unsigned int * numEntries) @@ -574,7 +687,7 @@ UPNP_GetPortMappingNumberOfEntries(const char * controlURL, /* UPNP_GetSpecificPortMappingEntry retrieves an existing port mapping * the result is returned in the intClient and intPort strings * please provide 16 and 6 bytes of data */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetSpecificPortMappingEntry(const char * controlURL, const char * servicetype, const char * extPort, @@ -666,7 +779,7 @@ UPNP_GetSpecificPortMappingEntry(const char * controlURL, * 733 InconsistantParameters - NewStartPort and NewEndPort values are not * consistent. */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetListOfPortMappings(const char * controlURL, const char * servicetype, const char * startPort, @@ -748,7 +861,7 @@ UPNP_GetListOfPortMappings(const char * controlURL, } /* IGD:2, functions for service WANIPv6FirewallControl:1 */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetFirewallStatus(const char * controlURL, const char * servicetype, int * firewallEnabled, @@ -792,7 +905,7 @@ UPNP_GetFirewallStatus(const char * controlURL, return ret; } -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype, const char * remoteHost, const char * remotePort, @@ -847,7 +960,7 @@ UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype return ret; } -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_AddPinhole(const char * controlURL, const char * servicetype, const char * remoteHost, const char * remotePort, @@ -926,7 +1039,7 @@ UPNP_AddPinhole(const char * controlURL, const char * servicetype, return ret; } -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_UpdatePinhole(const char * controlURL, const char * servicetype, const char * uniqueID, const char * leaseTime) @@ -968,7 +1081,7 @@ UPNP_UpdatePinhole(const char * controlURL, const char * servicetype, return ret; } -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_DeletePinhole(const char * controlURL, const char * servicetype, const char * uniqueID) { /*struct NameValueParserData pdata;*/ @@ -1007,7 +1120,7 @@ UPNP_DeletePinhole(const char * controlURL, const char * servicetype, const char return ret; } -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_CheckPinholeWorking(const char * controlURL, const char * servicetype, const char * uniqueID, int * isWorking) { @@ -1052,7 +1165,7 @@ UPNP_CheckPinholeWorking(const char * controlURL, const char * servicetype, return ret; } -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetPinholePackets(const char * controlURL, const char * servicetype, const char * uniqueID, int * packets) { diff --git a/external/miniupnpc/upnpcommands.h b/external/miniupnpc/upnpcommands.h index 93d9f3dd4..8034199ce 100755..100644 --- a/external/miniupnpc/upnpcommands.h +++ b/external/miniupnpc/upnpcommands.h @@ -17,24 +17,25 @@ #define UPNPCOMMAND_UNKNOWN_ERROR (-1) #define UPNPCOMMAND_INVALID_ARGS (-2) #define UPNPCOMMAND_HTTP_ERROR (-3) +#define UPNPCOMMAND_INVALID_RESPONSE (-4) #ifdef __cplusplus extern "C" { #endif -LIBSPEC UNSIGNED_INTEGER +MINIUPNP_LIBSPEC UNSIGNED_INTEGER UPNP_GetTotalBytesSent(const char * controlURL, const char * servicetype); -LIBSPEC UNSIGNED_INTEGER +MINIUPNP_LIBSPEC UNSIGNED_INTEGER UPNP_GetTotalBytesReceived(const char * controlURL, const char * servicetype); -LIBSPEC UNSIGNED_INTEGER +MINIUPNP_LIBSPEC UNSIGNED_INTEGER UPNP_GetTotalPacketsSent(const char * controlURL, const char * servicetype); -LIBSPEC UNSIGNED_INTEGER +MINIUPNP_LIBSPEC UNSIGNED_INTEGER UPNP_GetTotalPacketsReceived(const char * controlURL, const char * servicetype); @@ -43,7 +44,7 @@ UPNP_GetTotalPacketsReceived(const char * controlURL, * Return values : * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR * or a UPnP Error code */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetStatusInfo(const char * controlURL, const char * servicetype, char * status, @@ -55,7 +56,7 @@ UPNP_GetStatusInfo(const char * controlURL, * Return Values : * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR * or a UPnP Error code */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetConnectionTypeInfo(const char * controlURL, const char * servicetype, char * connectionType); @@ -71,7 +72,7 @@ UPNP_GetConnectionTypeInfo(const char * controlURL, * possible UPnP Errors : * 402 Invalid Args - See UPnP Device Architecture section on Control. * 501 Action Failed - See UPnP Device Architecture section on Control. */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetExternalIPAddress(const char * controlURL, const char * servicetype, char * extIpAdd); @@ -82,7 +83,7 @@ UPNP_GetExternalIPAddress(const char * controlURL, * return values : * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR * or a UPnP Error Code. */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetLinkLayerMaxBitRates(const char* controlURL, const char* servicetype, unsigned int * bitrateDown, @@ -121,15 +122,49 @@ UPNP_GetLinkLayerMaxBitRates(const char* controlURL, * due to conflict with other mechanisms. * 732 WildCardNotPermittedInIntPort - The internal port cannot be wild-carded */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_AddPortMapping(const char * controlURL, const char * servicetype, - const char * extPort, - const char * inPort, - const char * inClient, - const char * desc, - const char * proto, - const char * remoteHost, - const char * leaseDuration); + const char * extPort, + const char * inPort, + const char * inClient, + const char * desc, + const char * proto, + const char * remoteHost, + const char * leaseDuration); + +/* UPNP_AddAnyPortMapping() + * if desc is NULL, it will be defaulted to "libminiupnpc" + * remoteHost is usually NULL because IGD don't support it. + * + * Return values : + * 0 : SUCCESS + * NON ZERO : ERROR. Either an UPnP error code or an unknown error. + * + * List of possible UPnP errors for AddPortMapping : + * errorCode errorDescription (short) - Description (long) + * 402 Invalid Args - See UPnP Device Architecture section on Control. + * 501 Action Failed - See UPnP Device Architecture section on Control. + * 606 Action not authorized - The action requested REQUIRES authorization and + * the sender was not authorized. + * 715 WildCardNotPermittedInSrcIP - The source IP address cannot be + * wild-carded + * 716 WildCardNotPermittedInExtPort - The external port cannot be wild-carded + * 728 NoPortMapsAvailable - There are not enough free ports available to + * complete port mapping. + * 729 ConflictWithOtherMechanisms - Attempted port mapping is not allowed + * due to conflict with other mechanisms. + * 732 WildCardNotPermittedInIntPort - The internal port cannot be wild-carded + */ +MINIUPNP_LIBSPEC int +UPNP_AddAnyPortMapping(const char * controlURL, const char * servicetype, + const char * extPort, + const char * inPort, + const char * inClient, + const char * desc, + const char * proto, + const char * remoteHost, + const char * leaseDuration, + char * reservedPort); /* UPNP_DeletePortMapping() * Use same argument values as what was used for AddPortMapping(). @@ -143,14 +178,33 @@ UPNP_AddPortMapping(const char * controlURL, const char * servicetype, * 606 Action not authorized - The action requested REQUIRES authorization * and the sender was not authorized. * 714 NoSuchEntryInArray - The specified value does not exist in the array */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_DeletePortMapping(const char * controlURL, const char * servicetype, - const char * extPort, const char * proto, - const char * remoteHost); + const char * extPort, const char * proto, + const char * remoteHost); + +/* UPNP_DeletePortRangeMapping() + * Use same argument values as what was used for AddPortMapping(). + * remoteHost is usually NULL because IGD don't support it. + * Return Values : + * 0 : SUCCESS + * NON ZERO : error. Either an UPnP error code or an undefined error. + * + * List of possible UPnP errors for DeletePortMapping : + * 606 Action not authorized - The action requested REQUIRES authorization + * and the sender was not authorized. + * 730 PortMappingNotFound - This error message is returned if no port + * mapping is found in the specified range. + * 733 InconsistentParameters - NewStartPort and NewEndPort values are not consistent. */ +MINIUPNP_LIBSPEC int +UPNP_DeletePortMappingRange(const char * controlURL, const char * servicetype, + const char * extPortStart, const char * extPortEnd, + const char * proto, + const char * manage); /* UPNP_GetPortMappingNumberOfEntries() * not supported by all routers */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetPortMappingNumberOfEntries(const char* controlURL, const char* servicetype, unsigned int * num); @@ -178,7 +232,7 @@ UPNP_GetPortMappingNumberOfEntries(const char* controlURL, * and the sender was not authorized. * 714 NoSuchEntryInArray - The specified value does not exist in the array. */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetSpecificPortMappingEntry(const char * controlURL, const char * servicetype, const char * extPort, @@ -212,7 +266,7 @@ UPNP_GetSpecificPortMappingEntry(const char * controlURL, * and the sender was not authorized. * 713 SpecifiedArrayIndexInvalid - The specified array index is out of bounds */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetGenericPortMappingEntry(const char * controlURL, const char * servicetype, const char * index, @@ -234,7 +288,7 @@ UPNP_GetGenericPortMappingEntry(const char * controlURL, * 733 InconsistantParameters - NewStartPort and NewEndPort values are not * consistent. */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetListOfPortMappings(const char * controlURL, const char * servicetype, const char * startPort, @@ -244,13 +298,13 @@ UPNP_GetListOfPortMappings(const char * controlURL, struct PortMappingParserData * data); /* IGD:2, functions for service WANIPv6FirewallControl:1 */ -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetFirewallStatus(const char * controlURL, const char * servicetype, int * firewallEnabled, int * inboundPinholeAllowed); -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype, const char * remoteHost, const char * remotePort, @@ -259,7 +313,7 @@ UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype const char * proto, int * opTimeout); -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_AddPinhole(const char * controlURL, const char * servicetype, const char * remoteHost, const char * remotePort, @@ -269,19 +323,19 @@ UPNP_AddPinhole(const char * controlURL, const char * servicetype, const char * leaseTime, char * uniqueID); -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_UpdatePinhole(const char * controlURL, const char * servicetype, const char * uniqueID, const char * leaseTime); -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_DeletePinhole(const char * controlURL, const char * servicetype, const char * uniqueID); -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_CheckPinholeWorking(const char * controlURL, const char * servicetype, const char * uniqueID, int * isWorking); -LIBSPEC int +MINIUPNP_LIBSPEC int UPNP_GetPinholePackets(const char * controlURL, const char * servicetype, const char * uniqueID, int * packets); diff --git a/external/miniupnpc/upnperrors.c b/external/miniupnpc/upnperrors.c index 644098f0d..40a2e7857 100755..100644 --- a/external/miniupnpc/upnperrors.c +++ b/external/miniupnpc/upnperrors.c @@ -1,4 +1,4 @@ -/* $Id: upnperrors.c,v 1.6 2012/03/15 01:02:03 nanard Exp $ */ +/* $Id: upnperrors.c,v 1.5 2011/04/10 11:19:36 nanard Exp $ */ /* Project : miniupnp * Author : Thomas BERNARD * copyright (c) 2007 Thomas Bernard @@ -24,6 +24,9 @@ const char * strupnperror(int err) case UPNPCOMMAND_INVALID_ARGS: s = "Miniupnpc Invalid Arguments"; break; + case UPNPCOMMAND_INVALID_RESPONSE: + s = "Miniupnpc Invalid response"; + break; case UPNPDISCOVER_SOCKET_ERROR: s = "Miniupnpc Socket error"; break; diff --git a/external/miniupnpc/upnperrors.h b/external/miniupnpc/upnperrors.h index 077d6938b..b42c6424a 100755..100644 --- a/external/miniupnpc/upnperrors.h +++ b/external/miniupnpc/upnperrors.h @@ -1,4 +1,4 @@ -/* $Id: upnperrors.h,v 1.4 2012/09/27 15:42:11 nanard Exp $ */ +/* $Id: upnperrors.h,v 1.2 2008/07/02 23:31:15 nanard Exp $ */ /* (c) 2007 Thomas Bernard * All rights reserved. * MiniUPnP Project. @@ -17,7 +17,7 @@ extern "C" { /* strupnperror() * Return a string description of the UPnP error code * or NULL for undefinded errors */ -LIBSPEC const char * strupnperror(int err); +MINIUPNP_LIBSPEC const char * strupnperror(int err); #ifdef __cplusplus } diff --git a/external/miniupnpc/upnpreplyparse.c b/external/miniupnpc/upnpreplyparse.c index dafa26313..dafa26313 100755..100644 --- a/external/miniupnpc/upnpreplyparse.c +++ b/external/miniupnpc/upnpreplyparse.c diff --git a/external/miniupnpc/upnpreplyparse.h b/external/miniupnpc/upnpreplyparse.h index d4e37576a..d4e37576a 100755..100644 --- a/external/miniupnpc/upnpreplyparse.h +++ b/external/miniupnpc/upnpreplyparse.h diff --git a/external/miniupnpc/wingenminiupnpcstrings.c b/external/miniupnpc/wingenminiupnpcstrings.c index ed289f4a2..fd9ee061d 100755..100644 --- a/external/miniupnpc/wingenminiupnpcstrings.c +++ b/external/miniupnpc/wingenminiupnpcstrings.c @@ -1,4 +1,4 @@ -/* $Id: wingenminiupnpcstrings.c,v 1.3 2012/03/05 19:42:48 nanard Exp $ */ +/* $Id: wingenminiupnpcstrings.c,v 1.2 2011/01/11 15:31:13 nanard Exp $ */ /* Project: miniupnp * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * Author: Thomas Bernard diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 2953bdb7a..01fbaa497 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -48,9 +48,11 @@ #ifdef UPNP_STATIC #include <miniupnpc/miniupnpc.h> #include <miniupnpc/upnpcommands.h> + #include <miniupnpc/upnperrors.h> #else #include "miniupnpc.h" #include "upnpcommands.h" + #include "upnperrors.h" #endif #define NET_MAKE_IP(b1,b2,b3,b4) ((LPARAM)(((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4)))) @@ -326,8 +328,14 @@ namespace nodetool if (result == 1) { std::ostringstream portString; portString << m_listenning_port; - if (UPNP_AddPortMapping(urls.controlURL, igdData.first.servicetype, portString.str().c_str(), portString.str().c_str(), lanAddress, CRYPTONOTE_NAME, "TCP", 0, "0") != 0) { - LOG_ERROR("UPNP_AddPortMapping failed."); + + // Delete the port mapping before we create it, just in case we have dangling port mapping from the daemon not being shut down correctly + UPNP_DeletePortMapping(urls.controlURL, igdData.first.servicetype, portString.str().c_str(), "TCP", 0); + + int portMappingResult; + portMappingResult = UPNP_AddPortMapping(urls.controlURL, igdData.first.servicetype, portString.str().c_str(), portString.str().c_str(), lanAddress, CRYPTONOTE_NAME, "TCP", 0, "0"); + if (portMappingResult != 0) { + LOG_ERROR("UPNP_AddPortMapping failed, error: " << strupnperror(portMappingResult)); } else { LOG_PRINT_GREEN("Added IGD port mapping.", LOG_LEVEL_0); } |