upnpsoap.c: comment and improve GetExternalIPAddress()

GetExternalIPAddress returns empty string when the External IP address can
not be retrieved.
This commit is contained in:
Thomas Bernard 2021-03-31 09:43:28 +02:00
parent 20ee72f9c8
commit 3a87be33e7
No known key found for this signature in database
GPG Key ID: DB511043A31ACAAF
2 changed files with 17 additions and 4 deletions

View File

@ -1,5 +1,9 @@
$Id: Changelog.txt,v 1.473 2020/12/20 18:06:36 nanard Exp $ $Id: Changelog.txt,v 1.473 2020/12/20 18:06:36 nanard Exp $
2020/03/31:
GetExternalIPAddress returns empty string when the External IP address can
not be retrieved.
VERSION 2.2.1 : released on 2020/12/20 VERSION 2.2.1 : released on 2020/12/20
(only minor build corrections) (only minor build corrections)

View File

@ -2,7 +2,7 @@
/* vim: tabstop=4 shiftwidth=4 noexpandtab /* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project * MiniUPnP project
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* (c) 2006-2020 Thomas Bernard * (c) 2006-2021 Thomas Bernard
* This software is subject to the conditions detailed * This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */ * in the LICENCE file provided within the distribution */
@ -345,15 +345,15 @@ GetExternalIPAddress(struct upnphttp * h, const char * action, const char * ns)
{ {
syslog(LOG_ERR, "Failed to get ip address for interface %s", syslog(LOG_ERR, "Failed to get ip address for interface %s",
ext_if_name); ext_if_name);
strncpy(ext_ip_addr, "0.0.0.0", INET_ADDRSTRLEN); ext_ip_addr[0] = '\0';
} else if (addr_is_reserved(&addr)) { } else if (addr_is_reserved(&addr)) {
syslog(LOG_NOTICE, "private/reserved address %s is not suitable for external IP", ext_ip_addr); syslog(LOG_NOTICE, "private/reserved address %s is not suitable for external IP", ext_ip_addr);
strncpy(ext_ip_addr, "0.0.0.0", INET_ADDRSTRLEN); ext_ip_addr[0] = '\0';
} }
} }
#else #else
struct lan_addr_s * lan_addr; struct lan_addr_s * lan_addr;
strncpy(ext_ip_addr, "0.0.0.0", INET_ADDRSTRLEN); ext_ip_addr[0] = '\0';
for(lan_addr = lan_addrs.lh_first; lan_addr != NULL; lan_addr = lan_addr->list.le_next) for(lan_addr = lan_addrs.lh_first; lan_addr != NULL; lan_addr = lan_addr->list.le_next)
{ {
if( (h->clientaddr.s_addr & lan_addr->mask.s_addr) if( (h->clientaddr.s_addr & lan_addr->mask.s_addr)
@ -364,6 +364,15 @@ GetExternalIPAddress(struct upnphttp * h, const char * action, const char * ns)
} }
} }
#endif #endif
/* WANIPConnection:2 Service 2.3.13 :
* When the external IP address could not be retrieved by the gateway
* (for example, because the interface is down or because there was a
* failure in the last connection setup attempt),
* then the ExternalIPAddress MUST be equal to the empty string.
*
* There is no precise requirement on how theses cases must be handled
* in IGDv1 specifications, but ExternalIPAddress default value is empty
* string. */
if (strcmp(ext_ip_addr, "0.0.0.0") == 0) if (strcmp(ext_ip_addr, "0.0.0.0") == 0)
ext_ip_addr[0] = '\0'; ext_ip_addr[0] = '\0';
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,