1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-15 17:47:09 +00:00

upspeed/f downspeed/f: Be able to use ${gw_iface} as argument (#571)

This commit is contained in:
su8 2018-08-06 21:48:07 +00:00 committed by Brenden Matthews
parent fd4ab7fc07
commit bd98860640
4 changed files with 24 additions and 4 deletions

View File

@ -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)

View File

@ -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))

View File

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

View File

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