6 #include "status/netif.h"
11 #define NETIF_BASEDIR "/sys/class/net/"
15 void status_netif(char *ifname)
28 ifpathlen = sizeof(NETIF_BASEDIR) - 1 + strlen(ifname);
29 if (ifpathlen + 1 + sizeof("/statistics/rx_bytes") >= sizeof(ifpath)) {
30 statusError("status_netif",
31 "ifpath buffer too small",
35 strcpy(ifpath, NETIF_BASEDIR);
36 strcat(ifpath, ifname);
39 /* Is the interface up? */
40 if (access(ifpath, F_OK)) {
41 //printf(" ^fg(grey)[%s] ", ifname);
46 strcpy(&ifpath[ifpathlen], "/carrier");
47 stlen = fileRead(stline, sizeof(stline), ifpath);
49 if (stline[0] == '1') {
50 fputs("^fg(yellow)", stdout);
52 //fputs("^fg(red)", stdout);
59 strcpy(&ifpath[ifpathlen], "/statistics/rx_bytes");
60 stlen = fileRead(stline, sizeof(stline), ifpath);
65 strcpy(&ifpath[ifpathlen], "/statistics/tx_bytes");
66 stlen = fileRead(stline, sizeof(stline), ifpath);
68 ifsum += atof(stline);
72 for(ifsumpower = 0; ifsum >= 1024.0; ifsumpower++) {
76 printf(" %s: %.*f %c ", ifname,
77 ifsumpower ? ifsumpower - 1 : ifsumpower,
79 powerToChar(ifsumpower));