6 #include "netif_named.h"
9 #define NETIF_BASEDIR "/sys/class/net/"
11 void status_netif_named(char *ifname)
20 char *stfilename = NULL;
22 stfilename = malloc(sizeof(NETIF_BASEDIR) - 1 + strlen(ifname) + sizeof("/statistics/rx_bytes"));
24 strcpy(stfilename, NETIF_BASEDIR);
25 strcat(stfilename, ifname);
27 if (access(stfilename, F_OK))
29 //printf(" ^fg(grey)[%s] ", ifname);
33 strcat(stfilename, "/carrier");
34 stfile = open(stfilename, 0);
37 stlen = read(stfile, stline, sizeof(stline) - 1);
40 fputs("^fg(yellow)", stdout);
43 //fputs("^fg(red)", stdout);
48 strcpy(stfilename, NETIF_BASEDIR);
49 strcat(stfilename, ifname);
50 strcat(stfilename, "/statistics/rx_bytes");
51 stfile = open(stfilename, 0);
54 stlen = read(stfile, stline, sizeof(stline) - 1);
60 strcpy(stfilename, NETIF_BASEDIR);
61 strcat(stfilename, ifname);
62 strcat(stfilename, "/statistics/tx_bytes");
63 stfile = open(stfilename, 0);
66 stlen = read(stfile, stline, sizeof(stline) - 1);
69 ifsum += atof(stline);
72 for(ifsumpower = 0; ifsum >= 1024.0; ifsumpower++)
75 printf(" %s: %.*f %c ", ifname, ifsumpower ? ifsumpower - 1 : ifsumpower, ifsum, powertochar(ifsumpower));