1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-16 01:57:09 +00:00

Support for scope in $v6addrs

This commit is contained in:
Nikolas Garofil 2011-02-11 13:05:00 +01:00
parent 997dcc87d9
commit 2754fab78d
4 changed files with 37 additions and 3 deletions

View File

@ -251,6 +251,9 @@ static void print_version(void)
#ifdef BUILD_HTTP #ifdef BUILD_HTTP
<< _(" * HTTP\n") << _(" * HTTP\n")
#endif #endif
#ifdef BUILD_IPV6
<< _(" * IPv6\n")
#endif /* BUILD_IPV6 */
#ifdef BUILD_IRC #ifdef BUILD_IRC
<< _(" * IRC\n") << _(" * IRC\n")
#endif #endif

View File

@ -575,11 +575,11 @@ int update_net_stats(void)
FILE *file; FILE *file;
char v6addr[32]; char v6addr[32];
char devname[21]; char devname[21];
unsigned int netmask; unsigned int netmask, scope;
struct net_stat *ns; struct net_stat *ns;
struct v6addr *lastv6; struct v6addr *lastv6;
if ((file = fopen(PROCDIR"/net/if_inet6", "r")) != NULL) { if ((file = fopen(PROCDIR"/net/if_inet6", "r")) != NULL) {
while (fscanf(file, "%32s %*02x %02x %*02x %*02x %20s\n", v6addr, &netmask, devname) != EOF) { while (fscanf(file, "%32s %*02x %02x %02x %*02x %20s\n", v6addr, &netmask, &scope, devname) != EOF) {
ns = get_net_stat(devname, NULL, NULL); ns = get_net_stat(devname, NULL, NULL);
if(ns->v6addrs == NULL) { if(ns->v6addrs == NULL) {
lastv6 = (struct v6addr *) malloc(sizeof(struct v6addr)); lastv6 = (struct v6addr *) malloc(sizeof(struct v6addr));
@ -592,6 +592,25 @@ int update_net_stats(void)
} }
strncpy(lastv6->addr, v6addr, 32); strncpy(lastv6->addr, v6addr, 32);
lastv6->netmask = netmask; lastv6->netmask = netmask;
switch(scope) {
case 0: //global
lastv6->scope = 'G';
break;
case 16: //host-local
lastv6->scope = 'H';
break;
case 32: //link-local
lastv6->scope = 'L';
break;
case 64: //site-local
lastv6->scope = 'S';
break;
case 128: //compat
lastv6->scope = 'C';
break;
default:
lastv6->scope = '?';
}
lastv6->next = NULL; lastv6->next = NULL;
} }
} }

View File

@ -91,6 +91,7 @@ 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) void parse_net_stat_arg(struct text_object *obj, const char *arg, void *free_at_crash)
{ {
bool shownetmask = false; bool shownetmask = false;
bool showscope = false;
char dev[21]; //a netdev can only be 20 chars long char dev[21]; //a netdev can only be 20 chars long
int i=0; int i=0;
@ -100,6 +101,7 @@ void parse_net_stat_arg(struct text_object *obj, const char *arg, void *free_at_
if (*arg == '-') { //there are flags if (*arg == '-') { //there are flags
for(i=1; arg[i] != ' ' && arg[i] != 0; i++) { for(i=1; arg[i] != ' ' && arg[i] != 0; i++) {
if(arg[i]=='n') shownetmask = true; if(arg[i]=='n') shownetmask = true;
if(arg[i]=='s') showscope = true;
} }
} }
sscanf(arg+i, "%20s", dev); sscanf(arg+i, "%20s", dev);
@ -108,6 +110,7 @@ void parse_net_stat_arg(struct text_object *obj, const char *arg, void *free_at_
struct net_stat *netstat = get_net_stat(dev, obj, free_at_crash); struct net_stat *netstat = get_net_stat(dev, obj, free_at_crash);
#ifdef BUILD_IPV6 #ifdef BUILD_IPV6
netstat->v6show_nm = shownetmask; netstat->v6show_nm = shownetmask;
netstat->v6show_sc = showscope;
#endif /* BUILD_IPV6 */ #endif /* BUILD_IPV6 */
obj->data.opaque = netstat; obj->data.opaque = netstat;
} }
@ -233,7 +236,9 @@ void print_v6addrs(struct text_object *obj, char *p, int p_max_size)
return; return;
if( ! ns->v6addrs) { if( ! ns->v6addrs) {
if(ns->v6show_nm) strncpy(p, "::/128", p_max_size); else strncpy(p, "::", p_max_size); strncpy(p, "::", p_max_size);
if(ns->v6show_nm) strcat(p, "/128");
if(ns->v6show_sc) strcat(p, "(/)");
return; return;
} }
while(current_v6) { while(current_v6) {
@ -275,6 +280,11 @@ void print_v6addrs(struct text_object *obj, char *p, int p_max_size)
strcpy(current_char, netmaskstr); strcpy(current_char, netmaskstr);
current_char += strlen(netmaskstr); current_char += strlen(netmaskstr);
} }
//scope
if(ns->v6show_sc) {
sprintf(current_char, "(%c)", current_v6->scope);
current_char += 3;
}
//next (or last) address //next (or last) address
current_v6 = current_v6->next; current_v6 = current_v6->next;
if(current_v6) { if(current_v6) {

View File

@ -37,6 +37,7 @@
struct v6addr { struct v6addr {
char addr[32]; char addr[32];
unsigned int netmask; unsigned int netmask;
char scope;
struct v6addr *next; struct v6addr *next;
}; };
#endif /* BUILD_IPV6 */ #endif /* BUILD_IPV6 */
@ -51,6 +52,7 @@ struct net_stat {
#ifdef BUILD_IPV6 #ifdef BUILD_IPV6
struct v6addr *v6addrs; struct v6addr *v6addrs;
bool v6show_nm; bool v6show_nm;
bool v6show_sc;
#endif /* BUILD_IPV6 */ #endif /* BUILD_IPV6 */
#if defined(__linux__) #if defined(__linux__)
char addrs[273]; char addrs[273];