X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/06d4447f03669b72a885a997b666e4cbcc6b5ed1..74c4f4ebdae8a12fc95840954dde574692234b01:/components/netspeeds.c?ds=sidebyside diff --git a/components/netspeeds.c b/components/netspeeds.c index bdaf420..32e78d6 100644 --- a/components/netspeeds.c +++ b/components/netspeeds.c @@ -17,14 +17,17 @@ oldrxbytes = rxbytes; - snprintf(path, sizeof(path), - "/sys/class/net/%s/statistics/rx_bytes", interface); + if (esnprintf(path, sizeof(path), + "/sys/class/net/%s/statistics/rx_bytes", + interface) < 0) { + return NULL; + } if (pscanf(path, "%llu", &rxbytes) != 1) { return NULL; } - return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) / - interval * 1000) : NULL; + return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) * + 1000 / interval) : NULL; } const char * @@ -37,14 +40,17 @@ oldtxbytes = txbytes; - snprintf(path, sizeof(path), - "/sys/class/net/%s/statistics/tx_bytes", interface); + if (esnprintf(path, sizeof(path), + "/sys/class/net/%s/statistics/tx_bytes", + interface) < 0) { + return NULL; + } if (pscanf(path, "%llu", &txbytes) != 1) { return NULL; } - return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) / - interval * 1000) : NULL; + return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) * + 1000 / interval) : NULL; } #elif defined(__OpenBSD__) #include @@ -61,7 +67,7 @@ uint64_t oldrxbytes; static uint64_t rxbytes = 0; extern const unsigned int interval; - char if_ok = 0; + int if_ok = 0; oldrxbytes = rxbytes; @@ -82,8 +88,8 @@ return NULL; } - return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) / - interval * 1000) : NULL; + return oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) * + 1000 / interval) : NULL; } const char * @@ -94,7 +100,7 @@ uint64_t oldtxbytes; static uint64_t txbytes = 0; extern const unsigned int interval; - char if_ok = 0; + int if_ok = 0; oldtxbytes = txbytes; @@ -115,7 +121,7 @@ return NULL; } - return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) / - interval * 1000) : NULL; + return oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) * + 1000 / interval) : NULL; } #endif