X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmadwifi.c;h=19ece7fec7d318f5533b929beeba147706336d5b;hb=13c83b972a8ade7dff6f8f2d00832d446ef6f502;hp=949724eba0e6b1bcc8c5417a837ef5266dec3f10;hpb=826293bf3acfdcee6632f5d8f0b6be013f2cebab;p=collectd.git diff --git a/src/madwifi.c b/src/madwifi.c index 949724eb..19ece7fe 100644 --- a/src/madwifi.c +++ b/src/madwifi.c @@ -89,6 +89,7 @@ #include "collectd.h" + #include "common.h" #include "plugin.h" #include "configfile.h" @@ -367,28 +368,28 @@ static int init_state = 0; static inline int item_watched(int i) { assert (i >= 0); - assert (((size_t) i) < ((STATIC_ARRAY_SIZE (watch_items) + 1) * 32)); + assert ((size_t) i < (STATIC_ARRAY_SIZE (watch_items) * 32)); return watch_items[i / 32] & FLAG (i); } static inline int item_summed(int i) { assert (i >= 0); - assert (((size_t) i) < ((STATIC_ARRAY_SIZE (misc_items) + 1) * 32)); + assert ((size_t) i < (STATIC_ARRAY_SIZE (misc_items) * 32)); return misc_items[i / 32] & FLAG (i); } static inline void watchlist_add (uint32_t *wl, int item) { assert (item >= 0); - assert (item < ((WL_LEN + 1) * 32)); + assert (item < WL_LEN * 32); wl[item / 32] |= FLAG (item); } static inline void watchlist_remove (uint32_t *wl, int item) { assert (item >= 0); - assert (item < ((WL_LEN + 1) * 32)); + assert (item < WL_LEN * 32); wl[item / 32] &= ~FLAG (item); } @@ -699,7 +700,6 @@ process_80211stats (int sk, const char *dev) static int process_station (int sk, const char *dev, struct ieee80211req_sta_info *si) { - struct iwreq iwr; static char mac[DATA_MAX_NAME_LEN]; struct ieee80211req_sta_stats stats; const struct ieee80211_nodestats *ns = &stats.is_stats; @@ -714,10 +714,12 @@ process_station (int sk, const char *dev, struct ieee80211req_sta_info *si) if (item_watched (STAT_NODE_RSSI)) submit_gauge (dev, "node_rssi", mac, NULL, si->isi_rssi); - memset (&iwr, 0, sizeof (iwr)); + struct iwreq iwr = { + .u.data.pointer = (void *) &stats, + .u.data.length = sizeof (stats) + }; sstrncpy(iwr.ifr_name, dev, sizeof (iwr.ifr_name)); - iwr.u.data.pointer = (void *) &stats; - iwr.u.data.length = sizeof (stats); + memcpy(stats.is_u.macaddr, si->isi_macaddr, IEEE80211_ADDR_LEN); status = ioctl(sk, IEEE80211_IOCTL_STA_STATS, &iwr); if (status < 0) @@ -750,17 +752,17 @@ process_station (int sk, const char *dev, struct ieee80211req_sta_info *si) static int process_stations (int sk, const char *dev) { - uint8_t buf[24*1024]; - struct iwreq iwr; + uint8_t buf[24*1024] = { 0 }; uint8_t *cp; int nodes; size_t len; int status; - memset (&iwr, 0, sizeof (iwr)); + struct iwreq iwr = { + .u.data.pointer = (void *) buf, + .u.data.length = sizeof (buf) + }; sstrncpy (iwr.ifr_name, dev, sizeof (iwr.ifr_name)); - iwr.u.data.pointer = (void *) buf; - iwr.u.data.length = sizeof (buf); status = ioctl (sk, IEEE80211_IOCTL_STA_INFO, &iwr); if (status < 0)