From a4242c42b24d936c1ca79f98aa1062177c222c04 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 21 Mar 2016 13:37:54 +0200 Subject: [PATCH 1/3] update miniupnpc --- external/miniupnpc/Changelog.txt | 10 ++- external/miniupnpc/Makefile | 4 +- external/miniupnpc/Makefile.mingw | 6 +- external/miniupnpc/apiversions.txt | 7 +- external/miniupnpc/minissdpc.c | 25 ++++++- external/miniupnpc/miniupnpc.c | 73 ++++++++++++++----- external/miniupnpc/miniupnpc.h | 6 +- external/miniupnpc/miniwget.c | 65 ++++++++++++----- external/miniupnpc/miniwget.h | 10 +-- .../miniupnpc/testdesc/new_LiveBox_desc.xml | 2 +- external/miniupnpc/testminiwget.c | 12 +-- external/miniupnpc/upnpc.c | 18 +++-- external/miniupnpc/upnpcommands.c | 4 +- 13 files changed, 174 insertions(+), 68 deletions(-) diff --git a/external/miniupnpc/Changelog.txt b/external/miniupnpc/Changelog.txt index bef61f59e..bf6343bd2 100644 --- a/external/miniupnpc/Changelog.txt +++ b/external/miniupnpc/Changelog.txt @@ -1,6 +1,14 @@ -$Id: Changelog.txt,v 1.219 2015/10/26 17:05:06 nanard Exp $ +$Id: Changelog.txt,v 1.222 2016/01/24 17:24:35 nanard Exp $ miniUPnP client Changelog. +2016/01/24: + change miniwget to return HTTP status code + increments API_VERSION to 16 + +2016/01/22: + Improve UPNPIGD_IsConnected() to check if WAN address is not private. + parse HTTP response status line in miniwget.c + 2015/10/26: snprintf() overflow check. check overflow in simpleUPnPcommand2() diff --git a/external/miniupnpc/Makefile b/external/miniupnpc/Makefile index 21845f8ae..99a69301c 100644 --- a/external/miniupnpc/Makefile +++ b/external/miniupnpc/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.126 2015/08/28 12:14:18 nanard Exp $ +# $Id: Makefile,v 1.133 2016/01/24 17:24:35 nanard Exp $ # MiniUPnP Project # http://miniupnp.free.fr/ # http://miniupnp.tuxfamily.org/ @@ -66,7 +66,7 @@ ifeq (SunOS, $(OS)) endif # APIVERSION is used to build SONAME -APIVERSION = 15 +APIVERSION = 16 SRCS = igd_desc_parse.c miniupnpc.c minixml.c minisoap.c miniwget.c \ upnpc.c upnpcommands.c upnpreplyparse.c testminixml.c \ diff --git a/external/miniupnpc/Makefile.mingw b/external/miniupnpc/Makefile.mingw index 54c62de1b..1b0d44aab 100644 --- a/external/miniupnpc/Makefile.mingw +++ b/external/miniupnpc/Makefile.mingw @@ -18,7 +18,8 @@ OBJS=miniwget.o minixml.o igd_desc_parse.o minisoap.o \ upnpdev.o OBJSDLL=$(addprefix dll/, $(OBJS)) -all: init upnpc-static upnpc-shared testminixml libminiupnpc.a miniupnpc.dll +all: init upnpc-static upnpc-shared testminixml libminiupnpc.a \ + miniupnpc.dll listdevices init: mkdir dll @@ -66,6 +67,9 @@ upnpc-static: upnpc.o libminiupnpc.a upnpc-shared: dll/upnpc.o miniupnpc.lib $(CC) -o $@ $^ $(LDLIBS) +listdevices: listdevices.o libminiupnpc.a + $(CC) -o $@ $^ $(LDLIBS) + wingenminiupnpcstrings: wingenminiupnpcstrings.o wingenminiupnpcstrings.o: wingenminiupnpcstrings.c diff --git a/external/miniupnpc/apiversions.txt b/external/miniupnpc/apiversions.txt index daac18faa..9464a8675 100644 --- a/external/miniupnpc/apiversions.txt +++ b/external/miniupnpc/apiversions.txt @@ -1,7 +1,12 @@ -$Id: apiversions.txt,v 1.7 2015/07/23 20:40:08 nanard Exp $ +$Id: apiversions.txt,v 1.9 2016/01/24 17:24:36 nanard Exp $ Differences in API between miniUPnPc versions +API version 16 + added "status_code" argument to getHTTPResponse(), miniwget() and miniwget_getaddr() + updated macro : + #define MINIUPNPC_API_VERSION 16 + API version 15 changed "sameport" argument of upnpDiscover() upnpDiscoverAll() upnpDiscoverDevice() to "localport". When 0 or 1, behaviour is not changed, but it can take diff --git a/external/miniupnpc/minissdpc.c b/external/miniupnpc/minissdpc.c index 7b1c317b2..a6380dfd4 100644 --- a/external/miniupnpc/minissdpc.c +++ b/external/miniupnpc/minissdpc.c @@ -1,5 +1,6 @@ /* $Id: minissdpc.c,v 1.28 2015/09/18 13:05:39 nanard Exp $ */ -/* Project : miniupnp +/* vim: tabstop=4 shiftwidth=4 noexpandtab + * Project : miniupnp * Web : http://miniupnp.free.fr/ * Author : Thomas BERNARD * copyright (c) 2005-2015 Thomas Bernard @@ -67,6 +68,10 @@ struct sockaddr_un { #define HAS_IP_MREQN #endif +#if !defined(HAS_IP_MREQN) && !defined(_WIN32) +#include +#endif + #if defined(HAS_IP_MREQN) && defined(NEED_STRUCT_IP_MREQN) /* Several versions of glibc don't define this structure, * define it here and compile with CFLAGS NEED_STRUCT_IP_MREQN */ @@ -647,11 +652,25 @@ ssdpDiscoverDevices(const char * const deviceTypes[], { PRINT_SOCKET_ERROR("setsockopt"); } -#else +#elif !defined(_WIN32) + struct ifreq ifr; + int ifrlen = sizeof(ifr); + strncpy(ifr.ifr_name, multicastif, IFNAMSIZ); + ifr.ifr_name[IFNAMSIZ-1] = '\0'; + if(ioctl(sudp, SIOCGIFADDR, &ifr, &ifrlen) < 0) + { + PRINT_SOCKET_ERROR("ioctl(...SIOCGIFADDR...)"); + } + mc_if.s_addr = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; + if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF, (const char *)&mc_if, sizeof(mc_if)) < 0) + { + PRINT_SOCKET_ERROR("setsockopt"); + } +#else /* _WIN32 */ #ifdef DEBUG printf("Setting of multicast interface not supported with interface name.\n"); #endif -#endif +#endif /* #ifdef HAS_IP_MREQN / !defined(_WIN32) */ } } } diff --git a/external/miniupnpc/miniupnpc.c b/external/miniupnpc/miniupnpc.c index fc665a0a4..5eb9500e3 100644 --- a/external/miniupnpc/miniupnpc.c +++ b/external/miniupnpc/miniupnpc.c @@ -1,9 +1,9 @@ -/* $Id: miniupnpc.c,v 1.135 2015/07/23 20:40:08 nanard Exp $ */ -/* vim: tabstop=4 shiftwidth=4 noexpandtab */ -/* Project : miniupnp +/* $Id: miniupnpc.c,v 1.148 2016/01/24 17:24:36 nanard Exp $ */ +/* vim: tabstop=4 shiftwidth=4 noexpandtab + * Project : miniupnp * Web : http://miniupnp.free.fr/ * Author : Thomas BERNARD - * copyright (c) 2005-2015 Thomas Bernard + * copyright (c) 2005-2016 Thomas Bernard * This software is subjet to the conditions detailed in the * provided LICENSE file. */ #include @@ -72,6 +72,25 @@ #define SERVICEPREFIX "u" #define SERVICEPREFIX2 'u' +/* check if an ip address is a private (LAN) address + * see https://tools.ietf.org/html/rfc1918 */ +static int is_rfc1918addr(const char * addr) +{ + /* 192.168.0.0 - 192.168.255.255 (192.168/16 prefix) */ + if(COMPARE(addr, "192.168.")) + return 1; + /* 10.0.0.0 - 10.255.255.255 (10/8 prefix) */ + if(COMPARE(addr, "10.")) + return 1; + /* 172.16.0.0 - 172.31.255.255 (172.16/12 prefix) */ + if(COMPARE(addr, "172.")) { + int i = atoi(addr + 4); + if((16 <= i) && (i <= 31)) + return 1; + } + return 0; +} + /* root description parsing */ MINIUPNP_LIBSPEC void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data) { @@ -107,6 +126,7 @@ char * simpleUPnPcommand2(int s, const char * url, const char * service, int soapbodylen; char * buf; int n; + int status_code; *bufsize = 0; snprintf(soapact, sizeof(soapact), "%s#%s", service, action); @@ -210,11 +230,15 @@ char * simpleUPnPcommand2(int s, const char * url, const char * service, return NULL; } - buf = getHTTPResponse(s, bufsize); + buf = getHTTPResponse(s, bufsize, &status_code); #ifdef DEBUG if(*bufsize > 0 && buf) { - printf("SOAP Response :\n%.*s\n", *bufsize, buf); + printf("HTTP %d SOAP Response :\n%.*s\n", status_code, *bufsize, buf); + } + else + { + printf("HTTP %d, empty SOAP response. size=%d\n", status_code, *bufsize); } #endif closesocket(s); @@ -526,7 +550,7 @@ UPNPIGD_IsConnected(struct UPNPUrls * urls, struct IGDdatas * data) * 3 = an UPnP device has been found but was not recognized as an IGD * * In any positive non zero return case, the urls and data structures - * passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to + * passed as parameters are set. Dont forget to call FreeUPNPUrls(urls) to * free allocated memory. */ MINIUPNP_LIBSPEC int @@ -547,6 +571,8 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, int n_igd = 0; char extIpAddr[16]; char myLanAddr[40]; + int status_code = -1; + if(!devlist) { #ifdef DEBUG @@ -570,7 +596,7 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, * with st == urn:schemas-upnp-org:device:InternetGatewayDevice:1 */ desc[i].xml = miniwget_getaddr(dev->descURL, &(desc[i].size), myLanAddr, sizeof(myLanAddr), - dev->scope_id); + dev->scope_id, &status_code); #ifdef DEBUG if(!desc[i].xml) { @@ -604,20 +630,25 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, parserootdesc(desc[i].xml, desc[i].size, data); if(desc[i].is_igd || state >= 3 ) { + int is_connected; + GetUPNPUrls(urls, data, dev->descURL, dev->scope_id); /* in state 2 and 3 we dont test if device is connected ! */ if(state >= 2) goto free_and_return; + is_connected = UPNPIGD_IsConnected(urls, data); #ifdef DEBUG printf("UPNPIGD_IsConnected(%s) = %d\n", - urls->controlURL, - UPNPIGD_IsConnected(urls, data)); + urls->controlURL, is_connected); #endif /* checks that status is connected AND there is a external IP address assigned */ - if(UPNPIGD_IsConnected(urls, data) - && (UPNP_GetExternalIPAddress(urls->controlURL, data->first.servicetype, extIpAddr) == 0)) - goto free_and_return; + if(is_connected && + (UPNP_GetExternalIPAddress(urls->controlURL, data->first.servicetype, extIpAddr) == 0)) { + if(!is_rfc1918addr(extIpAddr) && (extIpAddr[0] != '\0') + && (0 != strcmp(extIpAddr, "0.0.0.0"))) + goto free_and_return; + } FreeUPNPUrls(urls); if(data->second.servicetype[0] != '\0') { #ifdef DEBUG @@ -629,14 +660,17 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, memcpy(&data->first, &data->second, sizeof(struct IGDdatas_service)); memcpy(&data->second, &data->tmp, sizeof(struct IGDdatas_service)); GetUPNPUrls(urls, data, dev->descURL, dev->scope_id); + is_connected = UPNPIGD_IsConnected(urls, data); #ifdef DEBUG printf("UPNPIGD_IsConnected(%s) = %d\n", - urls->controlURL, - UPNPIGD_IsConnected(urls, data)); + urls->controlURL, is_connected); #endif - if(UPNPIGD_IsConnected(urls, data) - && (UPNP_GetExternalIPAddress(urls->controlURL, data->first.servicetype, extIpAddr) == 0)) - goto free_and_return; + if(is_connected && + (UPNP_GetExternalIPAddress(urls->controlURL, data->first.servicetype, extIpAddr) == 0)) { + if(!is_rfc1918addr(extIpAddr) && (extIpAddr[0] != '\0') + && (0 != strcmp(extIpAddr, "0.0.0.0"))) + goto free_and_return; + } FreeUPNPUrls(urls); } } @@ -670,8 +704,9 @@ UPNP_GetIGDFromUrl(const char * rootdescurl, { char * descXML; int descXMLsize = 0; + descXML = miniwget_getaddr(rootdescurl, &descXMLsize, - lanaddr, lanaddrlen, 0); + lanaddr, lanaddrlen, 0, NULL); if(descXML) { memset(data, 0, sizeof(struct IGDdatas)); memset(urls, 0, sizeof(struct UPNPUrls)); diff --git a/external/miniupnpc/miniupnpc.h b/external/miniupnpc/miniupnpc.h index a694978c6..5e8248850 100644 --- a/external/miniupnpc/miniupnpc.h +++ b/external/miniupnpc/miniupnpc.h @@ -1,8 +1,8 @@ -/* $Id: miniupnpc.h,v 1.44 2015/07/23 20:40:10 nanard Exp $ */ +/* $Id: miniupnpc.h,v 1.49 2016/01/24 17:24:36 nanard Exp $ */ /* Project: miniupnp * http://miniupnp.free.fr/ * Author: Thomas Bernard - * Copyright (c) 2005-2015 Thomas Bernard + * Copyright (c) 2005-2016 Thomas Bernard * This software is subjects to the conditions detailed * in the LICENCE file provided within this distribution */ #ifndef MINIUPNPC_H_INCLUDED @@ -20,7 +20,7 @@ /* versions : */ #define MINIUPNPC_VERSION "1.9" -#define MINIUPNPC_API_VERSION 15 +#define MINIUPNPC_API_VERSION 16 /* Source port: Using "1" as an alias for 1900 for backwards compatability diff --git a/external/miniupnpc/miniwget.c b/external/miniupnpc/miniwget.c index bc6e19bea..ca88a1e9d 100644 --- a/external/miniupnpc/miniwget.c +++ b/external/miniupnpc/miniwget.c @@ -1,8 +1,8 @@ -/* $Id: miniwget.c,v 1.70 2015/07/15 12:41:13 nanard Exp $ */ +/* $Id: miniwget.c,v 1.75 2016/01/24 17:24:36 nanard Exp $ */ /* Project : miniupnp * Website : http://miniupnp.free.fr/ * Author : Thomas Bernard - * Copyright (c) 2005-2015 Thomas Bernard + * Copyright (c) 2005-2016 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. */ @@ -65,7 +65,7 @@ * to the length parameter. */ void * -getHTTPResponse(int s, int * size) +getHTTPResponse(int s, int * size, int * status_code) { char buf[2048]; int n; @@ -83,7 +83,10 @@ getHTTPResponse(int s, int * size) unsigned int content_buf_used = 0; char chunksize_buf[32]; unsigned int chunksize_buf_index; + char * reason_phrase = NULL; + int reason_phrase_len = 0; + if(status_code) *status_code = -1; header_buf = malloc(header_buf_len); if(header_buf == NULL) { @@ -155,7 +158,7 @@ getHTTPResponse(int s, int * size) continue; /* parse header lines */ for(i = 0; i < endofheaders - 1; i++) { - if(colon <= linestart && header_buf[i]==':') + if(linestart > 0 && colon <= linestart && header_buf[i]==':') { colon = i; while(i < (endofheaders-1) @@ -166,7 +169,29 @@ getHTTPResponse(int s, int * size) /* detecting end of line */ else if(header_buf[i]=='\r' || header_buf[i]=='\n') { - if(colon > linestart && valuestart > colon) + if(linestart == 0 && status_code) + { + /* Status line + * HTTP-Version SP Status-Code SP Reason-Phrase CRLF */ + int sp; + for(sp = 0; sp < i; sp++) + if(header_buf[sp] == ' ') + { + if(*status_code < 0) + *status_code = atoi(header_buf + sp + 1); + else + { + reason_phrase = header_buf + sp + 1; + reason_phrase_len = i - sp - 1; + break; + } + } +#ifdef DEBUG + printf("HTTP status code = %d, Reason phrase = %.*s\n", + *status_code, reason_phrase_len, reason_phrase); +#endif + } + else if(colon > linestart && valuestart > colon) { #ifdef DEBUG printf("header='%.*s', value='%.*s'\n", @@ -337,7 +362,8 @@ static void * miniwget3(const char * host, unsigned short port, const char * path, int * size, char * addr_str, int addr_str_len, - const char * httpversion, unsigned int scope_id) + const char * httpversion, unsigned int scope_id, + int * status_code) { char buf[2048]; int s; @@ -435,7 +461,7 @@ miniwget3(const char * host, sent += n; } } - content = getHTTPResponse(s, size); + content = getHTTPResponse(s, size, status_code); closesocket(s); return content; } @@ -444,18 +470,20 @@ miniwget3(const char * host, * Call miniwget3(); retry with HTTP/1.1 if 1.0 fails. */ static void * miniwget2(const char * host, - unsigned short port, const char * path, - int * size, char * addr_str, int addr_str_len, - unsigned int scope_id) + unsigned short port, const char * path, + int * size, char * addr_str, int addr_str_len, + unsigned int scope_id, int * status_code) { char * respbuffer; #if 1 respbuffer = miniwget3(host, port, path, size, - addr_str, addr_str_len, "1.1", scope_id); + addr_str, addr_str_len, "1.1", + scope_id, status_code); #else respbuffer = miniwget3(host, port, path, size, - addr_str, addr_str_len, "1.0", scope_id); + addr_str, addr_str_len, "1.0", + scope_id, status_code); if (*size == 0) { #ifdef DEBUG @@ -463,7 +491,8 @@ miniwget2(const char * host, #endif free(respbuffer); respbuffer = miniwget3(host, port, path, size, - addr_str, addr_str_len, "1.1", scope_id); + addr_str, addr_str_len, "1.1", + scope_id, status_code); } #endif return respbuffer; @@ -588,7 +617,8 @@ parseURL(const char * url, } void * -miniwget(const char * url, int * size, unsigned int scope_id) +miniwget(const char * url, int * size, + unsigned int scope_id, int * status_code) { unsigned short port; char * path; @@ -601,12 +631,13 @@ miniwget(const char * url, int * size, unsigned int scope_id) printf("parsed url : hostname='%s' port=%hu path='%s' scope_id=%u\n", hostname, port, path, scope_id); #endif - return miniwget2(hostname, port, path, size, 0, 0, scope_id); + return miniwget2(hostname, port, path, size, 0, 0, scope_id, status_code); } void * miniwget_getaddr(const char * url, int * size, - char * addr, int addrlen, unsigned int scope_id) + char * addr, int addrlen, unsigned int scope_id, + int * status_code) { unsigned short port; char * path; @@ -621,6 +652,6 @@ miniwget_getaddr(const char * url, int * size, printf("parsed url : hostname='%s' port=%hu path='%s' scope_id=%u\n", hostname, port, path, scope_id); #endif - return miniwget2(hostname, port, path, size, addr, addrlen, scope_id); + return miniwget2(hostname, port, path, size, addr, addrlen, scope_id, status_code); } diff --git a/external/miniupnpc/miniwget.h b/external/miniupnpc/miniwget.h index e231fc27a..0701494d0 100644 --- a/external/miniupnpc/miniwget.h +++ b/external/miniupnpc/miniwget.h @@ -1,7 +1,7 @@ -/* $Id: miniwget.h,v 1.7 2012/06/23 22:35:59 nanard Exp $ */ +/* $Id: miniwget.h,v 1.12 2016/01/24 17:24:36 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard - * Copyright (c) 2005-2015 Thomas Bernard + * Copyright (c) 2005-2016 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. * */ @@ -14,11 +14,11 @@ extern "C" { #endif -MINIUPNP_LIBSPEC void * getHTTPResponse(int s, int * size); +MINIUPNP_LIBSPEC void * getHTTPResponse(int s, int * size, int * status_code); -MINIUPNP_LIBSPEC void * miniwget(const char *, int *, unsigned int); +MINIUPNP_LIBSPEC void * miniwget(const char *, int *, unsigned int, int *); -MINIUPNP_LIBSPEC void * miniwget_getaddr(const char *, int *, char *, int, unsigned int); +MINIUPNP_LIBSPEC void * miniwget_getaddr(const char *, int *, char *, int, unsigned int, int *); int parseURL(const char *, char *, unsigned short *, char * *, unsigned int *); diff --git a/external/miniupnpc/testdesc/new_LiveBox_desc.xml b/external/miniupnpc/testdesc/new_LiveBox_desc.xml index 9d5160bb8..620eb55af 100644 --- a/external/miniupnpc/testdesc/new_LiveBox_desc.xml +++ b/external/miniupnpc/testdesc/new_LiveBox_desc.xml @@ -87,4 +87,4 @@ - + \ No newline at end of file diff --git a/external/miniupnpc/testminiwget.c b/external/miniupnpc/testminiwget.c index 8ae90320e..5eb49ec1c 100644 --- a/external/miniupnpc/testminiwget.c +++ b/external/miniupnpc/testminiwget.c @@ -1,7 +1,7 @@ -/* $Id: testminiwget.c,v 1.4 2012/06/23 22:35:59 nanard Exp $ */ +/* $Id: testminiwget.c,v 1.5 2016/01/24 17:24:36 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard - * Copyright (c) 2005-2012 Thomas Bernard + * Copyright (c) 2005-2016 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. * */ @@ -20,15 +20,17 @@ int main(int argc, char * * argv) int size, writtensize; FILE *f; char addr[64]; + int status_code = -1; if(argc < 3) { fprintf(stderr, "Usage:\t%s url file\n", argv[0]); fprintf(stderr, "Example:\t%s http://www.google.com/ out.html\n", argv[0]); return 1; } - data = miniwget_getaddr(argv[1], &size, addr, sizeof(addr), 0); - if(!data) { - fprintf(stderr, "Error fetching %s\n", argv[1]); + data = miniwget_getaddr(argv[1], &size, addr, sizeof(addr), 0, &status_code); + if(!data || (status_code != 200)) { + if(data) free(data); + fprintf(stderr, "Error %d fetching %s\n", status_code, argv[1]); return 1; } printf("local address : %s\n", addr); diff --git a/external/miniupnpc/upnpc.c b/external/miniupnpc/upnpc.c index 1a910ccdc..94f131c87 100644 --- a/external/miniupnpc/upnpc.c +++ b/external/miniupnpc/upnpc.c @@ -1,7 +1,7 @@ -/* $Id: upnpc.c,v 1.111 2015/07/23 20:40:10 nanard Exp $ */ +/* $Id: upnpc.c,v 1.114 2016/01/22 15:04:23 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard - * Copyright (c) 2005-2015 Thomas Bernard + * Copyright (c) 2005-2016 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. */ @@ -66,7 +66,7 @@ static void DisplayInfos(struct UPNPUrls * urls, char connectionType[64]; char status[64]; char lastconnerr[64]; - unsigned int uptime; + unsigned int uptime = 0; unsigned int brUp, brDown; time_t timenow, timestarted; int r; @@ -82,9 +82,11 @@ static void DisplayInfos(struct UPNPUrls * urls, else printf("Status : %s, uptime=%us, LastConnectionError : %s\n", status, uptime, lastconnerr); - timenow = time(NULL); - timestarted = timenow - uptime; - printf(" Time started : %s", ctime(×tarted)); + if(uptime > 0) { + timenow = time(NULL); + timestarted = timenow - uptime; + printf(" Time started : %s", ctime(×tarted)); + } if(UPNP_GetLinkLayerMaxBitRates(urls->controlURL_CIF, data->CIF.servicetype, &brDown, &brUp) != UPNPCOMMAND_SUCCESS) { printf("GetLinkLayerMaxBitRates failed.\n"); @@ -538,7 +540,7 @@ int main(int argc, char ** argv) char ** commandargv = 0; int commandargc = 0; struct UPNPDev * devlist = 0; - char lanaddr[64]; /* my ip address on the LAN */ + char lanaddr[64] = "unset"; /* my ip address on the LAN */ int i; const char * rootdescurl = 0; const char * multicastif = 0; @@ -560,7 +562,7 @@ int main(int argc, char ** argv) } #endif printf("upnpc : miniupnpc library test client, version %s.\n", MINIUPNPC_VERSION_STRING); - printf(" (c) 2005-2015 Thomas Bernard.\n"); + printf(" (c) 2005-2016 Thomas Bernard.\n"); printf("Go to http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/\n" "for more information.\n"); /* command line processing */ diff --git a/external/miniupnpc/upnpcommands.c b/external/miniupnpc/upnpcommands.c index cabdb50d8..76cf9e391 100644 --- a/external/miniupnpc/upnpcommands.c +++ b/external/miniupnpc/upnpcommands.c @@ -616,14 +616,14 @@ UPNP_GetGenericPortMappingEntry(const char * controlURL, protocol[3] = '\0'; } p = GetValueFromNameValueList(&pdata, "NewInternalClient"); - if(p && intClient) + if(p) { strncpy(intClient, p, 16); intClient[15] = '\0'; r = 0; } p = GetValueFromNameValueList(&pdata, "NewInternalPort"); - if(p && intPort) + if(p) { strncpy(intPort, p, 6); intPort[5] = '\0'; From 1800d611a2a60ee5cdce7af266ac927118147b1f Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 21 Mar 2016 15:05:50 +0200 Subject: [PATCH 2/3] bump miniupnpc API version number --- external/miniupnpc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/miniupnpc/CMakeLists.txt b/external/miniupnpc/CMakeLists.txt index 1e7645a9d..2d75a5304 100644 --- a/external/miniupnpc/CMakeLists.txt +++ b/external/miniupnpc/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 2.6) project (miniupnpc C) set (MINIUPNPC_VERSION 1.9) -set (MINIUPNPC_API_VERSION 15) +set (MINIUPNPC_API_VERSION 16) # - we comment out this block as we don't support these other build types if(0) From 40974b155e5ef48bead0989e80fe17366029491b Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 21 Mar 2016 19:37:07 +0200 Subject: [PATCH 3/3] fix building on FreeBSD --- external/CMakeLists.txt | 3 --- external/miniupnpc/CMakeLists.txt | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 33e843e63..f0e65ac06 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -37,9 +37,6 @@ find_package(Miniupnpc QUIET) -# FreeBSD doesn't play well with the local copy, so default to using shared -set(USE_SHARED_MINIUPNPC false) - # If we have the correct shared version and we're not building static, use it if(STATIC) set(USE_SHARED_MINIUPNPC false) diff --git a/external/miniupnpc/CMakeLists.txt b/external/miniupnpc/CMakeLists.txt index 2d75a5304..fd75f9ff5 100644 --- a/external/miniupnpc/CMakeLists.txt +++ b/external/miniupnpc/CMakeLists.txt @@ -33,7 +33,7 @@ endif (NO_GETADDRINFO) if (NOT WIN32) add_definitions (-DMINIUPNPC_SET_SOCKET_TIMEOUT) - add_definitions (-D_BSD_SOURCE -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200112L) + add_definitions (-D_BSD_SOURCE -D_DEFAULT_SOURCE) else (NOT WIN32) add_definitions (-D_WIN32_WINNT=0x0501) # XP or higher for getnameinfo and friends endif (NOT WIN32)