1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-28 13:00:45 +00:00

Support for -n in $v6addrs

This commit is contained in:
Nikolas Garofil 2011-02-10 23:27:14 +01:00
parent ac4a3682ae
commit b548f476cc
3 changed files with 33 additions and 6 deletions

View File

@ -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;
}
}

View File

@ -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 */

View File

@ -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];