aboutsummaryrefslogtreecommitdiff
path: root/networking/rxtxrpt.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/rxtxrpt.c')
-rw-r--r--networking/rxtxrpt.c124
1 files changed, 119 insertions, 5 deletions
diff --git a/networking/rxtxrpt.c b/networking/rxtxrpt.c
index 609cedb..98e94f7 100644
--- a/networking/rxtxrpt.c
+++ b/networking/rxtxrpt.c
@@ -12,11 +12,15 @@ table if it has changed.
#include "libbb.h"
+#define NEW_FORMAT
+
#define DEV_FILE "/proc/net/dev"
#define IF_INET6_FILE "/proc/net/if_inet6"
#define IPV6_ROUTE_FILE "/proc/net/ipv6_route"
#define SUFFIX ".new"
+#define DBQ(str) "\"" #str "\""
+
int do_atlas= 0;
static int rpt_rxtx(void);
@@ -28,12 +32,11 @@ static void report_err(const char *fmt, ...);
int rxtxrpt_main(int argc, char *argv[])
{
int r, need_report;
- unsigned opt;
char *opt_atlas, *cache_name;
opt_atlas= NULL;
opt_complementary= NULL;
- opt= getopt32(argv, "A:", &opt_atlas);
+ getopt32(argv, "A:", &opt_atlas);
do_atlas= (opt_atlas != NULL);
@@ -46,13 +49,31 @@ int rxtxrpt_main(int argc, char *argv[])
if (do_atlas)
{
+#ifdef NEW_FORMAT
+ printf("RESULT { " DBQ(id) ": " DBQ(%s) ", ", opt_atlas);
+ printf(DBQ(fw) ": %d, ", get_atlas_fw_version());
+ printf(DBQ(time) ": %lld, ", (long long)time(NULL));
+ printf(DBQ(lts) ": %d, ", get_timesync());
+ printf(DBQ(interfaces) ": [");
+#else /* !NEW_FORMWAT */
printf("%s %lu ", opt_atlas, time(NULL));
+#endif /* NEW_FORMWAT */
}
r= rpt_rxtx();
if (r != 0)
return r;
+ if (do_atlas)
+ {
+#ifdef NEW_FORMAT
+ printf(" ] }\n");
+#else /* !NEW_FORMAT */
+ printf("\n");
+
+#endif /* NEW_FORMAT */
+ }
+
if (cache_name)
{
r= setup_ipv6_rpt(cache_name, &need_report);
@@ -66,12 +87,104 @@ int rxtxrpt_main(int argc, char *argv[])
}
}
- if (do_atlas)
- printf("\n");
-
return 0;
}
+#ifdef NEW_FORMAT
+static int rpt_rxtx(void)
+{
+ int i;
+ unsigned long long bytes_recv, pkt_recv, errors_recv, dropped_recv,
+ fifo_recv, framing_recv, compressed_recv, multicast_recv,
+ bytes_sent, pkt_sent, errors_sent, dropped_sent,
+ fifo_sent, collisions_sent, carr_lost_sent, compressed_sent;
+ char *cp, *infname;
+ FILE *file;
+ char buf[256];
+
+ file= fopen(DEV_FILE, "r");
+ if (!file)
+ {
+ report_err("unable to open '%s'", DEV_FILE);
+ return 1;
+ }
+
+ /* Skip two lines */
+ if (fgets(buf, sizeof(buf), file) == NULL ||
+ fgets(buf, sizeof(buf), file) == NULL)
+ {
+ report_err("unable to read from '%s'", DEV_FILE);
+ fclose(file);
+ return 1;
+ }
+
+ for (i= 0; i<4; i++)
+ {
+ if (fgets(buf, sizeof(buf), file) == NULL)
+ {
+ if (feof(file))
+ break;
+ report_err("unable to read from '%s'", DEV_FILE);
+ fclose(file);
+ return 1;
+ }
+
+ cp= buf;
+
+ /* Skip leading white space */
+ while (*cp == ' ')
+ cp++;
+ infname= cp;
+ cp= strchr(cp, ':');
+ if (cp == NULL)
+ {
+ report_err("format error in '%s'", DEV_FILE);
+ fclose(file);
+ return 1;
+ }
+
+ /* Get all the values */
+ if (sscanf(cp+1, "%llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu",
+ &bytes_recv, &pkt_recv, &errors_recv, &dropped_recv,
+ &fifo_recv, &framing_recv, &compressed_recv,
+ &multicast_recv,
+ &bytes_sent, &pkt_sent, &errors_sent, &dropped_sent,
+ &fifo_sent, &collisions_sent, &carr_lost_sent,
+ &compressed_sent) != 16)
+ {
+ report_err("format error in '%s'", DEV_FILE);
+ fclose(file);
+ return 1;
+ }
+
+ *cp= '\0';
+
+ printf("%s { " DBQ(name) ": " DBQ(%s) ", ",
+ i == 0 ? "" : ",", infname);
+
+ printf(DBQ(bytes_recv) ": %llu, ", bytes_recv);
+ printf(DBQ(pkt_recv) ": %llu, ", pkt_recv);
+ printf(DBQ(errors_recv) ": %llu, ", errors_recv);
+ printf(DBQ(dropped_recv) ": %llu, ", dropped_recv);
+ printf(DBQ(fifo_recv) ": %llu, ", fifo_recv);
+ printf(DBQ(framing_recv) ": %llu, ", framing_recv);
+ printf(DBQ(compressed_recv) ": %llu, ", compressed_recv);
+ printf(DBQ(multicast_recv) ": %llu, ", multicast_recv);
+ printf(DBQ(bytes_sent) ": %llu, ", bytes_sent);
+ printf(DBQ(pkt_sent) ": %llu, ", pkt_sent);
+ printf(DBQ(errors_sent) ": %llu, ", errors_sent);
+ printf(DBQ(dropped_sent) ": %llu, ", dropped_sent);
+ printf(DBQ(fifo_sent) ": %llu, ", fifo_sent);
+ printf(DBQ(collisions_sent) ": %llu, ", collisions_sent);
+ printf(DBQ(carr_lost_sent) ": %llu, ", carr_lost_sent);
+ printf(DBQ(compressed_sent) ": %llu", compressed_sent);
+ printf(" }");
+ }
+ fclose(file);
+
+ return 0;
+}
+#else /* !NEW_FORMAT */
static int rpt_rxtx(void)
{
int i;
@@ -120,6 +233,7 @@ static int rpt_rxtx(void)
return 0;
}
+#endif /* NEW_FORMAT */
static int setup_ipv6_rpt(char *cache_name, int *need_report)
{