1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-26 20:31:17 +00:00

Use a define for the maximum number of network devices

This commit is contained in:
Nikolas Garofil 2009-11-07 23:46:46 +01:00
parent aad43bea8d
commit ce99d1a782
4 changed files with 11 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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