commit bb21f5158a463cfad0c0640a1a87fb5d29026362
parent 3d4332787af6f26808e6f27aaae14e1ebcb47437
Author: sin <sin@2f30.org>
Date: Mon, 22 Feb 2016 14:14:49 +0000
Use uint64_t where applicable
Diffstat:
M | sbm.c | | | 33 | ++++++++++++++++++++------------- |
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/sbm.c b/sbm.c
@@ -31,6 +31,7 @@
#include <errno.h>
#include <ifaddrs.h>
#include <limits.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -77,8 +78,8 @@ scan(char *ifname)
#ifdef __linux__
void
-sample(char *ifname, unsigned long long *rxbytes, unsigned long long *txbytes,
- unsigned long long *rxpps, unsigned long long *txpps)
+sample(char *ifname, uint64_t *rxbytes, uint64_t *txbytes,
+ uint64_t *rxpps, uint64_t *txpps)
{
struct ifaddrs *ifas, *ifa;
struct rtnl_link_stats *stats = NULL;
@@ -105,8 +106,8 @@ sample(char *ifname, unsigned long long *rxbytes, unsigned long long *txbytes,
}
#else
void
-sample(char *ifname, unsigned long long *rxbytes, unsigned long long *txbytes,
- unsigned long long *rxpps, unsigned long long *txpps)
+sample(char *ifname, uint64_t *rxbytes, uint64_t *txbytes,
+ uint64_t *rxpps, uint64_t *txpps)
{
int mib[6];
char *buf, *next;
@@ -152,7 +153,7 @@ sample(char *ifname, unsigned long long *rxbytes, unsigned long long *txbytes,
#endif
void
-scale(char **suffix, unsigned long long *bits)
+scale(char **suffix, uint64_t *bits)
{
static char *suffixes[] = { "bps", "Kbps", "Mbps" };
@@ -167,15 +168,21 @@ scale(char **suffix, unsigned long long *bits)
}
void
-print(char *ifname, unsigned long long rxbits, unsigned long long txbits,
- unsigned long long rxpps, unsigned long long txpps)
+print(char *ifname, uint64_t rxbits, uint64_t txbits,
+ uint64_t rxpps, uint64_t txpps)
{
char *rxsuffix, *txsuffix;
scale(&rxsuffix, &rxbits);
scale(&txsuffix, &txbits);
- printf("%s: down %lld %s up %lld %s rxpps %lld txpps %lld\n",
- ifname, rxbits, rxsuffix, txbits, txsuffix, rxpps, txpps);
+ printf("%s: down %llu %s up %llu %s rxpps %llu txpps %llu\n",
+ ifname,
+ (unsigned long long)rxbits,
+ rxsuffix,
+ (unsigned long long)txbits,
+ txsuffix,
+ (unsigned long long)rxpps,
+ (unsigned long long)txpps);
}
int
@@ -207,10 +214,10 @@ void
loop(char *ifname, long count, struct timeval *delay)
{
struct timeval old, now, diff;
- unsigned long long oldrxbytes, rxbytes, diffrxbits;
- unsigned long long oldtxbytes, txbytes, difftxbits;
- unsigned long long oldrxpps, rxpps, diffrxpps;
- unsigned long long oldtxpps, txpps, difftxpps;
+ uint64_t oldrxbytes, rxbytes, diffrxbits;
+ uint64_t oldtxbytes, txbytes, difftxbits;
+ uint64_t oldrxpps, rxpps, diffrxpps;
+ uint64_t oldtxpps, txpps, difftxpps;
long n = 0;
clock_gettime_tv(CLOCK_MONOTONIC, &old);