diff --git a/src/core.cc b/src/core.cc index 1b576072..960d3fdd 100644 --- a/src/core.cc +++ b/src/core.cc @@ -781,10 +781,12 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, END OBJ(conky_build_date, nullptr) obj_be_plain_text(obj, BUILD_DATE); END OBJ(conky_build_arch, nullptr) obj_be_plain_text(obj, BUILD_ARCH); END OBJ(downspeed, &update_net_stats) - parse_net_stat_arg(obj, arg, free_at_crash); + update_gateway_info(); + parse_net_stat_arg(obj, arg, free_at_crash); obj->callbacks.print = &print_downspeed; END OBJ(downspeedf, &update_net_stats) - parse_net_stat_arg(obj, arg, free_at_crash); + update_gateway_info(); + parse_net_stat_arg(obj, arg, free_at_crash); obj->callbacks.print = &print_downspeedf; #ifdef BUILD_X11 END OBJ(downspeedgraph, &update_net_stats) @@ -1405,10 +1407,12 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, END OBJ(alignc, nullptr) obj->data.l = arg != nullptr ? atoi(arg) : 0; obj->callbacks.print = &new_alignc; END OBJ(upspeed, &update_net_stats) - parse_net_stat_arg(obj, arg, free_at_crash); + update_gateway_info(); + parse_net_stat_arg(obj, arg, free_at_crash); obj->callbacks.print = &print_upspeed; END OBJ(upspeedf, &update_net_stats) - parse_net_stat_arg(obj, arg, free_at_crash); + update_gateway_info(); + parse_net_stat_arg(obj, arg, free_at_crash); obj->callbacks.print = &print_upspeedf; #ifdef BUILD_X11 END OBJ(upspeedgraph, &update_net_stats) diff --git a/src/linux.cc b/src/linux.cc index 6e549698..c0ef9d9e 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -94,6 +94,8 @@ struct sysfs { float factor, offset; }; +char e_iface[50]; + #define SHORTSTAT_TEMPL "%*s %llu %llu %llu" #define LONGSTAT_TEMPL "%*s %llu %llu %llu " @@ -314,6 +316,7 @@ int update_gateway_info(void) { } if (!(dest || mask) && ((flags & RTF_GATEWAY) || !gate)) { gw_info.count++; + snprintf(e_iface, 49, "%s", iface); SAVE_SET_STRING(gw_info.iface, iface) ina.s_addr = gate; SAVE_SET_STRING(gw_info.ip, inet_ntoa(ina)) diff --git a/src/linux.h b/src/linux.h index 76c9364a..95ad1fd5 100644 --- a/src/linux.h +++ b/src/linux.h @@ -55,4 +55,6 @@ int update_stat(void); void print_distribution(struct text_object *, char *, int); void determine_longstat_file(void); + +extern char e_iface[50]; #endif /* _LINUX_H */ diff --git a/src/net_stat.cc b/src/net_stat.cc index a0cc1dca..d1cd66b0 100644 --- a/src/net_stat.cc +++ b/src/net_stat.cc @@ -48,6 +48,12 @@ #define SOCK_CLOEXEC O_CLOEXEC #endif /* SOCK_CLOEXEC */ +#if defined(__linux__) +#include "linux.h" +#else +char e_iface[50] = "empty"; +#endif /* __linux__ */ + /* network interface stuff */ enum if_up_strictness_ { IFUP_UP, IFUP_LINK, IFUP_ADDR }; @@ -117,6 +123,11 @@ void parse_net_stat_arg(struct text_object *obj, const char *arg, if (arg == nullptr) { arg = DEFAULTNETDEV; } + if (0 == (strcmp("$gw_iface", arg)) || + 0 == (strcmp("${gw_iface}", arg))) { + arg = e_iface; + } + while (sscanf(arg + i, " %20s", nextarg) == 1) { if (strcmp(nextarg, "-n") == 0 || strcmp(nextarg, "--netmask") == 0) { shownetmask = true;