解决网卡中的获取子网掩码接口段错误

This commit is contained in:
szm-min 2024-04-28 17:28:06 +08:00
parent 573506a17d
commit 822a8960ea
1 changed files with 17 additions and 15 deletions

View File

@ -835,19 +835,21 @@ int kdk_nc_get_carrier(char *nc)
char *kdk_nc_get_duplex(char *nc)
{
char path[1024] = {0}, real_path[1024];
char path[1024] = {0};
char res[1024] = {0};
char *result = NULL;
sprintf(path, "/sys/class/net/%s/duplex", nc);
if (NULL == realpath(path, real_path))
return NULL;
FILE *fp = fopen(real_path, "r");
// if (NULL == realpath(path, real_path))
// return NULL;
FILE *fp = fopen(path, "r");
if(NULL == fp)
return NULL;
fgets(res, 1024, fp);
strstripspace(res);
if(strlen(res) != 0)
{
strstripspace(res);
result = strdup(res);
}
fclose(fp);
return result;
}
@ -956,12 +958,12 @@ char *kdk_nc_get_broadAddr(const char *eth_name, const char *address)
int ret = 0;
struct nl_cache *addr_cache;
struct rtnl_link *link;
char *ip = (char *)malloc(sizeof(char) * 32);
char *ip = (char *)malloc(sizeof(char) * 256);
if(!ip)
{
return NULL;
}
memset(ip, 0, 32);
memset(ip, 0, 256);
strcpy(ip, address);
struct nl_sock *sk = nl_socket_alloc();
@ -1024,12 +1026,12 @@ char *kdk_nc_get_netmask(const char *eth_name, const char *addr)
int ret = 0;
struct nl_cache *addr_cache;
struct rtnl_link *link;
char *ip = (char *)malloc(sizeof(addr) + 1);
char *ip = (char *)malloc(sizeof(char) * 512);
if(!ip)
{
return NULL;
}
memset(ip, 0, sizeof(addr) + 1);
memset(ip, 0, 512);
strcpy(ip, addr);
char *netmask = NULL;
@ -1062,12 +1064,12 @@ char *kdk_nc_get_netmask(const char *eth_name, const char *addr)
free(ip);
if(ctx.netmask)
{
netmask = (char *)malloc(sizeof(char) * 64);
netmask = (char *)malloc(sizeof(char) * 256);
if(!netmask)
{
return NULL;
}
memset(netmask, 0, 64);
memset(netmask, 0, 256);
strcpy(netmask, ctx.netmask);
free(ctx.netmask);
}
@ -1091,12 +1093,12 @@ int kdk_nc_get_mask_length(int type, const char *eth_name, const char *addr)
int ret = 0;
struct nl_cache *addr_cache;
struct rtnl_link *link;
char *ip = (char *)malloc(sizeof(char) * 32);
char *ip = (char *)malloc(sizeof(char) * 256);
if(!ip)
{
return -1;
}
memset(ip, 0, 32);
memset(ip, 0, 256);
strcpy(ip, addr);
struct nl_sock *sk = nl_socket_alloc();
@ -1593,12 +1595,12 @@ int kdk_nc_get_scope(const char *eth_name, const char *addr)
int ret = 0;
struct nl_cache *addr_cache;
struct rtnl_link *link;
char *ip = (char *)malloc(sizeof(char) * 32);
char *ip = (char *)malloc(sizeof(char) * 256);
if(!ip)
{
return -1;
}
memset(ip, 0, 32);
memset(ip, 0, 256);
strcpy(ip, addr);
struct nl_sock *sk = nl_socket_alloc();