diff --git a/src/linux.cc b/src/linux.cc index 00c343e2..5b5a5404 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -575,10 +575,11 @@ int update_net_stats(void) FILE *file; char v6addr[32]; char devname[21]; + unsigned int netmask; struct net_stat *ns; struct v6addr *lastv6; if ((file = fopen(PROCDIR"/net/if_inet6", "r")) != NULL) { - while (fscanf(file, "%32s %*02x %*02x %*02x %*02x %20s\n", v6addr, devname) != EOF) { + while (fscanf(file, "%32s %*02x %02x %*02x %*02x %20s\n", v6addr, &netmask, devname) != EOF) { ns = get_net_stat(devname, NULL, NULL); if(ns->v6addrs == NULL) { lastv6 = (struct v6addr *) malloc(sizeof(struct v6addr)); @@ -590,6 +591,7 @@ int update_net_stats(void) lastv6 = lastv6->next; } strncpy(lastv6->addr, v6addr, 32); + lastv6->netmask = netmask; lastv6->next = NULL; } } diff --git a/src/net_stat.cc b/src/net_stat.cc index 42e88331..7f46a9e7 100644 --- a/src/net_stat.cc +++ b/src/net_stat.cc @@ -90,10 +90,24 @@ struct net_stat *get_net_stat(const char *dev, void *free_at_crash1, void *free_ void parse_net_stat_arg(struct text_object *obj, const char *arg, void *free_at_crash) { + bool shownetmask = false; + char dev[21]; //a netdev can only be 20 chars long + int i=0; + if (!arg) arg = DEFAULTNETDEV; - obj->data.opaque = get_net_stat(arg, obj, free_at_crash); + if (*arg == '-') { //there are flags + for(i=1; arg[i] != ' ' && arg[i] != 0; i++) { + if(arg[i]=='n') shownetmask = true; + } + } + sscanf(arg+i, "%20s", dev); + if(*dev==0) strcpy(dev, DEFAULTNETDEV); + + struct net_stat *netstat = get_net_stat(dev, obj, free_at_crash); + netstat->v6show_nm = shownetmask; + obj->data.opaque = netstat; } void parse_net_stat_bar_arg(struct text_object *obj, const char *arg, void *free_at_crash) @@ -217,7 +231,7 @@ void print_v6addrs(struct text_object *obj, char *p, int p_max_size) return; if( ! ns->v6addrs) { - strncpy(p, "::", p_max_size); + if(ns->v6show_nm) strncpy(p, "::/128", p_max_size); else strncpy(p, "::", p_max_size); return; } while(current_v6) { @@ -251,11 +265,20 @@ void print_v6addrs(struct text_object *obj, char *p, int p_max_size) *(current_char+4-j)=':'; current_char+=5-j; } + current_char--; + //netmask + if(ns->v6show_nm) { + char netmaskstr[5]; //max 5 chars (/128 + null-terminator) + sprintf(netmaskstr, "/%u", current_v6->netmask); + strcpy(current_char, netmaskstr); + current_char += strlen(netmaskstr); + } + //next (or last) address current_v6 = current_v6->next; if(current_v6) { - strncpy(current_char-1, ", ", 3); - current_char++; - } else *(current_char-1)=0; + strcpy(current_char, ", "); + current_char+=2; + } else *current_char=0; } } #endif /* BUILD_IPV6 */ diff --git a/src/net_stat.h b/src/net_stat.h index 21e29bdf..bbeed45a 100644 --- a/src/net_stat.h +++ b/src/net_stat.h @@ -36,6 +36,7 @@ #ifdef BUILD_IPV6 struct v6addr { char addr[32]; + unsigned int netmask; struct v6addr *next; }; #endif /* BUILD_IPV6 */ @@ -49,6 +50,7 @@ struct net_stat { struct sockaddr addr; #ifdef BUILD_IPV6 struct v6addr *v6addrs; + bool v6show_nm; #endif /* BUILD_IPV6 */ #if defined(__linux__) char addrs[273];