mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-15 17:47:09 +00:00
Support for scope in $v6addrs
This commit is contained in:
parent
997dcc87d9
commit
2754fab78d
@ -251,6 +251,9 @@ static void print_version(void)
|
||||
#ifdef BUILD_HTTP
|
||||
<< _(" * HTTP\n")
|
||||
#endif
|
||||
#ifdef BUILD_IPV6
|
||||
<< _(" * IPv6\n")
|
||||
#endif /* BUILD_IPV6 */
|
||||
#ifdef BUILD_IRC
|
||||
<< _(" * IRC\n")
|
||||
#endif
|
||||
|
23
src/linux.cc
23
src/linux.cc
@ -575,11 +575,11 @@ int update_net_stats(void)
|
||||
FILE *file;
|
||||
char v6addr[32];
|
||||
char devname[21];
|
||||
unsigned int netmask;
|
||||
unsigned int netmask, scope;
|
||||
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, &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);
|
||||
if(ns->v6addrs == NULL) {
|
||||
lastv6 = (struct v6addr *) malloc(sizeof(struct v6addr));
|
||||
@ -592,6 +592,25 @@ int update_net_stats(void)
|
||||
}
|
||||
strncpy(lastv6->addr, v6addr, 32);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
bool shownetmask = false;
|
||||
bool showscope = false;
|
||||
char dev[21]; //a netdev can only be 20 chars long
|
||||
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
|
||||
for(i=1; arg[i] != ' ' && arg[i] != 0; i++) {
|
||||
if(arg[i]=='n') shownetmask = true;
|
||||
if(arg[i]=='s') showscope = true;
|
||||
}
|
||||
}
|
||||
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);
|
||||
#ifdef BUILD_IPV6
|
||||
netstat->v6show_nm = shownetmask;
|
||||
netstat->v6show_sc = showscope;
|
||||
#endif /* BUILD_IPV6 */
|
||||
obj->data.opaque = netstat;
|
||||
}
|
||||
@ -233,7 +236,9 @@ void print_v6addrs(struct text_object *obj, char *p, int p_max_size)
|
||||
return;
|
||||
|
||||
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;
|
||||
}
|
||||
while(current_v6) {
|
||||
@ -275,6 +280,11 @@ void print_v6addrs(struct text_object *obj, char *p, int p_max_size)
|
||||
strcpy(current_char, netmaskstr);
|
||||
current_char += strlen(netmaskstr);
|
||||
}
|
||||
//scope
|
||||
if(ns->v6show_sc) {
|
||||
sprintf(current_char, "(%c)", current_v6->scope);
|
||||
current_char += 3;
|
||||
}
|
||||
//next (or last) address
|
||||
current_v6 = current_v6->next;
|
||||
if(current_v6) {
|
||||
|
@ -37,6 +37,7 @@
|
||||
struct v6addr {
|
||||
char addr[32];
|
||||
unsigned int netmask;
|
||||
char scope;
|
||||
struct v6addr *next;
|
||||
};
|
||||
#endif /* BUILD_IPV6 */
|
||||
@ -51,6 +52,7 @@ struct net_stat {
|
||||
#ifdef BUILD_IPV6
|
||||
struct v6addr *v6addrs;
|
||||
bool v6show_nm;
|
||||
bool v6show_sc;
|
||||
#endif /* BUILD_IPV6 */
|
||||
#if defined(__linux__)
|
||||
char addrs[273];
|
||||
|
Loading…
Reference in New Issue
Block a user