From 822a8960eaaaa64818a7c5c5c2c780782f5c8c60 Mon Sep 17 00:00:00 2001 From: szm-min Date: Sun, 28 Apr 2024 17:28:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=BD=91=E5=8D=A1=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E8=8E=B7=E5=8F=96=E5=AD=90=E7=BD=91=E6=8E=A9=E7=A0=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=AE=B5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hardware/libkync.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/hardware/libkync.c b/src/hardware/libkync.c index 0b88b0b..3f9029b 100644 --- a/src/hardware/libkync.c +++ b/src/hardware/libkync.c @@ -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();