X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/7246dc4381c6c95454672a5c1aff65a02d6d3747..aced8326228ea3cf1673828a6e488b8f75108f45:/components/wifi.c?ds=sidebyside diff --git a/components/wifi.c b/components/wifi.c index 30b57ab..a02c277 100644 --- a/components/wifi.c +++ b/components/wifi.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#if defined(__linux__) #include #include #include @@ -14,7 +15,9 @@ const char * wifi_perc(const char *iface) { - int i, perc; + int i, cur; + float perc; + int total = 70; /* the max of /proc/net/wireless */ char *p, *datastart; char path[PATH_MAX]; char status[5]; @@ -50,9 +53,11 @@ wifi_perc(const char *iface) return NULL; datastart = (datastart+(strlen(iface)+1)); - sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d", &perc); + sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d", &cur); - return bprintf("%d", perc); + perc = (float)cur / total * 100.0; + + return bprintf("%.0f", perc); } const char * @@ -73,6 +78,7 @@ wifi_essid(const char *iface) wreq.u.essid.pointer = id; if (ioctl(sockfd,SIOCGIWESSID, &wreq) == -1) { warn("Failed to get ESSID for interface %s", iface); + close(sockfd); return NULL; } @@ -83,3 +89,4 @@ wifi_essid(const char *iface) else return id; } +#endif