Xinqi Bao's Git
projects
/
slstatus.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
Update README
[slstatus.git]
/
components
/
netspeeds.c
diff --git
a/components/netspeeds.c
b/components/netspeeds.c
index
6adc3ea
..
0029177
100644
(file)
--- a/
components/netspeeds.c
+++ b/
components/netspeeds.c
@@
-10,8
+10,8
@@
const char *
netspeed_rx(const char *interface)
{
const char *
netspeed_rx(const char *interface)
{
- uint
64
_t oldrxbytes;
- static uint
64_t rxbytes = 0
;
+ uint
max
_t oldrxbytes;
+ static uint
max_t rxbytes
;
extern const unsigned int interval;
char path[PATH_MAX];
extern const unsigned int interval;
char path[PATH_MAX];
@@
-22,19
+22,22
@@
interface) < 0) {
return NULL;
}
interface) < 0) {
return NULL;
}
- if (pscanf(path, "%llu", &rxbytes) != 1) {
+ if (pscanf(path, "%ju", &rxbytes) != 1) {
+ return NULL;
+ }
+ if (oldrxbytes == 0) {
return NULL;
}
return NULL;
}
- return
oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) /
-
interval * 1000) : NULL
;
+ return
fmt_human((rxbytes - oldrxbytes) * 1000 / interval,
+
1024)
;
}
const char *
netspeed_tx(const char *interface)
{
}
const char *
netspeed_tx(const char *interface)
{
- uint
64
_t oldtxbytes;
- static uint
64_t txbytes = 0
;
+ uint
max
_t oldtxbytes;
+ static uint
max_t txbytes
;
extern const unsigned int interval;
char path[PATH_MAX];
extern const unsigned int interval;
char path[PATH_MAX];
@@
-45,14
+48,17
@@
interface) < 0) {
return NULL;
}
interface) < 0) {
return NULL;
}
- if (pscanf(path, "%llu", &txbytes) != 1) {
+ if (pscanf(path, "%ju", &txbytes) != 1) {
+ return NULL;
+ }
+ if (oldtxbytes == 0) {
return NULL;
}
return NULL;
}
- return
oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) /
-
interval * 1000) : NULL
;
+ return
fmt_human((txbytes - oldtxbytes) * 1000 / interval,
+
1024)
;
}
}
-#elif defined(__OpenBSD__)
+#elif defined(__OpenBSD__)
| defined(__FreeBSD__)
#include <string.h>
#include <ifaddrs.h>
#include <sys/types.h>
#include <string.h>
#include <ifaddrs.h>
#include <sys/types.h>
@@
-64,8
+70,8
@@
{
struct ifaddrs *ifal, *ifa;
struct if_data *ifd;
{
struct ifaddrs *ifal, *ifa;
struct if_data *ifd;
- uint
64
_t oldrxbytes;
- static uint
64_t rxbytes = 0
;
+ uint
max
_t oldrxbytes;
+ static uint
max_t rxbytes
;
extern const unsigned int interval;
int if_ok = 0;
extern const unsigned int interval;
int if_ok = 0;
@@
-87,9
+93,12
@@
warn("reading 'if_data' failed");
return NULL;
}
warn("reading 'if_data' failed");
return NULL;
}
+ if (oldrxbytes == 0) {
+ return NULL;
+ }
- return
oldrxbytes ? fmt_scaled((rxbytes - oldrxbytes) /
-
interval * 1000) : NULL
;
+ return
fmt_human((rxbytes - oldrxbytes) * 1000 / interval,
+
1024)
;
}
const char *
}
const char *
@@
-97,8
+106,8
@@
{
struct ifaddrs *ifal, *ifa;
struct if_data *ifd;
{
struct ifaddrs *ifal, *ifa;
struct if_data *ifd;
- uint
64
_t oldtxbytes;
- static uint
64_t txbytes = 0
;
+ uint
max
_t oldtxbytes;
+ static uint
max_t txbytes
;
extern const unsigned int interval;
int if_ok = 0;
extern const unsigned int interval;
int if_ok = 0;
@@
-120,8
+129,11
@@
warn("reading 'if_data' failed");
return NULL;
}
warn("reading 'if_data' failed");
return NULL;
}
+ if (oldtxbytes == 0) {
+ return NULL;
+ }
- return
oldtxbytes ? fmt_scaled((txbytes - oldtxbytes) /
-
interval * 1000) : NULL
;
+ return
fmt_human((txbytes - oldtxbytes) * 1000 / interval,
+
1024)
;
}
#endif
}
#endif