X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/13772c3979cbed6883fddb5811da9b56fb16e179..ba0f0998d9e782714f1007ca3e812403e5a4d0f7:/slstatus.c diff --git a/slstatus.c b/slstatus.c index 8c65435..6a338f9 100644 --- a/slstatus.c +++ b/slstatus.c @@ -699,11 +699,11 @@ wifi_perc(const char *iface) fgets(buf, sizeof(buf), fp); fclose(fp); - datastart = strstr(buf, concat); - if (datastart != NULL) { - datastart = strstr(buf, ":"); - sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d", &perc); + if ((datastart = strstr(buf, concat)) == NULL) { + return smprintf("%s", UNKNOWN_STR); } + datastart = (datastart+(strlen(iface)+1)); + sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d", &perc); return smprintf("%d%%", perc); } @@ -717,7 +717,8 @@ wifi_essid(const char *iface) memset(&wreq, 0, sizeof(struct iwreq)); wreq.u.essid.length = IW_ESSID_MAX_SIZE+1; - sprintf(wreq.ifr_name, iface); + snprintf(wreq.ifr_name, sizeof(wreq.ifr_name), "%s", iface); + if (sockfd == -1) { warn("Failed to get ESSID for interface %s", iface); return smprintf("%s", UNKNOWN_STR); @@ -830,10 +831,6 @@ main(int argc, char *argv[]) printf("%s\n", status_string); } - /* - * subtract delay time spend in function - * calls from the actual global delay time - */ if ((UPDATE_INTERVAL - delay) <= 0) { delay = 0; continue;