From 1a6c57847a30ebcc947eafffd81bce2136217a9c Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Thu, 1 Dec 2016 11:56:18 +0100 Subject: [PATCH 01/33] Fix "AddPinhole Twice" test UCTT 2.0 test case - AddPinhole Twice see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=4731 --- miniupnpd/upnppinhole.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/miniupnpd/upnppinhole.c b/miniupnpd/upnppinhole.c index c4320d9..9d25977 100644 --- a/miniupnpd/upnppinhole.c +++ b/miniupnpd/upnppinhole.c @@ -134,16 +134,12 @@ upnp_add_inboundpinhole(const char * raddr, timestamp = current + leasetime; r = 0; -#if 0 - if(r == 1 && strcmp(iaddr, iaddr_old)==0 && iport==iport_old) - { - syslog(LOG_INFO, "Pinhole for inbound traffic from [%s]:%hu to [%s]:%hu with protocol %s already done. Updating it.", raddr, rport, iaddr_old, iport_old, protocol); - t = upnp_update_inboundpinhole(idfound, leaseTime); - *uid = atoi(idfound); - return t; + *uid = upnp_find_inboundpinhole(raddr, rport, iaddr, iport, proto, NULL, 0, NULL); + if(*uid >= 0) { + syslog(LOG_INFO, "Pinhole for inbound traffic from [%s]:%hu to [%s]:%hu with protocol %s found uid=%d. Updating it.", raddr, rport, iaddr, iport, protocol, *uid); + r = upnp_update_inboundpinhole(*uid, timestamp); + return (r >= 0) ? 1 : r; } - else -#endif #if defined(USE_PF) || defined(USE_NETFILTER) *uid = add_pinhole (0/*ext_if_name*/, raddr, rport, iaddr, iport, proto, desc, timestamp); From 3d9b606a88ef4661b20a3982205f84def55fbeab Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Thu, 1 Dec 2016 12:05:40 +0100 Subject: [PATCH 02/33] update Changelog.txt --- miniupnpd/Changelog.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/miniupnpd/Changelog.txt b/miniupnpd/Changelog.txt index d00cbbe..b89b1c7 100644 --- a/miniupnpd/Changelog.txt +++ b/miniupnpd/Changelog.txt @@ -1,5 +1,14 @@ $Id: Changelog.txt,v 1.428 2016/04/19 21:10:36 nanard Exp $ +2016/12/01: + Fix "AddPinhole Twice" test + +2016/11/11: + fixes build for Solaris/SunOS + +2016/07/23: + fixes build error on DragonFly BSD + VERSION 2.0 : released on 2016/04/19 2016/04/18: From cfa01c5c32c8739d6465800e3021853473ecfaae Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Thu, 1 Dec 2016 12:14:10 +0100 Subject: [PATCH 03/33] fix 1a6c57847a30ebcc947eafffd81bce2136217a9c --- miniupnpd/upnppinhole.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miniupnpd/upnppinhole.c b/miniupnpd/upnppinhole.c index 9d25977..75ecb77 100644 --- a/miniupnpd/upnppinhole.c +++ b/miniupnpd/upnppinhole.c @@ -136,7 +136,7 @@ upnp_add_inboundpinhole(const char * raddr, *uid = upnp_find_inboundpinhole(raddr, rport, iaddr, iport, proto, NULL, 0, NULL); if(*uid >= 0) { - syslog(LOG_INFO, "Pinhole for inbound traffic from [%s]:%hu to [%s]:%hu with protocol %s found uid=%d. Updating it.", raddr, rport, iaddr, iport, protocol, *uid); + syslog(LOG_INFO, "Pinhole for inbound traffic from [%s]:%hu to [%s]:%hu with proto %d found uid=%d. Updating it.", raddr, rport, iaddr, iport, proto, *uid); r = upnp_update_inboundpinhole(*uid, timestamp); return (r >= 0) ? 1 : r; } From 2a1cc8d79845e349742aaf5aefd16602b86d085f Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 16 Dec 2016 09:32:41 +0100 Subject: [PATCH 04/33] do not try to call OpenAndConfPCPv6Socket() when IPv6 is off see #49 --- miniupnpd/miniupnpd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/miniupnpd/miniupnpd.c b/miniupnpd/miniupnpd.c index 6dd0154..66d75f1 100644 --- a/miniupnpd/miniupnpd.c +++ b/miniupnpd/miniupnpd.c @@ -2004,7 +2004,9 @@ main(int argc, char * * argv) #endif #if defined(ENABLE_IPV6) && defined(ENABLE_PCP) - spcp_v6 = OpenAndConfPCPv6Socket(); + if(!GETFLAG(IPV6DISABLEDMASK)) { + spcp_v6 = OpenAndConfPCPv6Socket(); + } #endif /* for miniupnpdctl */ From 32855b854c281c6a4277fa385f0662b6291218d1 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 16 Dec 2016 09:39:19 +0100 Subject: [PATCH 05/33] dot not try to find IPv6 address if IPv6 is disabled see #49 --- miniupnpd/miniupnpd.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/miniupnpd/miniupnpd.c b/miniupnpd/miniupnpd.c index 66d75f1..7afcbc0 100644 --- a/miniupnpd/miniupnpd.c +++ b/miniupnpd/miniupnpd.c @@ -322,6 +322,7 @@ OpenAndConfHTTPSocket(unsigned short * port) syslog(LOG_WARNING, "socket(PF_INET6, ...) failed with EAFNOSUPPORT, disabling IPv6"); SETFLAG(IPV6DISABLEDMASK); ipv6 = 0; + /* Try again with IPv4 */ s = socket(PF_INET, SOCK_STREAM, 0); } #endif @@ -1927,16 +1928,18 @@ main(int argc, char * * argv) #endif /* V6SOCKETS_ARE_V6ONLY */ #endif /* ENABLE_HTTPS */ #ifdef ENABLE_IPV6 - if(find_ipv6_addr(lan_addrs.lh_first ? lan_addrs.lh_first->ifname : NULL, - ipv6_addr_for_http_with_brackets, sizeof(ipv6_addr_for_http_with_brackets)) > 0) { - syslog(LOG_NOTICE, "HTTP IPv6 address given to control points : %s", - ipv6_addr_for_http_with_brackets); - } else { - memcpy(ipv6_addr_for_http_with_brackets, "[::1]", 6); - syslog(LOG_WARNING, "no HTTP IPv6 address, disabling IPv6"); - SETFLAG(IPV6DISABLEDMASK); + if(!GETFLAG(IPV6DISABLEDMASK)) { + if(find_ipv6_addr(lan_addrs.lh_first ? lan_addrs.lh_first->ifname : NULL, + ipv6_addr_for_http_with_brackets, sizeof(ipv6_addr_for_http_with_brackets)) > 0) { + syslog(LOG_NOTICE, "HTTP IPv6 address given to control points : %s", + ipv6_addr_for_http_with_brackets); + } else { + memcpy(ipv6_addr_for_http_with_brackets, "[::1]", 6); + syslog(LOG_WARNING, "no HTTP IPv6 address, disabling IPv6"); + SETFLAG(IPV6DISABLEDMASK); + } } -#endif +#endif /* ENABLE_IPV6 */ /* open socket for SSDP connections */ sudp = OpenAndConfSSDPReceiveSocket(0); From 6bbdb817f7f79bb518c9f1761e845e2b8c798238 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 16 Dec 2016 09:59:10 +0100 Subject: [PATCH 06/33] miniupnpc: update Changelog.txt and 2015=>2016 --- miniupnpc/Changelog.txt | 9 ++++++++- miniupnpc/connecthostport.c | 2 +- miniupnpc/minihttptestserver.c | 2 +- miniupnpc/portlistingparse.c | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/miniupnpc/Changelog.txt b/miniupnpc/Changelog.txt index 078bebc..76d947b 100644 --- a/miniupnpc/Changelog.txt +++ b/miniupnpc/Changelog.txt @@ -1,6 +1,13 @@ -$Id: Changelog.txt,v 1.223 2016/04/19 21:06:20 nanard Exp $ +$Id: Changelog.txt,v 1.226 2016/12/16 08:57:19 nanard Exp $ miniUPnP client Changelog. +2016/11/11: + check strlen before memcmp in XML parsing portlistingparse.c + fix build under SOLARIS and CYGWIN + +2016/10/11: + Add python 3 compatibility to IGD test + VERSION 2.0 : released 2016/04/19 2016/01/24: diff --git a/miniupnpc/connecthostport.c b/miniupnpc/connecthostport.c index 7db958b..e3c17d3 100644 --- a/miniupnpc/connecthostport.c +++ b/miniupnpc/connecthostport.c @@ -1,7 +1,7 @@ /* $Id: connecthostport.c,v 1.15 2015/10/09 16:26:19 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard - * Copyright (c) 2010-2015 Thomas Bernard + * Copyright (c) 2010-2016 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. */ diff --git a/miniupnpc/minihttptestserver.c b/miniupnpc/minihttptestserver.c index b2178e8..b7a5cea 100644 --- a/miniupnpc/minihttptestserver.c +++ b/miniupnpc/minihttptestserver.c @@ -1,7 +1,7 @@ /* $Id: minihttptestserver.c,v 1.19 2015/11/17 09:07:17 nanard Exp $ */ /* Project : miniUPnP * Author : Thomas Bernard - * Copyright (c) 2011-2015 Thomas Bernard + * Copyright (c) 2011-2016 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. * */ diff --git a/miniupnpc/portlistingparse.c b/miniupnpc/portlistingparse.c index 07f3f87..55859f2 100644 --- a/miniupnpc/portlistingparse.c +++ b/miniupnpc/portlistingparse.c @@ -1,7 +1,7 @@ /* $Id: portlistingparse.c,v 1.9 2015/07/15 12:41:13 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2011-2015 Thomas Bernard + * (c) 2011-2016 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ #include From 9fc3b090173ffd95e8e44e7547a73e4ed4064240 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 16 Dec 2016 10:15:42 +0100 Subject: [PATCH 07/33] miniupnpd: update changelog and 2016 --- miniupnpd/Changelog.txt | 5 ++++- miniupnpd/asyncsendto.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/miniupnpd/Changelog.txt b/miniupnpd/Changelog.txt index b89b1c7..6fa44d3 100644 --- a/miniupnpd/Changelog.txt +++ b/miniupnpd/Changelog.txt @@ -1,4 +1,7 @@ -$Id: Changelog.txt,v 1.428 2016/04/19 21:10:36 nanard Exp $ +$Id: Changelog.txt,v 1.430 2016/12/16 09:14:40 nanard Exp $ + +2016/12/16: + Do not try to open IPv6 sockets once it is disabled 2016/12/01: Fix "AddPinhole Twice" test diff --git a/miniupnpd/asyncsendto.c b/miniupnpd/asyncsendto.c index bd21e93..4b345de 100644 --- a/miniupnpd/asyncsendto.c +++ b/miniupnpd/asyncsendto.c @@ -1,7 +1,7 @@ /* $Id: asyncsendto.c,v 1.7 2015/09/03 18:19:20 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2006-2014 Thomas Bernard + * (c) 2006-2016 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ From 0bf264dbeba945af89ceea9b618debd2b188cbd3 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 16 Dec 2016 10:23:25 +0100 Subject: [PATCH 08/33] minissdpd: update Change log and 2016 --- minissdpd/Changelog.txt | 5 ++++- minissdpd/ifacewatch.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/minissdpd/Changelog.txt b/minissdpd/Changelog.txt index bbf2afa..31eec1c 100644 --- a/minissdpd/Changelog.txt +++ b/minissdpd/Changelog.txt @@ -1,4 +1,7 @@ -$Id: Changelog.txt,v 1.45 2016/03/01 18:06:46 nanard Exp $ +$Id: Changelog.txt,v 1.47 2016/12/16 09:22:35 nanard Exp $ + +2016/11/11: + Fix for Solaris build 2016/03/01: Fix broken overflow test (p+l > buf+n) thanks to Salva Peiro diff --git a/minissdpd/ifacewatch.c b/minissdpd/ifacewatch.c index f91eff7..2909636 100644 --- a/minissdpd/ifacewatch.c +++ b/minissdpd/ifacewatch.c @@ -1,6 +1,6 @@ /* $Id: ifacewatch.c,v 1.16 2015/09/03 18:31:25 nanard Exp $ */ /* MiniUPnP project - * (c) 2011-2012 Thomas Bernard + * (c) 2011-2016 Thomas Bernard * website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ From 3571a41d1ba36107f968de9fe71b68ae86b95029 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 23 Dec 2016 12:12:49 +0100 Subject: [PATCH 09/33] Fix UDA-1.2.10 Man header empty or invalid --- miniupnpd/Changelog.txt | 3 +++ miniupnpd/minissdp.c | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/miniupnpd/Changelog.txt b/miniupnpd/Changelog.txt index 6fa44d3..8e73485 100644 --- a/miniupnpd/Changelog.txt +++ b/miniupnpd/Changelog.txt @@ -1,5 +1,8 @@ $Id: Changelog.txt,v 1.430 2016/12/16 09:14:40 nanard Exp $ +2016/12/23: + Fix UDA-1.2.10 Man header empty or invalid + 2016/12/16: Do not try to open IPv6 sockets once it is disabled diff --git a/miniupnpd/minissdp.c b/miniupnpd/minissdp.c index 1d19144..81a0714 100644 --- a/miniupnpd/minissdp.c +++ b/miniupnpd/minissdp.c @@ -889,7 +889,26 @@ ProcessSSDPData(int s, const char *bufr, int n, mx_value = atoi(mx); syslog(LOG_DEBUG, "MX: %.*s (value=%d)", mx_len, mx, mx_value); } -#endif +#endif /* defined(UPNP_STRICT) || defined(DELAY_MSEARCH_RESPONSE) */ +#if defined(UPNP_STRICT) + /* Fix UDA-1.2.10 Man header empty or invalid */ + else if((i < n - 4) && (strncasecmp(bufr+i, "man:", 3) == 0)) + { + const char * man; + int man_len; + man = bufr+i+4; + man_len = 0; + while((*man == ' ' || *man == '\t') && (man < bufr + n)) + man++; + while(man[man_len]!='\r' && man[man_len]!='\n' + && (man + man_len < bufr + n)) + man_len++; + if(strncmp(man, "\"ssdp:discover\"", 15) != 0) { + syslog(LOG_INFO, "ignoring SSDP packet MAN empty or invalid header"); + return; + } + } +#endif /* defined(UPNP_STRICT) */ } #ifdef UPNP_STRICT /* For multicast M-SEARCH requests, if the search request does From 9e73075752806da45527c9ba0ef134f5bd7b8167 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 28 Dec 2016 10:16:47 +0100 Subject: [PATCH 10/33] initialize Winsock in python module fixes #221 --- miniupnpc/miniupnpcmodule.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/miniupnpc/miniupnpcmodule.c b/miniupnpc/miniupnpcmodule.c index fd97047..73bd2ea 100644 --- a/miniupnpc/miniupnpcmodule.c +++ b/miniupnpc/miniupnpcmodule.c @@ -2,7 +2,7 @@ /* Project : miniupnp * Author : Thomas BERNARD * website : http://miniupnp.tuxfamily.org/ - * copyright (c) 2007-2014 Thomas Bernard + * copyright (c) 2007-2016 Thomas Bernard * This software is subjet to the conditions detailed in the * provided LICENCE file. */ #include @@ -12,6 +12,10 @@ #include "upnpcommands.h" #include "upnperrors.h" +#ifdef _WIN32 +#include +#endif + /* for compatibility with Python < 2.4 */ #ifndef Py_RETURN_NONE #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None @@ -669,6 +673,10 @@ initminiupnpc(void) PyObject* m; #ifdef _WIN32 + /* initialize Winsock. */ + WSADATA wsaData; + int nResult = WSAStartup(MAKEWORD(2,2), &wsaData); + UPnPType.tp_new = PyType_GenericNew; #endif if (PyType_Ready(&UPnPType) < 0) From 2c777218888b5d28786fb84504aa7239198718d9 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 28 Dec 2016 11:58:21 +0100 Subject: [PATCH 11/33] do not split conditional statement #184 closes #184 --- miniupnpd/miniupnpd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/miniupnpd/miniupnpd.c b/miniupnpd/miniupnpd.c index 7afcbc0..b145fe4 100644 --- a/miniupnpd/miniupnpd.c +++ b/miniupnpd/miniupnpd.c @@ -1855,9 +1855,11 @@ main(int argc, char * * argv) if( #ifdef ENABLE_NATPMP - !GETFLAG(ENABLENATPMPMASK) && + !GETFLAG(ENABLENATPMPMASK) && !GETFLAG(ENABLEUPNPMASK) +#else + !GETFLAG(ENABLEUPNPMASK) #endif - !GETFLAG(ENABLEUPNPMASK) ) { + ) { syslog(LOG_ERR, "Why did you run me anyway?"); return 0; } From ee2f6ac2ce2efe0c999e14717e5026d6e372b7fa Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 28 Dec 2016 12:10:06 +0100 Subject: [PATCH 12/33] miniupnpd: FreeBSD uses /etc/defaults/rc.conf fixes #24 --- miniupnpd/Makefile | 4 ++-- miniupnpd/genconfig.sh | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/miniupnpd/Makefile b/miniupnpd/Makefile index e858a04..120d238 100644 --- a/miniupnpd/Makefile +++ b/miniupnpd/Makefile @@ -46,8 +46,8 @@ FWNAME = pf # better way to find if we are using ipf or pf .if $(OSNAME) == "FreeBSD" -.if exists(/etc/rc.subr) && exists(/etc/rc.conf) -FWNAME != . /etc/rc.subr; . /etc/rc.conf; \ +.if exists(/etc/rc.subr) && exists(/etc/default/rc.conf) +FWNAME != . /etc/rc.subr; . /etc/default/rc.conf; \ if checkyesno ipfilter_enable; then \ echo "ipf"; elif checkyesno pf_enable; then \ echo "pf"; elif checkyesno firewall_enable; then \ diff --git a/miniupnpd/genconfig.sh b/miniupnpd/genconfig.sh index db5290e..1e0f0b7 100755 --- a/miniupnpd/genconfig.sh +++ b/miniupnpd/genconfig.sh @@ -1,5 +1,7 @@ #! /bin/sh # $Id: genconfig.sh,v 1.90 2016/02/11 10:35:12 nanard Exp $ +# vim: tabstop=4 shiftwidth=4 noexpandtab +# # miniupnp daemon # http://miniupnp.free.fr or http://miniupnp.tuxfamily.org/ # (c) 2006-2016 Thomas Bernard @@ -166,14 +168,14 @@ case $OS_NAME in HAVE_IP_MREQN=1 # new way to see which one to use PF or IPF. # see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957 - if [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then + if [ -f /etc/rc.subr ] && [ -f /etc/default/rc.conf ] ; then # source file with handy subroutines like checkyesno . /etc/rc.subr # source config file so we can probe vars - . /etc/rc.conf + . /etc/default/rc.conf if checkyesno ipfilter_enable; then echo "Using ipf" - FW=ipf + FW=ipf elif checkyesno pf_enable; then echo "Using pf" FW=pf From 7aaf82a6542433e1165f42b9246ec5901e21f5d7 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 28 Dec 2016 12:43:27 +0100 Subject: [PATCH 13/33] miniupnpd: Update conf instructions in INSTALL see #102 https://github.com/miniupnp/miniupnp/issues/102 --- miniupnpd/INSTALL | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/miniupnpd/INSTALL b/miniupnpd/INSTALL index 2c6f53b..bbcf3d5 100644 --- a/miniupnpd/INSTALL +++ b/miniupnpd/INSTALL @@ -123,6 +123,23 @@ https://github.com/miniupnp/miniupnp/pull/114 Edit the /etc/miniupnpd.conf file to set options. Almost all options are also available through command line switches. +A basic configuration would set : +ext_ifname : WAN network interface (interface connected to the internet) +listening_ip : LAN network interface (network where to supply NAT traversal) +enable_natpmp=yes +enable_upnp=yes +and the permission rules (see below). + +Historically, LAN had to be specified by IP/mask, such as +listening_ip=192.168.0.1/24 +but if you compiled with IPv6 support, you need to specify an interface name : +listening_ip=eth0 +The current code assumes there is only one IPv4 address assigned to LAN +interfaces. That is not the case with some CARP setup, there is then a risk +the wrong mask would be picked. You can force the mask when using interface +names : +listtening_ip=eth0/24 + Miniupnpd supports some kind of security check for allowing or disallowing redirection to be made. The UPnP permission rules are read from the miniupnpd.conf configuration file. @@ -162,5 +179,3 @@ To stop the daemon use : # kill `cat /var/run/miniupnpd.pid` or if your linux system use /etc/init.d/ # /etc/init.d/miniupnpd stop - - From 0e6917841263e7345c37579a1b7403307aaa0631 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 28 Dec 2016 12:44:38 +0100 Subject: [PATCH 14/33] miniupnpd: improve README --- miniupnpd/README | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/miniupnpd/README b/miniupnpd/README index b7e9d12..6ad3526 100644 --- a/miniupnpd/README +++ b/miniupnpd/README @@ -20,19 +20,18 @@ In 2012, IGD v2 WANIPv6FirewallControl has been implemented. IGD2 is still not enabled by default because of interoperability issues. -Support for the NAT Port Mapping Protocol (NAT-PMP) has been -added. See information about NAT-PMP here : -http://miniupnp.free.fr/nat-pmp.html +In addition to UPnP IGD, miniUPnPd supports NAT-PMP and PCP : -NAT-PMP is the precursor of Port Control Protocol (PCP). +See information about NAT Port Mapping Protocol (NAT-PMP) here : +http://miniupnp.free.fr/nat-pmp.html +NAT-PMP is the precursor of Port Control Protocol (PCP, RFC 6887). In 2013, support for PCP has been added too. Read the INSTALL file for instructions to compile, install and configure miniupnpd on your system. -Report bugs to miniupnp@free.fr on the web forum +Report bugs to miniupnp@free.fr or on the web forum http://miniupnp.tuxfamily.org/forum/ or using https://github.com/miniupnp/miniupnp/issues Thomas Bernard - From b433902c025458acf8a4f329adc4de9d43c9a77a Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 30 Dec 2016 16:42:33 +0100 Subject: [PATCH 15/33] update .gitignore for win32 files --- miniupnpc/.gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/miniupnpc/.gitignore b/miniupnpc/.gitignore index b1209cc..6bc38af 100644 --- a/miniupnpc/.gitignore +++ b/miniupnpc/.gitignore @@ -4,6 +4,9 @@ build/ *.a *.so *.dll +*.dll.def +*.exe +*.lib *.dylib Makefile.bak miniupnpcstrings.h @@ -30,3 +33,4 @@ testigddescparse validateigddescparse dist/ miniupnpc.egg-info/ +init From e7068a7d340f1ca84e56d51a49dbe4a247863fc0 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 30 Dec 2016 20:07:59 +0100 Subject: [PATCH 16/33] LDLIBS, not LDFLAGS :) --- miniupnpc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miniupnpc/Makefile b/miniupnpc/Makefile index 6dcf4b1..51a19f0 100644 --- a/miniupnpc/Makefile +++ b/miniupnpc/Makefile @@ -65,7 +65,7 @@ JNAERATORARGS = -mode StandaloneJar -runtime JNAerator -library miniupnpc JNAERATORBASEURL = https://repo1.maven.org/maven2/com/nativelibs4java/jnaerator/0.12 ifeq (SunOS, $(OS)) - LDFLAGS=-lsocket -lnsl -lresolv + LDLIBS=-lsocket -lnsl -lresolv CFLAGS += -D__EXTENSIONS__ CFLAGS += -std=c99 endif From c8b42602a28654fab31982f898b680bf4ec43dd1 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 9 Jan 2017 09:54:54 +0100 Subject: [PATCH 17/33] fix potential mem leaks in upnpcommands.c fixes #225 --- miniupnpc/upnpcommands.c | 89 +++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/miniupnpc/upnpcommands.c b/miniupnpc/upnpcommands.c index 76cf9e3..9f70449 100644 --- a/miniupnpc/upnpcommands.c +++ b/miniupnpc/upnpcommands.c @@ -1,7 +1,8 @@ /* $Id: upnpcommands.c,v 1.46 2015/07/15 12:19:00 nanard Exp $ */ -/* Project : miniupnp +/* vim: tabstop=4 shiftwidth=4 noexpandtab + * Project : miniupnp * Author : Thomas Bernard - * Copyright (c) 2005-2015 Thomas Bernard + * Copyright (c) 2005-2017 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. * */ @@ -372,10 +373,11 @@ UPNP_AddPortMapping(const char * controlURL, const char * servicetype, AddPortMappingArgs[6].val = desc?desc:"libminiupnpc"; AddPortMappingArgs[7].elt = "NewLeaseDuration"; AddPortMappingArgs[7].val = leaseDuration?leaseDuration:"0"; - if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, - "AddPortMapping", AddPortMappingArgs, - &bufsize))) { - free(AddPortMappingArgs); + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "AddPortMapping", AddPortMappingArgs, + &bufsize); + free(AddPortMappingArgs); + if(!buffer) { return UPNPCOMMAND_HTTP_ERROR; } /*DisplayNameValueList(buffer, bufsize);*/ @@ -392,7 +394,6 @@ UPNP_AddPortMapping(const char * controlURL, const char * servicetype, ret = UPNPCOMMAND_SUCCESS; } ClearNameValueList(&pdata); - free(AddPortMappingArgs); return ret; } @@ -436,10 +437,11 @@ UPNP_AddAnyPortMapping(const char * controlURL, const char * servicetype, 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); + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "AddAnyPortMapping", AddPortMappingArgs, + &bufsize); + free(AddPortMappingArgs); + if(!buffer) { return UPNPCOMMAND_HTTP_ERROR; } ParseNameValue(buffer, bufsize, &pdata); @@ -461,7 +463,6 @@ UPNP_AddAnyPortMapping(const char * controlURL, const char * servicetype, } } ClearNameValueList(&pdata); - free(AddPortMappingArgs); return ret; } @@ -490,10 +491,11 @@ UPNP_DeletePortMapping(const char * controlURL, const char * servicetype, DeletePortMappingArgs[1].val = extPort; DeletePortMappingArgs[2].elt = "NewProtocol"; DeletePortMappingArgs[2].val = proto; - if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, - "DeletePortMapping", - DeletePortMappingArgs, &bufsize))) { - free(DeletePortMappingArgs); + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "DeletePortMapping", + DeletePortMappingArgs, &bufsize); + free(DeletePortMappingArgs); + if(!buffer) { return UPNPCOMMAND_HTTP_ERROR; } /*DisplayNameValueList(buffer, bufsize);*/ @@ -507,7 +509,6 @@ UPNP_DeletePortMapping(const char * controlURL, const char * servicetype, ret = UPNPCOMMAND_SUCCESS; } ClearNameValueList(&pdata); - free(DeletePortMappingArgs); return ret; } @@ -539,10 +540,11 @@ UPNP_DeletePortMappingRange(const char * controlURL, const char * servicetype, DeletePortMappingArgs[3].elt = "NewManage"; DeletePortMappingArgs[3].val = manage; - if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, - "DeletePortMappingRange", - DeletePortMappingArgs, &bufsize))) { - free(DeletePortMappingArgs); + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "DeletePortMappingRange", + DeletePortMappingArgs, &bufsize); + free(DeletePortMappingArgs); + if(!buffer) { return UPNPCOMMAND_HTTP_ERROR; } ParseNameValue(buffer, bufsize, &pdata); @@ -555,7 +557,6 @@ UPNP_DeletePortMappingRange(const char * controlURL, const char * servicetype, ret = UPNPCOMMAND_SUCCESS; } ClearNameValueList(&pdata); - free(DeletePortMappingArgs); return ret; } @@ -587,10 +588,11 @@ UPNP_GetGenericPortMappingEntry(const char * controlURL, return UPNPCOMMAND_MEM_ALLOC_ERROR; GetPortMappingArgs[0].elt = "NewPortMappingIndex"; GetPortMappingArgs[0].val = index; - if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, - "GetGenericPortMappingEntry", - GetPortMappingArgs, &bufsize))) { - free(GetPortMappingArgs); + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetGenericPortMappingEntry", + GetPortMappingArgs, &bufsize); + free(GetPortMappingArgs); + if(!buffer) { return UPNPCOMMAND_HTTP_ERROR; } ParseNameValue(buffer, bufsize, &pdata); @@ -652,7 +654,6 @@ UPNP_GetGenericPortMappingEntry(const char * controlURL, sscanf(p, "%d", &r); } ClearNameValueList(&pdata); - free(GetPortMappingArgs); return r; } @@ -728,10 +729,11 @@ UPNP_GetSpecificPortMappingEntry(const char * controlURL, GetPortMappingArgs[1].val = extPort; GetPortMappingArgs[2].elt = "NewProtocol"; GetPortMappingArgs[2].val = proto; - if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, - "GetSpecificPortMappingEntry", - GetPortMappingArgs, &bufsize))) { - free(GetPortMappingArgs); + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetSpecificPortMappingEntry", + GetPortMappingArgs, &bufsize); + free(GetPortMappingArgs); + if(!buffer) { return UPNPCOMMAND_HTTP_ERROR; } /*DisplayNameValueList(buffer, bufsize);*/ @@ -779,7 +781,6 @@ UPNP_GetSpecificPortMappingEntry(const char * controlURL, } ClearNameValueList(&pdata); - free(GetPortMappingArgs); return ret; } @@ -824,13 +825,13 @@ UPNP_GetListOfPortMappings(const char * controlURL, GetListOfPortMappingsArgs[4].elt = "NewNumberOfPorts"; GetListOfPortMappingsArgs[4].val = numberOfPorts?numberOfPorts:"1000"; - if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype, - "GetListOfPortMappings", - GetListOfPortMappingsArgs, &bufsize))) { - free(GetListOfPortMappingsArgs); + buffer = simpleUPnPcommand(-1, controlURL, servicetype, + "GetListOfPortMappings", + GetListOfPortMappingsArgs, &bufsize); + free(GetListOfPortMappingsArgs); + if(!buffer) { return UPNPCOMMAND_HTTP_ERROR; } - free(GetListOfPortMappingsArgs); /*DisplayNameValueList(buffer, bufsize);*/ ParseNameValue(buffer, bufsize, &pdata); @@ -954,6 +955,7 @@ UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype GetOutboundPinholeTimeoutArgs[4].val = intClient; buffer = simpleUPnPcommand(-1, controlURL, servicetype, "GetOutboundPinholeTimeout", GetOutboundPinholeTimeoutArgs, &bufsize); + free(GetOutboundPinholeTimeoutArgs); if(!buffer) return UPNPCOMMAND_HTTP_ERROR; ParseNameValue(buffer, bufsize, &pdata); @@ -972,7 +974,6 @@ UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype *opTimeout = my_atoui(p); } ClearNameValueList(&pdata); - free(GetOutboundPinholeTimeoutArgs); return ret; } @@ -1031,6 +1032,7 @@ UPNP_AddPinhole(const char * controlURL, const char * servicetype, AddPinholeArgs[5].val = leaseTime; buffer = simpleUPnPcommand(-1, controlURL, servicetype, "AddPinhole", AddPinholeArgs, &bufsize); + free(AddPinholeArgs); if(!buffer) return UPNPCOMMAND_HTTP_ERROR; ParseNameValue(buffer, bufsize, &pdata); @@ -1053,7 +1055,6 @@ UPNP_AddPinhole(const char * controlURL, const char * servicetype, ret = UPNPCOMMAND_SUCCESS; } ClearNameValueList(&pdata); - free(AddPinholeArgs); return ret; } @@ -1081,6 +1082,7 @@ UPNP_UpdatePinhole(const char * controlURL, const char * servicetype, UpdatePinholeArgs[1].val = leaseTime; buffer = simpleUPnPcommand(-1, controlURL, servicetype, "UpdatePinhole", UpdatePinholeArgs, &bufsize); + free(UpdatePinholeArgs); if(!buffer) return UPNPCOMMAND_HTTP_ERROR; ParseNameValue(buffer, bufsize, &pdata); @@ -1097,7 +1099,6 @@ UPNP_UpdatePinhole(const char * controlURL, const char * servicetype, ret = UPNPCOMMAND_SUCCESS; } ClearNameValueList(&pdata); - free(UpdatePinholeArgs); return ret; } @@ -1122,6 +1123,7 @@ UPNP_DeletePinhole(const char * controlURL, const char * servicetype, const char DeletePinholeArgs[0].val = uniqueID; buffer = simpleUPnPcommand(-1, controlURL, servicetype, "DeletePinhole", DeletePinholeArgs, &bufsize); + free(DeletePinholeArgs); if(!buffer) return UPNPCOMMAND_HTTP_ERROR; /*DisplayNameValueList(buffer, bufsize);*/ @@ -1138,7 +1140,6 @@ UPNP_DeletePinhole(const char * controlURL, const char * servicetype, const char ret = UPNPCOMMAND_SUCCESS; } ClearNameValueList(&pdata); - free(DeletePinholeArgs); return ret; } @@ -1163,8 +1164,11 @@ UPNP_CheckPinholeWorking(const char * controlURL, const char * servicetype, CheckPinholeWorkingArgs[0].val = uniqueID; buffer = simpleUPnPcommand(-1, controlURL, servicetype, "CheckPinholeWorking", CheckPinholeWorkingArgs, &bufsize); + free(CheckPinholeWorkingArgs); if(!buffer) + { return UPNPCOMMAND_HTTP_ERROR; + } ParseNameValue(buffer, bufsize, &pdata); free(buffer); buffer = NULL; @@ -1185,7 +1189,6 @@ UPNP_CheckPinholeWorking(const char * controlURL, const char * servicetype, } ClearNameValueList(&pdata); - free(CheckPinholeWorkingArgs); return ret; } @@ -1210,6 +1213,7 @@ UPNP_GetPinholePackets(const char * controlURL, const char * servicetype, GetPinholePacketsArgs[0].val = uniqueID; buffer = simpleUPnPcommand(-1, controlURL, servicetype, "GetPinholePackets", GetPinholePacketsArgs, &bufsize); + free(GetPinholePacketsArgs); if(!buffer) return UPNPCOMMAND_HTTP_ERROR; ParseNameValue(buffer, bufsize, &pdata); @@ -1230,7 +1234,6 @@ UPNP_GetPinholePackets(const char * controlURL, const char * servicetype, } ClearNameValueList(&pdata); - free(GetPinholePacketsArgs); return ret; } From 8c9ce4dbb4aed03d7ed88df8da9c0aff29d83ee6 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 9 Jan 2017 10:16:29 +0100 Subject: [PATCH 18/33] make sure no unitialized memory is accessed in the sockaddr_un structure --- miniupnpc/minissdpc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/miniupnpc/minissdpc.c b/miniupnpc/minissdpc.c index 3dda648..89b9d24 100644 --- a/miniupnpc/minissdpc.c +++ b/miniupnpc/minissdpc.c @@ -3,7 +3,7 @@ * Project : miniupnp * Web : http://miniupnp.free.fr/ * Author : Thomas BERNARD - * copyright (c) 2005-2016 Thomas Bernard + * copyright (c) 2005-2017 Thomas Bernard * This software is subjet to the conditions detailed in the * provided LICENCE file. */ /*#include */ @@ -201,6 +201,7 @@ connectToMiniSSDPD(const char * socketpath) #endif /* #ifdef MINIUPNPC_SET_SOCKET_TIMEOUT */ if(!socketpath) socketpath = "/var/run/minissdpd.sock"; + memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, socketpath, sizeof(addr.sun_path)); /* TODO : check if we need to handle the EINTR */ From a39fd6d2805cfb50a3020921f12a0d3f57b5a811 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 30 Jan 2017 17:44:34 +0100 Subject: [PATCH 19/33] bsd/getroute.c: output offset see #227 --- miniupnpd/bsd/getroute.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/miniupnpd/bsd/getroute.c b/miniupnpd/bsd/getroute.c index 5f9d93d..dacad86 100644 --- a/miniupnpd/bsd/getroute.c +++ b/miniupnpd/bsd/getroute.c @@ -102,7 +102,8 @@ get_src_for_route_to(const struct sockaddr * dst, } sa = (struct sockaddr *)p; sockaddr_to_string(sa, tmp, sizeof(tmp)); - syslog(LOG_DEBUG, "type=%d sa_len=%d sa_family=%d %s", + syslog(LOG_DEBUG, "offset=%3d type=%2d sa_len=%d sa_family=%d %s", + (int)(p - m_rtmsg.m_space), i, SA_LEN(sa), sa->sa_family, tmp); if(i == RTA_IFA) { size_t len = 0; From 859b9863854244fdb7eb65f9c185df4e8fe71dc0 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 30 Jan 2017 17:52:57 +0100 Subject: [PATCH 20/33] bsd/getroute.c: proper SA_SIZE() definition fixes #227 --- miniupnpd/bsd/getroute.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/miniupnpd/bsd/getroute.c b/miniupnpd/bsd/getroute.c index dacad86..292504d 100644 --- a/miniupnpd/bsd/getroute.c +++ b/miniupnpd/bsd/getroute.c @@ -1,7 +1,7 @@ /* $Id: getroute.c,v 1.12 2015/11/19 11:46:30 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2006-2015 Thomas Bernard + * (c) 2006-2017 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ @@ -20,8 +20,9 @@ #include "../config.h" #include "../upnputils.h" +/* SA_SIZE() is a multiple of sizeof(long) with a minimum value of sizeof(long) */ #ifndef SA_SIZE -#define SA_SIZE(sa) (SA_LEN(sa)) +#define SA_SIZE(sa) (((SA_LEN(sa)) == 0) ? sizeof(long) : (1 + (((SA_LEN(sa)) - 1) | (sizeof(long) - 1)))) #endif /* SA_SIZE */ int @@ -135,14 +136,7 @@ get_src_for_route_to(const struct sockaddr * dst, *index = sdl->sdl_index; } #endif - /* at least 4 bytes per address are reserved, - * that is true with OpenBSD 4.3. - * The test is only useful when SA_SIZE() is not properly - * defined, as it should be always >= sizeof(long) */ - if(SA_SIZE(sa) > 0) - p += SA_SIZE(sa); - else - p += sizeof(long); + p += SA_SIZE(sa); } } } From 2c262a87932536cce6f7e1103f6616d69d67f0a3 Mon Sep 17 00:00:00 2001 From: Darexon Date: Wed, 15 Feb 2017 00:01:41 -0600 Subject: [PATCH 21/33] AddPortMapping() now returns an error code --- miniupnpc/upnpc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/miniupnpc/upnpc.c b/miniupnpc/upnpc.c index 533439b..b722a2f 100644 --- a/miniupnpc/upnpc.c +++ b/miniupnpc/upnpc.c @@ -292,9 +292,11 @@ static int SetRedirectAndTest(struct UPNPUrls * urls, r = UPNP_AddPortMapping(urls->controlURL, data->first.servicetype, eport, iport, iaddr, description, proto, 0, leaseDuration); - if(r!=UPNPCOMMAND_SUCCESS) + if(r!=UPNPCOMMAND_SUCCESS) { printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", eport, iport, iaddr, r, strupnperror(r)); + return -2; + } } r = UPNP_GetSpecificPortMappingEntry(urls->controlURL, From 7aaa60076932d0bbfb1b158c93650625a7a48407 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 15 Feb 2017 12:10:59 +0100 Subject: [PATCH 22/33] travis-ci: libevent-2.0.22 is now already installed was causing : $ if [ "$TRAVIS_OS_NAME" = "osx" -a "$PROJECT" = "miniupnpc-libevent" ]; then brew update > /dev/null && brew install libevent; fi Error: libevent-2.0.22 already installed To install this version, first `brew unlink libevent` --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 665e965..a890857 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,9 +32,6 @@ compiler: - gcc - clang -before_install: - - 'if [ "$TRAVIS_OS_NAME" = "osx" -a "$PROJECT" = "miniupnpc-libevent" ]; then brew update > /dev/null && brew install libevent; fi' - script: - 'cd $TRAVIS_BUILD_DIR && cd $PROJECT' - 'MAKEFILE=Makefile && if [ -f Makefile.linux -a "$TRAVIS_OS_NAME" = "linux" ]; then MAKEFILE=Makefile.linux; elif [ -f Makefile.macosx -a "$TRAVIS_OS_NAME" = "osx" ]; then MAKEFILE=Makefile.macosx; fi' From 8208d873bffc5a6ae02b6ae07bda3aeae725b746 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 15 Feb 2017 12:15:36 +0100 Subject: [PATCH 23/33] travis-ci: OS X : compile with real gcc 4.9 instead of clang gcc frontend --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index a890857..24941f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,9 @@ compiler: - gcc - clang +before_install: + - 'if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "$CC" == "gcc" ] ; then CC=gcc-4.9; fi' + script: - 'cd $TRAVIS_BUILD_DIR && cd $PROJECT' - 'MAKEFILE=Makefile && if [ -f Makefile.linux -a "$TRAVIS_OS_NAME" = "linux" ]; then MAKEFILE=Makefile.linux; elif [ -f Makefile.macosx -a "$TRAVIS_OS_NAME" = "osx" ]; then MAKEFILE=Makefile.macosx; fi' From 93845c5abee85ce29c16e495a3ece1acd3a50072 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 13 Mar 2017 11:03:58 +0100 Subject: [PATCH 24/33] DEfault to client address for AddPortMapping when is empty see #236 --- miniupnpd/Changelog.txt | 4 ++++ miniupnpd/upnpsoap.c | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/miniupnpd/Changelog.txt b/miniupnpd/Changelog.txt index 8e73485..f609457 100644 --- a/miniupnpd/Changelog.txt +++ b/miniupnpd/Changelog.txt @@ -1,5 +1,9 @@ $Id: Changelog.txt,v 1.430 2016/12/16 09:14:40 nanard Exp $ +2017/03/13: + default to client address for AddPortMapping when + is empty + 2016/12/23: Fix UDA-1.2.10 Man header empty or invalid diff --git a/miniupnpd/upnpsoap.c b/miniupnpd/upnpsoap.c index c128cb1..9087ab8 100644 --- a/miniupnpd/upnpsoap.c +++ b/miniupnpd/upnpsoap.c @@ -1,7 +1,7 @@ /* $Id: upnpsoap.c,v 1.144 2016/02/12 12:35:03 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2006-2016 Thomas Bernard + * (c) 2006-2017 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ @@ -388,12 +388,19 @@ AddPortMapping(struct upnphttp * h, const char * action, const char * ns) ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data); int_ip = GetValueFromNameValueList(&data, "NewInternalClient"); - if (!int_ip) + if (int_ip) { + /* trim */ + while(int_ip[0] == ' ') + int_ip++; + } +#ifdef UPNP_STRICT + if (!int_ip || int_ip[0] == '\0') { ClearNameValueList(&data); SoapError(h, 402, "Invalid Args"); return; } +#endif /* IGD 2 MUST support both wildcard and specific IP address values * for RemoteHost (only the wildcard value was REQUIRED in release 1.0) */ @@ -409,6 +416,16 @@ AddPortMapping(struct upnphttp * h, const char * action, const char * ns) #endif #endif +#ifndef UPNP_STRICT + /* if arg is empty, use client address + * see https://github.com/miniupnp/miniupnp/issues/236 */ + if (!int_ip || int_ip[0] == '\0') + { + int_ip = h->clientaddr_str; + memcpy(&result_ip, &(h->clientaddr), sizeof(struct in_addr)); + } + else +#endif /* if ip not valid assume hostname and convert */ if (inet_pton(AF_INET, int_ip, &result_ip) <= 0) { From 07a3729b59f7dee0471a5372a0427a39c9b980ad Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 13 Mar 2017 11:30:44 +0100 Subject: [PATCH 25/33] sanitize arg of AddPinhole see #228 --- miniupnpd/upnpsoap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/miniupnpd/upnpsoap.c b/miniupnpd/upnpsoap.c index 9087ab8..315cd07 100644 --- a/miniupnpd/upnpsoap.c +++ b/miniupnpd/upnpsoap.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "macros.h" #include "config.h" @@ -1621,8 +1622,14 @@ AddPinhole(struct upnphttp * h, const char * action, const char * ns) goto clear_and_exit; } /* I guess it is useless to convert int_ip to literal ipv6 address */ + if(rem_host) + { + /* trim */ + while(isspace(rem_host[0])) + rem_host++; + } /* rem_host should be converted to literal ipv6 : */ - if(rem_host && (rem_host[0] != '\0')) + if(rem_host && (rem_host[0] != '\0') && (rem_host[0] != '*')) { struct addrinfo *ai, *p; struct addrinfo hints; From 2c02ef2b7bb9bf64d4374b71b8d33804b245760b Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 13 Mar 2017 11:37:43 +0100 Subject: [PATCH 26/33] right printf format in testobsdrdr.c and tespfpinhole.c --- miniupnpd/pf/testobsdrdr.c | 4 ++-- miniupnpd/pf/testpfpinhole.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/miniupnpd/pf/testobsdrdr.c b/miniupnpd/pf/testobsdrdr.c index 13d9ee5..e865989 100644 --- a/miniupnpd/pf/testobsdrdr.c +++ b/miniupnpd/pf/testobsdrdr.c @@ -1,7 +1,7 @@ /* $Id: testobsdrdr.c,v 1.28 2014/03/06 13:02:47 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2006-2014 Thomas Bernard + * (c) 2006-2017 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ @@ -118,7 +118,7 @@ main(int argc, char * * argv) printf("get_redirect_rule() failed\n"); else { - printf("\n%s:%d '%s' packets=%llu bytes=%llu\n", buf, (int)iport, desc, + printf("\n%s:%d '%s' packets=%" PRIu64 " bytes=%" PRIu64 "\n", buf, (int)iport, desc, packets, bytes); } diff --git a/miniupnpd/pf/testpfpinhole.c b/miniupnpd/pf/testpfpinhole.c index 8b68553..de3d4e0 100644 --- a/miniupnpd/pf/testpfpinhole.c +++ b/miniupnpd/pf/testpfpinhole.c @@ -2,7 +2,7 @@ /* vim: tabstop=4 shiftwidth=4 noexpandtab * MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2012-2016 Thomas Bernard + * (c) 2012-2017 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ @@ -49,7 +49,7 @@ static int print_pinhole(int uid) uid, rem_host, rem_port, int_client, int_port, proto, timestamp); printf(" desc='%s'\n", desc); - printf(" packets=%llu bytes=%llu\n", packets, bytes); + printf(" packets=%" PRIu64 " bytes=%" PRIu64 "\n", packets, bytes); } return r; } From da64fd85cbedae12d049ec3432e368c9b80c0793 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 13 Mar 2017 11:47:21 +0100 Subject: [PATCH 27/33] pass ext_if_name arg to add_pinhole() should fix #228 --- miniupnpd/Changelog.txt | 1 + miniupnpd/netfilter/iptpinhole.c | 3 ++- miniupnpd/pf/pfpinhole.c | 2 +- miniupnpd/upnppinhole.c | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/miniupnpd/Changelog.txt b/miniupnpd/Changelog.txt index f609457..7b469d3 100644 --- a/miniupnpd/Changelog.txt +++ b/miniupnpd/Changelog.txt @@ -3,6 +3,7 @@ $Id: Changelog.txt,v 1.430 2016/12/16 09:14:40 nanard Exp $ 2017/03/13: default to client address for AddPortMapping when is empty + pass ext_if_name to add_pinhole() 2016/12/23: Fix UDA-1.2.10 Man header empty or invalid diff --git a/miniupnpd/netfilter/iptpinhole.c b/miniupnpd/netfilter/iptpinhole.c index da37257..33d0f0e 100644 --- a/miniupnpd/netfilter/iptpinhole.c +++ b/miniupnpd/netfilter/iptpinhole.c @@ -1,7 +1,7 @@ /* $Id: iptpinhole.c,v 1.14 2015/02/10 15:01:03 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2012-2016 Thomas Bernard + * (c) 2012-2017 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ @@ -221,6 +221,7 @@ int add_pinhole(const char * ifname, if (proto) e->ipv6.flags |= IP6T_F_PROTO; + /* TODO: check if enforcing USE_IFNAME_IN_RULES is needed */ if(ifname) strncpy(e->ipv6.iniface, ifname, IFNAMSIZ); if(rem_host && (rem_host[0] != '\0')) { diff --git a/miniupnpd/pf/pfpinhole.c b/miniupnpd/pf/pfpinhole.c index 449a700..fd5d38f 100644 --- a/miniupnpd/pf/pfpinhole.c +++ b/miniupnpd/pf/pfpinhole.c @@ -2,7 +2,7 @@ /* vim: tabstop=4 shiftwidth=4 noexpandtab * MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2012-2016 Thomas Bernard + * (c) 2012-2017 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ diff --git a/miniupnpd/upnppinhole.c b/miniupnpd/upnppinhole.c index 75ecb77..9a4a131 100644 --- a/miniupnpd/upnppinhole.c +++ b/miniupnpd/upnppinhole.c @@ -1,7 +1,7 @@ /* $Id: upnppinhole.c,v 1.7 2014/12/09 09:13:53 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2006-2016 Thomas Bernard + * (c) 2006-2017 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ @@ -141,7 +141,7 @@ upnp_add_inboundpinhole(const char * raddr, return (r >= 0) ? 1 : r; } #if defined(USE_PF) || defined(USE_NETFILTER) - *uid = add_pinhole (0/*ext_if_name*/, raddr, rport, + *uid = add_pinhole (ext_if_name, raddr, rport, iaddr, iport, proto, desc, timestamp); return *uid >= 0 ? 1 : -1; #else From 0cc906169a2b6721914a33c4c4b9eb61267f8e3a Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 13 Mar 2017 13:01:00 +0100 Subject: [PATCH 28/33] use LinkLocal address for HTTP when needed should fix #229 should be tested... --- miniupnpd/minissdp.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/miniupnpd/minissdp.c b/miniupnpd/minissdp.c index 81a0714..5eb843f 100644 --- a/miniupnpd/minissdp.c +++ b/miniupnpd/minissdp.c @@ -1,7 +1,7 @@ /* $Id: minissdp.c,v 1.77 2015/08/26 07:36:52 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2006-2016 Thomas Bernard + * (c) 2006-2017 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ @@ -17,6 +17,10 @@ #include #include "config.h" +#if defined(ENABLE_IPV6) && defined(UPNP_STRICT) +#include +#endif /* defined(ENABLE_IPV6) && defined(UPNP_STRICT) */ + #include "upnpdescstrings.h" #include "miniupnpdpath.h" #include "upnphttp.h" @@ -116,6 +120,29 @@ AddMulticastMembershipIPv6(int s, unsigned int ifindex) } #endif + +#if defined(ENABLE_IPV6) && defined(UPNP_STRICT) +static int get_link_local_addr(unsigned scope_id, struct in6_addr * addr6) +{ + struct ifaddrs * ifap; + struct ifaddrs * ife; + if(getifaddrs(&ifap)<0) { + syslog(LOG_ERR, "getifaddrs: %m"); + return -1; + } + for(ife = ifap; ife != NULL; ife = ife->ifa_next) { + if(ife->ifa_addr == NULL) continue; + if(ife->ifa_addr->sa_family != AF_INET6) continue; + if(!IN6_IS_ADDR_LINKLOCAL(&(((const struct sockaddr_in6 *)ife->ifa_addr)->sin6_addr))) continue; + if(scope_id != if_nametoindex(ife->ifa_name)) continue; + memcpy(addr6, &(((const struct sockaddr_in6 *)ife->ifa_addr)->sin6_addr), sizeof(struct in6_addr)); + break; + } + freeifaddrs(ifap); + return 0; +} +#endif /* defined(ENABLE_IPV6) && defined(UPNP_STRICT) */ + /* Open and configure the socket listening for * SSDP udp packets sent on 239.255.255.250 port 1900 * SSDP v6 udp packets sent on FF02::C, or FF05::C, port 1900 */ @@ -962,10 +989,13 @@ ProcessSSDPData(int s, const char *bufr, int n, /* retrieve the IPv6 address which * will be used locally to reach sender */ memset(&addr6, 0, sizeof(addr6)); - if(get_src_for_route_to (sender, &addr6, &addr6_len, &index) < 0) { + if(IN6_IS_ADDR_LINKLOCAL(&(((struct sockaddr_in6 *)sender)->sin6_addr))) { + get_link_local_addr(((struct sockaddr_in6 *)sender)->sin6_scope_id, &addr6); + } else if(get_src_for_route_to (sender, &addr6, &addr6_len, &index) < 0) { syslog(LOG_WARNING, "get_src_for_route_to() failed, using %s", ipv6_addr_for_http_with_brackets); announced_host = ipv6_addr_for_http_with_brackets; - } else { + } + if(announced_host == NULL) { if(inet_ntop(AF_INET6, &addr6, announced_host_buf+1, sizeof(announced_host_buf) - 2)) { From b4ed41eae8f436485ed70111301e7786e863adaf Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 13 Mar 2017 13:07:22 +0100 Subject: [PATCH 29/33] add -w parameter to iptables for locking fixes #232 --- miniupnpd/netfilter/iptables_init.sh | 1 + miniupnpd/netfilter/iptables_init_and_clean.sh | 1 + miniupnpd/netfilter/iptables_removeall.sh | 1 + 3 files changed, 3 insertions(+) diff --git a/miniupnpd/netfilter/iptables_init.sh b/miniupnpd/netfilter/iptables_init.sh index 2088f13..297014f 100755 --- a/miniupnpd/netfilter/iptables_init.sh +++ b/miniupnpd/netfilter/iptables_init.sh @@ -1,6 +1,7 @@ #! /bin/sh # $Id: iptables_init.sh,v 1.5 2011/05/16 12:11:37 nanard Exp $ IPTABLES="`which iptables`" || exit 1 +IPTABLES="$IPTABLES -w" IP="`which ip`" || exit 1 #change this parameters : diff --git a/miniupnpd/netfilter/iptables_init_and_clean.sh b/miniupnpd/netfilter/iptables_init_and_clean.sh index 1783383..f61dff7 100755 --- a/miniupnpd/netfilter/iptables_init_and_clean.sh +++ b/miniupnpd/netfilter/iptables_init_and_clean.sh @@ -4,6 +4,7 @@ # Checks for state of filter before doing anything.. IPTABLES="`which iptables`" || exit 1 +IPTABLES="$IPTABLES -w" IP="`which ip`" || exit 1 #EXTIF=eth0 diff --git a/miniupnpd/netfilter/iptables_removeall.sh b/miniupnpd/netfilter/iptables_removeall.sh index 3cc8620..534ede8 100755 --- a/miniupnpd/netfilter/iptables_removeall.sh +++ b/miniupnpd/netfilter/iptables_removeall.sh @@ -1,6 +1,7 @@ #! /bin/sh # $Id: iptables_removeall.sh,v 1.5 2011/05/16 12:11:37 nanard Exp $ IPTABLES="`which iptables`" || exit 1 +IPTABLES="$IPTABLES -w" IP="`which ip`" || exit 1 #change this parameters : From d36853118e3c83448198a7cc85ab815b2d27dd3c Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 13 Mar 2017 14:34:16 +0100 Subject: [PATCH 30/33] connecthostport.c: fix compilation with -DNO_GETADDRINFO --- miniupnpc/Makefile | 4 ++-- miniupnpc/connecthostport.c | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/miniupnpc/Makefile b/miniupnpc/Makefile index 51a19f0..d1ad870 100644 --- a/miniupnpc/Makefile +++ b/miniupnpc/Makefile @@ -3,7 +3,7 @@ # http://miniupnp.free.fr/ # http://miniupnp.tuxfamily.org/ # https://github.com/miniupnp/miniupnp -# (c) 2005-2016 Thomas Bernard +# (c) 2005-2017 Thomas Bernard # to install use : # $ make DESTDIR=/tmp/dummylocation install # or @@ -48,7 +48,7 @@ CFLAGS += -D_XOPEN_SOURCE=600 endif endif #CFLAGS += -ansi -# -DNO_GETADDRINFO +#CFLAGS += -DNO_GETADDRINFO INSTALL = install SH = /bin/sh JAVA = java diff --git a/miniupnpc/connecthostport.c b/miniupnpc/connecthostport.c index e3c17d3..5185e13 100644 --- a/miniupnpc/connecthostport.c +++ b/miniupnpc/connecthostport.c @@ -1,7 +1,7 @@ /* $Id: connecthostport.c,v 1.15 2015/10/09 16:26:19 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard - * Copyright (c) 2010-2016 Thomas Bernard + * Copyright (c) 2010-2017 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. */ @@ -36,10 +36,8 @@ /* defining MINIUPNPC_IGNORE_EINTR enable the ignore of interruptions * during the connect() call */ #define MINIUPNPC_IGNORE_EINTR -#ifndef USE_GETHOSTBYNAME #include #include -#endif /* #ifndef USE_GETHOSTBYNAME */ #endif /* #else _WIN32 */ /* definition of PRINT_SOCKET_ERROR */ From e6ed3c5b8af83bb2e81f85d923da3e82abfbbc75 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 13 Mar 2017 15:33:38 +0100 Subject: [PATCH 31/33] do not stop discovery on sendto() failure --- miniupnpc/minissdpc.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/miniupnpc/minissdpc.c b/miniupnpc/minissdpc.c index 89b9d24..25640f3 100644 --- a/miniupnpc/minissdpc.c +++ b/miniupnpc/minissdpc.c @@ -503,6 +503,7 @@ ssdpDiscoverDevices(const char * const deviceTypes[], unsigned long _ttl = (unsigned long)ttl; #endif int linklocal = 1; + int sentok; if(error) *error = MINISSDPC_UNKNOWN_ERROR; @@ -613,14 +614,22 @@ ssdpDiscoverDevices(const char * const deviceTypes[], return NULL; } + if(ipv6) { + int mcastHops = ttl; + if(setsockopt(sudp, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastHops, sizeof(mcastHops)) < 0) + { + PRINT_SOCKET_ERROR("setsockopt(IPV6_MULTICAST_HOPS,...)"); + } + } else { #ifdef _WIN32 - if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_TTL, (const char *)&_ttl, sizeof(_ttl)) < 0) + if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_TTL, (const char *)&_ttl, sizeof(_ttl)) < 0) #else /* _WIN32 */ - if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) + if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) #endif /* _WIN32 */ - { - /* not a fatal error */ - PRINT_SOCKET_ERROR("setsockopt(IP_MULTICAST_TTL,...)"); + { + /* not a fatal error */ + PRINT_SOCKET_ERROR("setsockopt(IP_MULTICAST_TTL,...)"); + } } if(multicastif) @@ -705,6 +714,7 @@ ssdpDiscoverDevices(const char * const deviceTypes[], } /* receiving SSDP response packet */ for(deviceIndex = 0; deviceTypes[deviceIndex]; deviceIndex++) { + sentok = 0; /* sending the SSDP M-SEARCH packet */ n = snprintf(bufr, sizeof(bufr), MSearchMsgFmt, @@ -748,7 +758,8 @@ ssdpDiscoverDevices(const char * const deviceTypes[], if(error) *error = MINISSDPC_SOCKET_ERROR; PRINT_SOCKET_ERROR("sendto"); - break; + } else { + sentok = 1; } #else /* #ifdef NO_GETADDRINFO */ memset(&hints, 0, sizeof(hints)); @@ -780,19 +791,20 @@ ssdpDiscoverDevices(const char * const deviceTypes[], #endif PRINT_SOCKET_ERROR("sendto"); continue; + } else { + sentok = 1; } } freeaddrinfo(servinfo); - if(n < 0) { + if(!sentok) { if(error) *error = MINISSDPC_SOCKET_ERROR; - break; } #endif /* #ifdef NO_GETADDRINFO */ /* Waiting for SSDP REPLY packet to M-SEARCH * if searchalltypes is set, enter the loop only * when the last deviceType is reached */ - if(!searchalltypes || !deviceTypes[deviceIndex + 1]) do { + if((sentok && !searchalltypes) || !deviceTypes[deviceIndex + 1]) do { n = receivedata(sudp, bufr, sizeof(bufr), delay, &scope_id); if (n < 0) { /* error */ From 7c45f219e4b2c1397551e3261e37125108d94ebf Mon Sep 17 00:00:00 2001 From: Chris Lamb Date: Thu, 13 Apr 2017 20:08:51 +0100 Subject: [PATCH 32/33] Please make the build reproducible Whilst working on the Reproducible Builds effort [0], we noticed that miniupnpd could not be built reproducibly due to embedded timestamps. [0] https://reproducible-builds.org/ Signed-off-by: Chris Lamb --- miniupnpd/genconfig.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/miniupnpd/genconfig.sh b/miniupnpd/genconfig.sh index 1e0f0b7..d938a38 100755 --- a/miniupnpd/genconfig.sh +++ b/miniupnpd/genconfig.sh @@ -60,6 +60,10 @@ CONFIGFILE_FINAL="config.h" CONFIGMACRO="CONFIG_H_INCLUDED" MINIUPNPD_DATE=`date +"%Y%m%d"` +if [ -n "$SOURCE_DATE_EPOCH" ]; then + MINIUPNPD_DATE=`date --utc --date="@$SOURCE_DATE_EPOCH" +"%Y%m%d"` +fi + # Facility to syslog LOG_MINIUPNPD="LOG_DAEMON" From af5c091002038378100845d3602fcc7378c8db47 Mon Sep 17 00:00:00 2001 From: Matthieu Nottale Date: Fri, 2 Sep 2016 14:26:42 +0200 Subject: [PATCH 33/33] Send error logs to stderr. --- miniupnpc/connecthostport.c | 2 +- miniupnpc/minisoap.c | 2 +- miniupnpc/minissdpc.c | 2 +- miniupnpc/receivedata.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/miniupnpc/connecthostport.c b/miniupnpc/connecthostport.c index 5185e13..d28aaf5 100644 --- a/miniupnpc/connecthostport.c +++ b/miniupnpc/connecthostport.c @@ -42,7 +42,7 @@ /* definition of PRINT_SOCKET_ERROR */ #ifdef _WIN32 -#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError()); +#define PRINT_SOCKET_ERROR(x) fprintf(stderr, "Socket error: %s, %d\n", x, WSAGetLastError()); #else #define PRINT_SOCKET_ERROR(x) perror(x) #endif diff --git a/miniupnpc/minisoap.c b/miniupnpc/minisoap.c index 5c9a114..76225f4 100644 --- a/miniupnpc/minisoap.c +++ b/miniupnpc/minisoap.c @@ -25,7 +25,7 @@ #include #ifdef _WIN32 -#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError()); +#define PRINT_SOCKET_ERROR(x) fprintf(stderr, "Socket error: %s, %d\n", x, WSAGetLastError()); #else #define PRINT_SOCKET_ERROR(x) perror(x) #endif diff --git a/miniupnpc/minissdpc.c b/miniupnpc/minissdpc.c index 25640f3..8eee2e9 100644 --- a/miniupnpc/minissdpc.c +++ b/miniupnpc/minissdpc.c @@ -62,7 +62,7 @@ struct sockaddr_un { #endif #ifdef _WIN32 -#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError()); +#define PRINT_SOCKET_ERROR(x) fprintf(stderr, "Socket error: %s, %d\n", x, WSAGetLastError()); #else #define PRINT_SOCKET_ERROR(x) perror(x) #endif diff --git a/miniupnpc/receivedata.c b/miniupnpc/receivedata.c index ef85a3d..d003eb6 100644 --- a/miniupnpc/receivedata.c +++ b/miniupnpc/receivedata.c @@ -28,7 +28,7 @@ #endif /* _WIN32 */ #ifdef _WIN32 -#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError()); +#define PRINT_SOCKET_ERROR(x) fprintf(stderr, "Socket error: %s, %d\n", x, WSAGetLastError()); #else #define PRINT_SOCKET_ERROR(x) perror(x) #endif