mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-27 00:58:36 +00:00
Add $v6addrs to increase IPv6 support
This is only the beginning of the ipv6 support, This var isn't documented and only works on Linux. It should also be patched to show the addresses in compressed format Some other vars should also be added to see things like netmask, scope, routes, ...
This commit is contained in:
parent
41dc5db094
commit
6287b22a3d
@ -73,12 +73,14 @@ if(OS_LINUX)
|
||||
option(BUILD_WLAN "Enable wireless support" false)
|
||||
# nvidia may also work on FreeBSD, not sure
|
||||
option(BUILD_NVIDIA "Enable nvidia support" false)
|
||||
option(BUILD_IPV6 "Enable if you want IPv6 support" true)
|
||||
else(OS_LINUX)
|
||||
set(BUILD_PORT_MONITORS false)
|
||||
set(BUILD_IBM false)
|
||||
set(BUILD_HDDTEMP false)
|
||||
set(BUILD_WLAN false)
|
||||
set(BUILD_NVIDIA false)
|
||||
set(BUILD_IPV6 false)
|
||||
endif(OS_LINUX)
|
||||
|
||||
# Optional features etc
|
||||
|
@ -82,6 +82,13 @@ if(BUILD_IRC)
|
||||
set(conky_libs ${conky_libs} -lircclient)
|
||||
endif(BUILD_IRC)
|
||||
|
||||
if(BUILD_IPV6)
|
||||
find_file(IF_INET6 if_inet6 PATHS /proc/net)
|
||||
if(NOT IF_INET6)
|
||||
message(FATAL_ERROR "/proc/net/if_inet6 unavailable")
|
||||
endif(NOT IF_INET6)
|
||||
endif(BUILD_IPV6)
|
||||
|
||||
if(BUILD_HTTP)
|
||||
find_file(HTTP_H_ microhttpd.h)
|
||||
#I'm not using check_include_files because microhttpd.h seems to need a lot of different headers and i'm not sure which...
|
||||
|
@ -95,6 +95,8 @@
|
||||
|
||||
#cmakedefine BUILD_IRC 1
|
||||
|
||||
#cmakedefine BUILD_IPV6 1
|
||||
|
||||
#cmakedefine BUILD_HTTP 1
|
||||
|
||||
#cmakedefine BUILD_ICONV 1
|
||||
|
@ -865,6 +865,11 @@ struct text_object *construct_text_object(char *s, const char *arg, long
|
||||
END OBJ(addrs, &update_net_stats)
|
||||
parse_net_stat_arg(obj, arg, free_at_crash);
|
||||
obj->callbacks.print = &print_addrs;
|
||||
#ifdef BUILD_IPV6
|
||||
END OBJ(v6addrs, &update_net_stats)
|
||||
parse_net_stat_arg(obj, arg, free_at_crash);
|
||||
obj->callbacks.print = &print_v6addrs;
|
||||
#endif /* BUILD_IPV6 */
|
||||
END
|
||||
#endif /* __linux__ */
|
||||
OBJ_ARG(tail, 0, "tail needs arguments")
|
||||
|
27
src/linux.cc
27
src/linux.cc
@ -32,6 +32,7 @@
|
||||
#include "net_stat.h"
|
||||
#include "diskio.h"
|
||||
#include "temphelper.h"
|
||||
#include "proc.h"
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
@ -569,6 +570,32 @@ int update_net_stats(void)
|
||||
free(winfo);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef BUILD_IPV6
|
||||
FILE *file;
|
||||
char v6addr[32];
|
||||
char devname[21];
|
||||
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) {
|
||||
ns = get_net_stat(devname, NULL, NULL);
|
||||
if(ns->v6addrs == NULL) {
|
||||
lastv6 = (struct v6addr *) malloc(sizeof(struct v6addr));
|
||||
ns->v6addrs = lastv6;
|
||||
} else {
|
||||
lastv6 = ns->v6addrs;
|
||||
while(lastv6->next) lastv6 = lastv6->next;
|
||||
lastv6->next = (struct v6addr *) malloc(sizeof(struct v6addr));
|
||||
lastv6 = lastv6->next;
|
||||
}
|
||||
strncpy(lastv6->addr, v6addr, 32);
|
||||
lastv6->next = NULL;
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
#endif /* BUILD_IPV6 */
|
||||
|
||||
first = 0;
|
||||
|
||||
fclose(net_dev_fp);
|
||||
|
@ -205,6 +205,36 @@ void print_addrs(struct text_object *obj, char *p, int p_max_size)
|
||||
strncpy(p, "0.0.0.0", p_max_size);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BUILD_IPV6
|
||||
void print_v6addrs(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
struct net_stat *ns = (struct net_stat *)obj->data.opaque;
|
||||
char *current_char = p;
|
||||
struct v6addr *current_v6 = ns->v6addrs;
|
||||
|
||||
if (!ns)
|
||||
return;
|
||||
|
||||
if( ! ns->v6addrs) {
|
||||
strncpy(p, "::", p_max_size);
|
||||
return;
|
||||
}
|
||||
while(current_v6) {
|
||||
for(int i=0; i<8; i++) {
|
||||
strncpy(current_char, current_v6->addr+(i*4), 4);
|
||||
*(current_char+4)=':';
|
||||
current_char+=5;
|
||||
}
|
||||
current_v6 = current_v6->next;
|
||||
if(current_v6) {
|
||||
strncpy(current_char-1, ", ", 3);
|
||||
current_char++;
|
||||
} else *(current_char-1)=0;
|
||||
}
|
||||
}
|
||||
#endif /* BUILD_IPV6 */
|
||||
|
||||
#endif /* __linux__ */
|
||||
|
||||
#ifdef BUILD_X11
|
||||
@ -353,9 +383,19 @@ double wireless_link_barval(struct text_object *obj)
|
||||
|
||||
void clear_net_stats(void)
|
||||
{
|
||||
#ifdef BUILD_IPV6
|
||||
struct v6addr *nextv6;
|
||||
#endif /* BUILD_IPV6 */
|
||||
int i;
|
||||
for (i = 0; i < MAX_NET_INTERFACES; i++) {
|
||||
free_and_zero(netstats[i].dev);
|
||||
#ifdef BUILD_IPV6
|
||||
while(netstats[i].v6addrs) {
|
||||
nextv6 = netstats[i].v6addrs;
|
||||
netstats[i].v6addrs = netstats[i].v6addrs->next;
|
||||
free_and_zero(nextv6);
|
||||
}
|
||||
#endif /* BUILD_IPV6 */
|
||||
}
|
||||
memset(netstats, 0, sizeof(netstats));
|
||||
}
|
||||
|
@ -33,6 +33,13 @@
|
||||
|
||||
#include <sys/socket.h> /* struct sockaddr */
|
||||
|
||||
#ifdef BUILD_IPV6
|
||||
struct v6addr {
|
||||
char addr[32];
|
||||
struct v6addr *next;
|
||||
};
|
||||
#endif /* BUILD_IPV6 */
|
||||
|
||||
struct net_stat {
|
||||
char *dev;
|
||||
int up;
|
||||
@ -40,6 +47,9 @@ struct net_stat {
|
||||
long long recv, trans;
|
||||
double recv_speed, trans_speed;
|
||||
struct sockaddr addr;
|
||||
#ifdef BUILD_IPV6
|
||||
struct v6addr *v6addrs;
|
||||
#endif /* BUILD_IPV6 */
|
||||
#if defined(__linux__)
|
||||
char addrs[273];
|
||||
#endif /* __linux__ */
|
||||
@ -70,6 +80,9 @@ void print_totalup(struct text_object *, char *, int);
|
||||
void print_addr(struct text_object *, char *, int);
|
||||
#ifdef __linux__
|
||||
void print_addrs(struct text_object *, char *, int);
|
||||
#ifdef BUILD_IPV6
|
||||
void print_v6addrs(struct text_object *, char *, int);
|
||||
#endif /* BUILD_IPV6 */
|
||||
#endif /* __linux__ */
|
||||
#ifdef BUILD_X11
|
||||
void parse_net_stat_graph_arg(struct text_object *, const char *, void *);
|
||||
|
Loading…
x
Reference in New Issue
Block a user