From ce99d1a782b0fd1ddc0c474957b9947dbd6dd3ac Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sat, 7 Nov 2009 23:46:46 +0100 Subject: [PATCH] Use a define for the maximum number of network devices --- configure.ac.in | 1 + src/common.c | 2 +- src/linux.c | 8 ++++---- src/net_stat.c | 10 +++++----- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/configure.ac.in b/configure.ac.in index e85f9b90..f6beef86 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -775,6 +775,7 @@ AC_DEFINE(CONFIG_FILE, "$HOME/.conkyrc", [Configfile of the user]) AC_DEFINE(MAX_SPECIALS_DEFAULT, 512, [Default maximum number of special things, e.g. fonts, offsets, aligns, etc.]) AC_DEFINE(MAX_USER_TEXT_DEFAULT, 16384, [Default maximum size of config TEXT buffer, i.e. below TEXT line.]) AC_DEFINE(DEFAULT_TEXT_BUFFER_SIZE, 256, [Default size used for temporary, static text buffers]) +AC_DEFINE(MAX_NET_INTERFACES, 16, [Maximum number of network devices]) dnl dnl Some functions diff --git a/src/common.c b/src/common.c index 18c8eefe..f691a929 100644 --- a/src/common.c +++ b/src/common.c @@ -374,7 +374,7 @@ void update_stuff(void) #ifdef HAVE_OPENMP #pragma omp parallel for schedule(dynamic,10) #endif /* HAVE_OPENMP */ - for (i = 0; i < 16; i++) { + for (i = 0; i < MAX_NET_INTERFACES; i++) { if (netstats[i].dev) { netstats[i].up = 0; netstats[i].recv_speed = 0.0; diff --git a/src/linux.c b/src/linux.c index 5eeae2bf..249ada2e 100644 --- a/src/linux.c +++ b/src/linux.c @@ -362,7 +362,7 @@ void update_net_stats(void) fgets(buf, 255, net_dev_fp); /* garbage (field names) */ /* read each interface */ - for (i2 = 0; i2 < 16; i2++) { + for (i2 = 0; i2 < MAX_NET_INTERFACES; i2++) { struct net_stat *ns; char *s, *p; char temp_addr[18]; @@ -391,7 +391,7 @@ void update_net_stats(void) ns->up = 1; memset(&(ns->addr.sa_data), 0, 14); - memset(ns->addrs, 0, 17 * 16 + 1); /* Up to 17 chars per ip, max 16 interfaces. Nasty memory usage... */ + memset(ns->addrs, 0, 17 * MAX_NET_INTERFACES + 1); /* Up to 17 chars per ip, max MAX_NET_INTERFACES interfaces. Nasty memory usage... */ last_recv = ns->recv; last_trans = ns->trans; @@ -418,8 +418,8 @@ void update_net_stats(void) /*** ip addr patch ***/ i = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); - conf.ifc_buf = malloc(sizeof(struct ifreq) * 16); - conf.ifc_len = sizeof(struct ifreq) * 16; + conf.ifc_buf = malloc(sizeof(struct ifreq) * MAX_NET_INTERFACES); + conf.ifc_len = sizeof(struct ifreq) * MAX_NET_INTERFACES; memset(conf.ifc_buf, 0, conf.ifc_len); ioctl((long) i, SIOCGIFCONF, &conf); diff --git a/src/net_stat.c b/src/net_stat.c index 34c7fe15..e4790034 100644 --- a/src/net_stat.c +++ b/src/net_stat.c @@ -42,7 +42,7 @@ /* network interface stuff */ -struct net_stat netstats[16]; +struct net_stat netstats[MAX_NET_INTERFACES]; struct net_stat *get_net_stat(const char *dev, void *free_at_crash1, void *free_at_crash2) { @@ -53,21 +53,21 @@ struct net_stat *get_net_stat(const char *dev, void *free_at_crash1, void *free_ } /* find interface stat */ - for (i = 0; i < 16; i++) { + for (i = 0; i < MAX_NET_INTERFACES; i++) { if (netstats[i].dev && strcmp(netstats[i].dev, dev) == 0) { return &netstats[i]; } } /* wasn't found? add it */ - for (i = 0; i < 16; i++) { + for (i = 0; i < MAX_NET_INTERFACES; i++) { if (netstats[i].dev == 0) { netstats[i].dev = strndup(dev, text_buffer_size); return &netstats[i]; } } - CRIT_ERR(free_at_crash1, free_at_crash2, "too many interfaces used (limit is 16)"); + CRIT_ERR(free_at_crash1, free_at_crash2, "too many interfaces used (limit is %d)", MAX_NET_INTERFACES); return 0; } @@ -319,7 +319,7 @@ void print_wireless_link_bar(struct text_object *obj, char *p, int p_max_size) void clear_net_stats(void) { int i; - for (i = 0; i < 16; i++) { + for (i = 0; i < MAX_NET_INTERFACES; i++) { if (netstats[i].dev) { free(netstats[i].dev); }