miniupnpd/getifaddr.c: getifaddr_in6() only return IPv4 address when IPV6 disabled

see if it can help for issue #62
pcp/CheckAddress() is likely to need more changes.
This commit is contained in:
Thomas Bernard 2014-03-13 10:00:42 +01:00
parent d397d73628
commit 81fa1bcd57
2 changed files with 7 additions and 1 deletions

View File

@ -119,6 +119,8 @@ getifaddr(const char * ifname, char * buf, int len,
} }
#ifdef ENABLE_PCP #ifdef ENABLE_PCP
/* XXX I don't know if this function should return
* IPv4 or IPv6 if both are enabled... */
int getifaddr_in6(const char * ifname, struct in6_addr * addr){ int getifaddr_in6(const char * ifname, struct in6_addr * addr){
struct ifaddrs * ifap; struct ifaddrs * ifap;
struct ifaddrs * ife; struct ifaddrs * ife;
@ -157,6 +159,7 @@ int getifaddr_in6(const char * ifname, struct in6_addr * addr){
found = 1; found = 1;
break; break;
#ifdef ENABLE_IPV6
case AF_INET6: case AF_INET6:
if(!IN6_IS_ADDR_LOOPBACK(addr) if(!IN6_IS_ADDR_LOOPBACK(addr)
&& !IN6_IS_ADDR_LINKLOCAL(addr)) { && !IN6_IS_ADDR_LINKLOCAL(addr)) {
@ -164,12 +167,13 @@ int getifaddr_in6(const char * ifname, struct in6_addr * addr){
found = 1; found = 1;
} }
break; break;
#endif /* ENABLE_IPV6 */
} }
} }
freeifaddrs(ifap); freeifaddrs(ifap);
return (found ? 0 : -1); return (found ? 0 : -1);
} }
#endif #endif /* ENABLE_PCP */
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
int int

View File

@ -536,6 +536,7 @@ static int parsePCPOptions(void* pcp_buf, int* remainingSize,
static int CheckExternalAddress(pcp_info_t* pcp_msg_info) static int CheckExternalAddress(pcp_info_t* pcp_msg_info)
{ {
/* can contain a IPv4-mapped IPv6 address */
static struct in6_addr external_addr; static struct in6_addr external_addr;
if(use_ext_ip_addr) { if(use_ext_ip_addr) {
@ -554,6 +555,7 @@ static int CheckExternalAddress(pcp_info_t* pcp_msg_info)
pcp_msg_info->result_code = PCP_ERR_NETWORK_FAILURE; pcp_msg_info->result_code = PCP_ERR_NETWORK_FAILURE;
return -1; return -1;
} }
/* how do we know which address we need ? IPv6 or IPv4 ? */
if(getifaddr_in6(ext_if_name, &external_addr) < 0) { if(getifaddr_in6(ext_if_name, &external_addr) < 0) {
pcp_msg_info->result_code = PCP_ERR_NETWORK_FAILURE; pcp_msg_info->result_code = PCP_ERR_NETWORK_FAILURE;
return -1; return -1;