]> git.itanic.dy.fi Git - rrdd/commitdiff
parser: Use long long when parsing net stats
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 6 Apr 2011 14:57:49 +0000 (17:57 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 6 Apr 2011 15:02:31 +0000 (18:02 +0300)
It might be sufficient to use unsigned long in 32 bit environment, but
in order to avoid any issues with overflows, long long is safer.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
parser.c

index 65f264b167baea5bb59529779965b8c347d8daa7..10bcdbcc9e9bb62a5d4ad52bc35cc890a0159ded 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -177,10 +177,10 @@ int script_parser(char *rrd_data, void *parser_data)
 }
 
 struct iface_stats {
-       long int rx_bytes;
-       long int rx_packets;
-       long int tx_bytes;
-       long int tx_packets;
+       long long rx_bytes;
+       long long rx_packets;
+       long long tx_bytes;
+       long long tx_packets;
 };
 
 #define PROC_NETDEV    "/proc/net/dev"
@@ -221,7 +221,7 @@ static int get_iface_stats(const char *iface, struct iface_stats *stat)
                stat->tx_bytes          = dec_to_longlong(str, &str);
                stat->tx_packets        = dec_to_longlong(str, &str);
 
-               pr_info("rx_b %ld rx_p %ld tx_b %ld tx_p %ld\n",
+               pr_info("rx_b %lld rx_p %lld tx_b %lld tx_p %lld\n",
                        stat->rx_bytes, stat->rx_packets,
                        stat->tx_bytes, stat->tx_packets);
 
@@ -244,7 +244,7 @@ int netstats_parser(char *rrd_data, void *parser_data)
                ret = get_iface_stats(*iface_name, &stat);
 
                if (!ret) {
-                       ret = snprintf(rrd_data, max_str, "%ld:%ld:%ld:%ld",
+                       ret = snprintf(rrd_data, max_str, "%lld:%lld:%lld:%lld",
                                stat.rx_bytes, stat.rx_packets,
                                stat.tx_bytes, stat.tx_packets);
                } else {