网卡ipv6地址不存在kdk_nc_get_ipv6接口返回NULL

This commit is contained in:
sunzhen 2024-06-05 11:13:46 +08:00
parent e21a33a579
commit 9cba84f025
1 changed files with 29 additions and 24 deletions

View File

@ -433,32 +433,35 @@ char **_get_nc_cfg(const char *nc, enum cardcfg cfg)
}
}
res = malloc(sizeof(char *));
if (!res)
if(strlen(addr) != 0)
{
klog_err("内存申请失败:%s\n", strerror(errno));
close(sfd);
res = malloc(sizeof(char *));
if (!res)
{
klog_err("内存申请失败:%s\n", strerror(errno));
close(sfd);
freeifaddrs(ifap);
return NULL;
}
res[0] = malloc(sizeof(char) * INET6_ADDRSTRLEN);
if (!res[0])
{
free(res);
klog_err("内存申请失败:%s\n", strerror(errno));
close(sfd);
freeifaddrs(ifap);
return NULL;
}
int i = 0;
while (addr[i] != '%' && addr[i] != '\0')
i++;
addr[i] = '\0';
sprintf(res[0], "%s", addr);
freeifaddrs(ifap);
return NULL;
}
res[0] = malloc(sizeof(char) * INET6_ADDRSTRLEN);
if (!res[0])
{
free(res);
klog_err("内存申请失败:%s\n", strerror(errno));
close(sfd);
freeifaddrs(ifap);
return NULL;
}
int i = 0;
while (addr[i] != '%' && addr[i] != '\0')
i++;
addr[i] = '\0';
sprintf(res[0], "%s", addr);
freeifaddrs(ifap);
}
break;
default:
@ -528,10 +531,12 @@ char *kdk_nc_get_private_ipv6(const char *nc)
if (!nc)
return NULL;
char *ipv6 = NULL;
char **ipv6list = _get_nc_cfg(nc, NCCFG_IPv6);
if (!ipv6list)
return NULL;
char *ipv6 = ipv6list[0];
ipv6 = ipv6list[0];
free(ipv6list);
return ipv6;
}