fix GetExternalIPAddress()
a bug was introduced by
may fix
/* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
- * (c) 2006-2019 Thomas Bernard
+ * (c) 2006-2020 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@@ -332,20 +332,24 @@ GetExternalIPAddress(struct upnphttp * h, const char * action, const char * ns)
* There is usually no NAT with IPv6 */
#ifndef MULTIPLE_EXTERNAL_IP
- struct in_addr addr;
if(use_ext_ip_addr)
{
strncpy(ext_ip_addr, use_ext_ip_addr, INET_ADDRSTRLEN);
ext_ip_addr[INET_ADDRSTRLEN - 1] = '\0';
}
- else if(getifaddr(ext_if_name, ext_ip_addr, INET_ADDRSTRLEN, &addr, NULL) < 0)
+ else
+ {
+ struct in_addr addr;
+ if(getifaddr(ext_if_name, ext_ip_addr, INET_ADDRSTRLEN, &addr, NULL) < 0)
{
syslog(LOG_ERR, "Failed to get ip address for interface %s",
ext_if_name);
strncpy(ext_ip_addr, "0.0.0.0", INET_ADDRSTRLEN);
- }
- 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);
strncpy(ext_ip_addr, "0.0.0.0", INET_ADDRSTRLEN);
+ }
+ }
#else
struct lan_addr_s * lan_addr;
strncpy(ext_ip_addr, "0.0.0.0", INET_ADDRSTRLEN);
