func getifconfigs: get IPv6 address correctly

pull/37/head
YuQing 2019-09-26 10:00:02 +08:00
parent d366aa6492
commit 82eee4ddd0
1 changed files with 4 additions and 2 deletions

View File

@ -2021,6 +2021,7 @@ int getifconfigs(FastIFConfig *if_configs, const int max_count, int *count)
struct ifaddrs *ifc1; struct ifaddrs *ifc1;
FastIFConfig *config; FastIFConfig *config;
char *buff; char *buff;
void *sin_addr;
int buff_size; int buff_size;
int i; int i;
@ -2072,15 +2073,16 @@ int getifconfigs(FastIFConfig *if_configs, const int max_count, int *count)
{ {
buff = config->ipv4; buff = config->ipv4;
buff_size = sizeof(config->ipv4); buff_size = sizeof(config->ipv4);
sin_addr = &((struct sockaddr_in *)s)->sin_addr;
} }
else else
{ {
buff = config->ipv6; buff = config->ipv6;
buff_size = sizeof(config->ipv6); buff_size = sizeof(config->ipv6);
sin_addr = &((struct sockaddr_in6 *)s)->sin6_addr;
} }
if (inet_ntop(s->sa_family, &((struct sockaddr_in *)s)-> if (inet_ntop(s->sa_family, sin_addr, buff, buff_size) == NULL)
sin_addr, buff, buff_size) == NULL)
{ {
logWarning("file: "__FILE__", line: %d, " \ logWarning("file: "__FILE__", line: %d, " \
"call inet_ntop fail, " \ "call inet_ntop fail, " \