git: 44cd85d42e5d - main - ifconfig: cleanup warnings #1
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 24 May 2023 10:40:42 UTC
The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=44cd85d42e5ddb1d5811b388218e14582e078bf8 commit 44cd85d42e5ddb1d5811b388218e14582e078bf8 Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2023-05-23 11:04:09 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> CommitDate: 2023-05-24 10:40:34 +0000 ifconfig: cleanup warnings #1 Cleanup compiler warnings in preparation to set Wextra and remove WARNS?=2 Differential Revision: https://reviews.freebsd.org/D40238 MFC after: 2 weeks --- sbin/ifconfig/af_inet.c | 8 +----- sbin/ifconfig/af_inet6.c | 17 +++++------- sbin/ifconfig/carp.c | 4 +-- sbin/ifconfig/ifbridge.c | 8 ++---- sbin/ifconfig/ifconfig.c | 49 +++++++++++++++++++-------------- sbin/ifconfig/ifconfig.h | 18 ++++++++++++ sbin/ifconfig/ifconfig_netlink.c | 11 ++++---- sbin/ifconfig/ifgroup.c | 14 ++++++---- sbin/ifconfig/ifieee80211.c | 59 ++++++++++++++++++---------------------- sbin/ifconfig/iflagg.c | 12 +++----- sbin/ifconfig/ifmedia.c | 6 ++-- sbin/ifconfig/ifpfsync.c | 8 ++---- sbin/ifconfig/ifstf.c | 4 +-- sbin/ifconfig/ifvxlan.c | 16 +++++------ 14 files changed, 118 insertions(+), 116 deletions(-) diff --git a/sbin/ifconfig/af_inet.c b/sbin/ifconfig/af_inet.c index cb030dbc711b..8d302b260bd1 100644 --- a/sbin/ifconfig/af_inet.c +++ b/sbin/ifconfig/af_inet.c @@ -142,12 +142,6 @@ get_mask(int plen) return (a); } -static struct sockaddr_in * -satosin(struct sockaddr *sa) -{ - return ((struct sockaddr_in *)(void *)sa); -} - static void in_status_nl(struct ifconfig_args *args __unused, struct io_handler *h, if_link_t *link, if_addr_t *ifa) @@ -204,7 +198,7 @@ in_getaddr(const char *s, int which) if((p = strrchr(s, '/')) != NULL) { const char *errstr; /* address is `name/masklen' */ - int masklen; + int masklen = 0; struct sockaddr_in *min = sintab[MASK]; *p = '\0'; if (!isdigit(*(p + 1))) diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index 1bb08c8a6a5a..af4cecf057da 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -65,7 +65,9 @@ static struct in6_aliasreq in6_addreq = .ifra_lifetime = { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } }; static int ip6lifetime; +#ifdef WITHOUT_NETLINK static int prefix(void *, int); +#endif static char *sec2str(time_t); static int explicit_prefix = 0; extern char *f_inet6, *f_addr; @@ -154,7 +156,7 @@ setip6eui64(const char *cmd, int dummy __unused, int s, for (ifa = ifap; ifa; ifa = ifa->ifa_next) { if (ifa->ifa_addr->sa_family == AF_INET6 && strcmp(ifa->ifa_name, name) == 0) { - sin6 = (const struct sockaddr_in6 *)ifa->ifa_addr; + sin6 = (const struct sockaddr_in6 *)satosin6(ifa->ifa_addr); if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { lladdr = &sin6->sin6_addr; break; @@ -338,12 +340,6 @@ show_lifetime(struct ifa_cacheinfo *ci) print_lifetime("vltime", vl + now.tv_sec, &now); } -static struct sockaddr_in6 * -satosin6(struct sockaddr *sa) -{ - return ((struct sockaddr_in6 *)(void *)sa); -} - static void in6_status_nl(struct ifconfig_args *args __unused, struct io_handler *h, if_link_t *link, if_addr_t *ifa) @@ -376,10 +372,9 @@ in6_status_nl(struct ifconfig_args *args __unused, struct io_handler *h, } #endif -#define SIN6(x) ((struct sockaddr_in6 *) &(x)) static struct sockaddr_in6 *sin6tab[] = { - SIN6(in6_ridreq.ifr_addr), SIN6(in6_addreq.ifra_addr), - SIN6(in6_addreq.ifra_prefixmask), SIN6(in6_addreq.ifra_dstaddr) + &in6_ridreq.ifr_addr, &in6_addreq.ifra_addr, + &in6_addreq.ifra_prefixmask, &in6_addreq.ifra_dstaddr }; static void @@ -440,6 +435,7 @@ in6_getaddr(const char *s, int which) } } +#ifdef WITHOUT_NETLINK static int prefix(void *val, int size) { @@ -463,6 +459,7 @@ prefix(void *val, int size) return(0); return (plen); } +#endif static char * sec2str(time_t total) diff --git a/sbin/ifconfig/carp.c b/sbin/ifconfig/carp.c index cc38eed4cb4b..2d6c581582b1 100644 --- a/sbin/ifconfig/carp.c +++ b/sbin/ifconfig/carp.c @@ -252,13 +252,11 @@ static struct afswtch af_carp = { static __constructor void carp_ctor(void) { - int i; - /* Default to multicast. */ setcarp_mcast(NULL, 0, 0, NULL); setcarp_mcast6(NULL, 0, 0, NULL); - for (i = 0; i < nitems(carp_cmds); i++) + for (size_t i = 0; i < nitems(carp_cmds); i++) cmd_register(&carp_cmds[i]); af_register(&af_carp); } diff --git a/sbin/ifconfig/ifbridge.c b/sbin/ifconfig/ifbridge.c index 3a78b068eb5d..6bbc63ac9779 100644 --- a/sbin/ifconfig/ifbridge.c +++ b/sbin/ifconfig/ifbridge.c @@ -124,7 +124,7 @@ bridge_addresses(int s, const char *prefix) struct ifbaconf ifbac; struct ifbareq *ifba; char *inbuf = NULL, *ninbuf; - int i, len = 8192; + size_t len = 8192; struct ether_addr ea; for (;;) { @@ -140,7 +140,7 @@ bridge_addresses(int s, const char *prefix) len *= 2; } - for (i = 0; i < ifbac.ifbac_len / sizeof(*ifba); i++) { + for (unsigned long i = 0; i < ifbac.ifbac_len / sizeof(*ifba); i++) { ifba = ifbac.ifbac_req + i; memcpy(ea.octet, ifba->ifba_dst, sizeof(ea.octet)); @@ -683,9 +683,7 @@ static struct afswtch af_bridge = { static __constructor void bridge_ctor(void) { - int i; - - for (i = 0; i < nitems(bridge_cmds); i++) + for (size_t i = 0; i < nitems(bridge_cmds); i++) cmd_register(&bridge_cmds[i]); af_register(&af_bridge); } diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index e1467e661657..db275d877c00 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -93,8 +93,10 @@ ifconfig_handle_t *lifh; struct ifreq ifr; char name[IFNAMSIZ]; -char *descr = NULL; -size_t descrlen = 64; +#ifdef WITHOUT_NETLINK +static char *descr = NULL; +static size_t descrlen = 64; +#endif static int setaddr; static int setmask; static int doalias; @@ -111,17 +113,17 @@ int exit_code = 0; /* Formatter Strings */ char *f_inet, *f_inet6, *f_ether, *f_addr; +#ifdef WITHOUT_NETLINK static void list_interfaces_ioctl(struct ifconfig_args *args); static void status(struct ifconfig_args *args, const struct sockaddr_dl *sdl, struct ifaddrs *ifa); +#endif static _Noreturn void usage(void); static int getifflags(const char *ifname, int us, bool err_ok); static struct afswtch *af_getbyname(const char *name); -void printifnamemaybe(void); - static struct option *opts = NULL; struct ifa_order_elt { @@ -210,6 +212,7 @@ ioctl_ifcreate(int s, struct ifreq *ifr) } } +#ifdef WITHOUT_NETLINK static int calcorders(struct ifaddrs *ifa, struct ifa_queue *q) { @@ -296,6 +299,7 @@ cmpifaddrs(struct ifaddrs *a, struct ifaddrs *b, struct ifa_queue *q) return (0); } +#endif static void freeformat(void) { @@ -339,6 +343,7 @@ static void setformat(char *input) free(formatstr); } +#ifdef WITHOUT_NETLINK static struct ifaddrs * sortifaddrs(struct ifaddrs *list, int (*compare)(struct ifaddrs *, struct ifaddrs *, struct ifa_queue *), @@ -393,8 +398,10 @@ sortifaddrs(struct ifaddrs *list, return (result); } +#endif -void printifnamemaybe() +static void +printifnamemaybe(void) { if (printifname) printf("%s\n", name); @@ -694,6 +701,19 @@ match_ether(const struct sockaddr_dl *sdl) } } +bool +match_if_flags(struct ifconfig_args *args, int if_flags) +{ + if ((if_flags & IFF_CANTCONFIG) != 0) + return (false); + if (args->downonly && (if_flags & IFF_UP) != 0) + return (false); + if (args->uponly && (if_flags & IFF_UP) == 0) + return (false); + return (true); +} + +#ifdef WITHOUT_NETLINK static bool match_afp(const struct afswtch *afp, int sa_family, const struct sockaddr_dl *sdl) { @@ -708,19 +728,6 @@ match_afp(const struct afswtch *afp, int sa_family, const struct sockaddr_dl *sd return (afp->af_af == sa_family); } -bool -match_if_flags(struct ifconfig_args *args, int if_flags) -{ - if ((if_flags & IFF_CANTCONFIG) != 0) - return (false); - if (args->downonly && (if_flags & IFF_UP) != 0) - return (false); - if (args->uponly && (if_flags & IFF_UP) == 0) - return (false); - return (true); -} - -#ifdef WITHOUT_NETLINK static void list_interfaces_ioctl(struct ifconfig_args *args) { @@ -815,7 +822,7 @@ group_member(const char *ifname, const char *match, const char *nomatch) struct ifgroupreq ifgr; struct ifg_req *ifg; - int len; + unsigned int len; bool matched, nomatched; /* Sanity checks. */ @@ -1806,7 +1813,7 @@ ifmaybeload(struct ifconfig_args *args, const char *name) { #define MOD_PREFIX_LEN 3 /* "if_" */ struct module_stat mstat; - int i, fileid, modid; + int fileid, modid; char ifkind[IFNAMSIZ + MOD_PREFIX_LEN], ifname[IFNAMSIZ], *dp; const char *cp; struct module_map_entry *mme; @@ -1829,7 +1836,7 @@ ifmaybeload(struct ifconfig_args *args, const char *name) /* Either derive it from the map or guess otherwise */ *ifkind = '\0'; found = false; - for (i = 0; i < nitems(module_map); ++i) { + for (unsigned i = 0; i < nitems(module_map); ++i) { mme = &module_map[i]; if (strcmp(mme->ifname, ifname) == 0) { strlcpy(ifkind, mme->kldname, sizeof(ifkind)); diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h index 1df94f357c43..1f60164b7075 100644 --- a/sbin/ifconfig/ifconfig.h +++ b/sbin/ifconfig/ifconfig.h @@ -240,6 +240,7 @@ extern int verbose; extern int printifname; extern int exit_code; extern struct ifconfig_args args; +extern char *f_inet, *f_inet6, *f_ether, *f_addr; void setifcap(const char *, int value, int s, const struct afswtch *); void setifcapnv(const char *vname, const char *arg, int s, @@ -281,3 +282,20 @@ struct ifmediareq *ifmedia_getstate(void); void print_vhid(const struct ifaddrs *, const char *); void ioctl_ifcreate(int s, struct ifreq *); + +/* Helpers */ +struct sockaddr_in; +struct sockaddr_in6; +struct sockaddr; + +static inline struct sockaddr_in6 * +satosin6(struct sockaddr *sa) +{ + return ((struct sockaddr_in6 *)(void *)sa); +} + +static inline struct sockaddr_in * +satosin(struct sockaddr *sa) +{ + return ((struct sockaddr_in *)(void *)sa); +} diff --git a/sbin/ifconfig/ifconfig_netlink.c b/sbin/ifconfig/ifconfig_netlink.c index 26a42b5866c5..96f945de65b1 100644 --- a/sbin/ifconfig/ifconfig_netlink.c +++ b/sbin/ifconfig/ifconfig_netlink.c @@ -288,7 +288,7 @@ sort_iface_ifaddrs(struct snl_state *ss, struct iface *iface) struct ifa **sorted_ifaddrs = snl_allocz(ss, iface->ifa_count * sizeof(void *)); struct ifa *ifa = iface->ifa; - for (int i = 0; i < iface->ifa_count; i++) { + for (uint32_t i = 0; i < iface->ifa_count; i++) { struct ifa *ifa_next = ifa->next; sorted_ifaddrs[i] = ifa; @@ -298,7 +298,7 @@ sort_iface_ifaddrs(struct snl_state *ss, struct iface *iface) qsort(sorted_ifaddrs, iface->ifa_count, sizeof(void *), cmp_ifaddr); ifa = sorted_ifaddrs[0]; iface->ifa = ifa; - for (int i = 1; i < iface->ifa_count; i++) { + for (uint32_t i = 1; i < iface->ifa_count; i++) { ifa->next = sorted_ifaddrs[i]; ifa = sorted_ifaddrs[i]; } @@ -371,7 +371,8 @@ get_local_socket(void) static void set_global_ifname(if_link_t *link) { - int iflen = strlcpy(name, link->ifla_ifname, sizeof(name)); + size_t iflen = strlcpy(name, link->ifla_ifname, sizeof(name)); + if (iflen >= sizeof(name)) errx(1, "%s: cloning name too long", link->ifla_ifname); strlcpy(ifr.ifr_name, link->ifla_ifname, sizeof(ifr.ifr_name)); @@ -386,7 +387,7 @@ list_interfaces_nl(struct ifconfig_args *args) struct ifmap *ifmap = prepare_ifmap(&ss); struct iface **sorted_ifaces = snl_allocz(&ss, ifmap->count * sizeof(void *)); - for (int i = 0, num = 0; i < ifmap->size; i++) { + for (uint32_t i = 0, num = 0; i < ifmap->size; i++) { if (ifmap->ifaces[i] != NULL) { sorted_ifaces[num++] = ifmap->ifaces[i]; if (num == ifmap->count) @@ -401,7 +402,7 @@ list_interfaces_nl(struct ifconfig_args *args) .ss = &ss, }; - for (int i = 0, num = 0; i < ifmap->count; i++) { + for (uint32_t i = 0, num = 0; i < ifmap->count; i++) { struct iface *iface = sorted_ifaces[i]; if (!match_iface(args, iface)) diff --git a/sbin/ifconfig/ifgroup.c b/sbin/ifconfig/ifgroup.c index 67dbc7f689f5..fc252d783d40 100644 --- a/sbin/ifconfig/ifgroup.c +++ b/sbin/ifconfig/ifgroup.c @@ -114,7 +114,7 @@ printgroup(const char *groupname) { struct ifgroupreq ifgr; struct ifg_req *ifg; - int len; + unsigned int len; int s; s = socket(AF_LOCAL, SOCK_DGRAM, 0); @@ -150,19 +150,23 @@ static struct cmd group_cmds[] = { DEF_CMD_ARG("group", setifgroup), DEF_CMD_ARG("-group", unsetifgroup), }; + static struct afswtch af_group = { .af_name = "af_group", .af_af = AF_UNSPEC, .af_other_status = getifgroups, }; -static struct option group_gopt = { "g:", "[-g groupname]", printgroup }; + +static struct option group_gopt = { + .opt = "g:", + .opt_usage = "[-g groupname]", + .cb = printgroup, +}; static __constructor void group_ctor(void) { - int i; - - for (i = 0; i < nitems(group_cmds); i++) + for (size_t i = 0; i < nitems(group_cmds); i++) cmd_register(&group_cmds[i]); af_register(&af_group); opt_register(&group_gopt); diff --git a/sbin/ifconfig/ifieee80211.c b/sbin/ifconfig/ifieee80211.c index 065a141da0f1..fc47105d9366 100644 --- a/sbin/ifconfig/ifieee80211.c +++ b/sbin/ifconfig/ifieee80211.c @@ -264,7 +264,7 @@ getregdata(void) * 11b > 11g. */ static int -canpromote(int i, int from, int to) +canpromote(unsigned int i, uint32_t from, uint32_t to) { const struct ieee80211_channel *fc = &chaninfo->ic_chans[i]; u_int j; @@ -301,7 +301,7 @@ canpromote(int i, int from, int to) * XXX VHT */ static int -promote(int i) +promote(unsigned int i) { /* * Query the current mode of the interface in case it's @@ -347,7 +347,7 @@ promote(int i) } static void -mapfreq(struct ieee80211_channel *chan, int freq, int flags) +mapfreq(struct ieee80211_channel *chan, uint16_t freq, unsigned int flags) { u_int i; @@ -367,7 +367,7 @@ mapfreq(struct ieee80211_channel *chan, int freq, int flags) } static void -mapchan(struct ieee80211_channel *chan, int ieee, int flags) +mapchan(struct ieee80211_channel *chan, uint8_t ieee, unsigned int flags) { u_int i; @@ -662,7 +662,7 @@ set80211stationname(const char *val, int d, int s, const struct afswtch *rafp) * The result is not validated here; it's assumed to be * checked against the channel table fetched from the kernel. */ -static int +static unsigned int getchannelflags(const char *val, int freq) { #define _CHAN_HT 0x80000000 @@ -808,7 +808,7 @@ getchannelflags(const char *val, int freq) static void getchannel(int s, struct ieee80211_channel *chan, const char *val) { - int v, flags; + unsigned int v, flags; char *eptr; memset(chan, 0, sizeof(*chan)); @@ -2084,11 +2084,9 @@ chanlookup(const struct ieee80211_channel chans[], int nchans, } static int -chanfind(const struct ieee80211_channel chans[], int nchans, int flags) +chanfind(const struct ieee80211_channel chans[], int nchans, unsigned int flags) { - int i; - - for (i = 0; i < nchans; i++) { + for (int i = 0; i < nchans; i++) { const struct ieee80211_channel *c = &chans[i]; if ((c->ic_flags & flags) == flags) return 1; @@ -2699,7 +2697,7 @@ getflags(int flags) } static void -printie(const char* tag, const uint8_t *ie, size_t ielen, int maxlen) +printie(const char* tag, const uint8_t *ie, size_t ielen, unsigned int maxlen) { printf("%s", tag); if (verbose) { @@ -2829,14 +2827,14 @@ printvhtpwrenv(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) if (verbose) { const struct ieee80211_ie_vht_txpwrenv *vhtpwr = (const struct ieee80211_ie_vht_txpwrenv *) ie; - int i, n; + size_t i, n; const char *sep = ""; /* Get count; trim at ielen */ n = (vhtpwr->tx_info & IEEE80211_VHT_TXPWRENV_INFO_COUNT_MASK) + 1; /* Trim at ielen */ - if (n > ielen - 3) + if (n + 3 > ielen) n = ielen - 3; printf("<tx_info 0x%02x pwr:[", vhtpwr->tx_info); for (i = 0; i < n; i++) { @@ -3006,11 +3004,10 @@ printapchanrep(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) const struct ieee80211_ap_chan_report_ie *ap = (const struct ieee80211_ap_chan_report_ie *) ie; const char *sep = ""; - int i; printf("<class %u, chan:[", ap->i_class); - for (i = 3; i < ielen; i++) { + for (size_t i = 3; i < ielen; i++) { printf("%s%u", sep, ie[i]); sep = ","; } @@ -3331,7 +3328,7 @@ printwpsie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) break; case IEEE80211_WPS_ATTR_DEV_PASSWORD_ID: n = LE_READ_2(ie); - if (n < nitems(dev_pass_id)) + if (n < (int)nitems(dev_pass_id)) printf(" dpi:%s", dev_pass_id[n]); break; case IEEE80211_WPS_ATTR_MANUFACTURER: @@ -3492,11 +3489,10 @@ static void printrates(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) { const char *sep; - int i; printf("%s", tag); sep = "<"; - for (i = 2; i < ielen; i++) { + for (size_t i = 2; i < ielen; i++) { printf("%s%s%d", sep, ie[i] & IEEE80211_RATE_BASIC ? "B" : "", ie[i] & IEEE80211_RATE_VAL); @@ -3603,7 +3599,7 @@ iename(int elemid) } static void -printies(const u_int8_t *vp, int ielen, int maxcols) +printies(const u_int8_t *vp, int ielen, unsigned int maxcols) { while (ielen > 0) { switch (vp[0]) { @@ -3737,7 +3733,7 @@ list_scan(int s) if (get80211len(s, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0) errx(1, "unable to get scan results"); - if (len < sizeof(struct ieee80211req_scan_result)) + if (len < (int)sizeof(struct ieee80211req_scan_result)) return; getchaninfo(s); @@ -3756,7 +3752,7 @@ list_scan(int s) const struct ieee80211req_scan_result *sr; const uint8_t *vp, *idp; - sr = (const struct ieee80211req_scan_result *) cp; + sr = (const struct ieee80211req_scan_result *)(const void *) cp; vp = cp + sr->isr_ie_off; if (sr->isr_meshid_len) { idp = vp + sr->isr_ssid_len; @@ -3781,7 +3777,7 @@ list_scan(int s) printbssidname((const struct ether_addr *)sr->isr_bssid); printf("\n"); cp += sr->isr_len, len -= sr->isr_len; - } while (len >= sizeof(struct ieee80211req_scan_result)); + } while (len >= (int)sizeof(struct ieee80211req_scan_result)); } static void @@ -3862,13 +3858,13 @@ gettxseq(const struct ieee80211req_sta_info *si) static int getrxseq(const struct ieee80211req_sta_info *si) { - int i, rxseq; + int rxseq; if ((si->isi_state & IEEE80211_NODE_QOS) == 0) return si->isi_rxseqs[0]; /* XXX not right but usually what folks want */ rxseq = 0; - for (i = 0; i < IEEE80211_TID_SIZE; i++) + for (unsigned int i = 0; i < IEEE80211_TID_SIZE; i++) if (si->isi_rxseqs[i] > rxseq) rxseq = si->isi_rxseqs[i]; return rxseq; @@ -3896,7 +3892,7 @@ list_stations(int s) } if (get80211len(s, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0) errx(1, "unable to get station information"); - if (len < sizeof(struct ieee80211req_sta_info)) + if (len < (int)sizeof(struct ieee80211req_sta_info)) return; getchaninfo(s); @@ -3968,7 +3964,7 @@ list_stations(int s) printmimo(&si->isi_mimo); printf("\n"); cp += si->isi_len, len -= si->isi_len; - } while (len >= sizeof(struct ieee80211req_sta_info)); + } while (len >= (int)sizeof(struct ieee80211req_sta_info)); } static const char * @@ -4108,7 +4104,7 @@ print_channels(int s, const struct ieee80211req_chaninfo *chans, struct ieee80211req_chaninfo *achans; uint8_t reported[IEEE80211_CHAN_BYTES]; const struct ieee80211_channel *c; - int i, half; + unsigned int i, half; achans = malloc(IEEE80211_CHANINFO_SPACE(chans)); if (achans == NULL) @@ -4202,7 +4198,7 @@ list_txpow(int s) struct ieee80211req_chaninfo *achans; uint8_t reported[IEEE80211_CHAN_BYTES]; struct ieee80211_channel *c, *prev; - int i, half; + unsigned int i, half; getchaninfo(s); achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo)); @@ -4623,7 +4619,8 @@ list_mesh(int s) , "MSEQ" , "FLAGS"); - for (rt = &routes[0]; rt - &routes[0] < ireq.i_len / sizeof(*rt); rt++){ + for (unsigned int i = 0; i < ireq.i_len / sizeof(*rt); i++) { + rt = &routes[i]; printf("%s ", ether_ntoa((const struct ether_addr *)rt->imr_dest)); printf("%s %4u %4u %6u %6u %c%c\n", @@ -6079,9 +6076,7 @@ static struct afswtch af_ieee80211 = { static __constructor void ieee80211_ctor(void) { - int i; - - for (i = 0; i < nitems(ieee80211_cmds); i++) + for (size_t i = 0; i < nitems(ieee80211_cmds); i++) cmd_register(&ieee80211_cmds[i]); af_register(&af_ieee80211); clone_setdefcallback_prefix("wlan", wlan_create); diff --git a/sbin/ifconfig/iflagg.c b/sbin/ifconfig/iflagg.c index 48d7450076a9..4040d423cc6a 100644 --- a/sbin/ifconfig/iflagg.c +++ b/sbin/ifconfig/iflagg.c @@ -78,12 +78,11 @@ setlaggproto(const char *val, int d, int s, const struct afswtch *afp) { struct lagg_protos lpr[] = LAGG_PROTOS; struct lagg_reqall ra; - int i; bzero(&ra, sizeof(ra)); ra.ra_proto = LAGG_PROTO_MAX; - for (i = 0; i < nitems(lpr); i++) { + for (size_t i = 0; i < nitems(lpr); i++) { if (strcmp(val, lpr[i].lpr_name) == 0) { ra.ra_proto = lpr[i].lpr_proto; break; @@ -279,7 +278,7 @@ lagg_status(int s) } } - for (size_t i = 0; i < ra->ra_ports; ++i) { + for (size_t i = 0; i < (size_t)ra->ra_ports; ++i) { lp = &ports[i].rp_lacpreq; printf("\tlaggport: %s ", ports[i].rp_portname); printb("flags", ports[i].rp_flags, LAGG_PORT_BITS); @@ -298,9 +297,8 @@ static DECL_CMD_FUNC(setlaggtype, arg, d) { static const struct lagg_types lt[] = LAGG_TYPES; - int i; - for (i = 0; i < nitems(lt); i++) { + for (size_t i = 0; i < nitems(lt); i++) { if (strcmp(arg, lt[i].lt_name) == 0) { params.lagg_type = lt[i].lt_value; return; @@ -346,9 +344,7 @@ static struct afswtch af_lagg = { static __constructor void lagg_ctor(void) { - int i; - - for (i = 0; i < nitems(lagg_cmds); i++) + for (size_t i = 0; i < nitems(lagg_cmds); i++) cmd_register(&lagg_cmds[i]); af_register(&af_lagg); clone_setdefcallback_prefix("lagg", lagg_create); diff --git a/sbin/ifconfig/ifmedia.c b/sbin/ifconfig/ifmedia.c index 3014d19b00ff..510c74b8be21 100644 --- a/sbin/ifconfig/ifmedia.c +++ b/sbin/ifconfig/ifmedia.c @@ -146,7 +146,7 @@ media_status(int s) if (args.supmedia) { printf("\tsupported media:\n"); - for (size_t i = 0; i < ifmr->ifm_count; ++i) { + for (int i = 0; i < ifmr->ifm_count; ++i) { printf("\t\t"); print_media_ifconfig(ifmr->ifm_ulist[i]); putchar('\n'); @@ -486,9 +486,7 @@ static struct afswtch af_media = { static __constructor void ifmedia_ctor(void) { - size_t i; - - for (i = 0; i < nitems(media_cmds); i++) + for (size_t i = 0; i < nitems(media_cmds); i++) cmd_register(&media_cmds[i]); af_register(&af_media); } diff --git a/sbin/ifconfig/ifpfsync.c b/sbin/ifconfig/ifpfsync.c index e5118fff36af..eb214ed6e634 100644 --- a/sbin/ifconfig/ifpfsync.c +++ b/sbin/ifconfig/ifpfsync.c @@ -330,8 +330,8 @@ pfsync_status(int s) char syncdev[IFNAMSIZ]; char syncpeer_str[NI_MAXHOST]; struct sockaddr_storage syncpeer; - int maxupdates; - int flags; + int maxupdates = 0; + int flags = 0; int error; nvl = nvlist_create(0); @@ -401,9 +401,7 @@ static struct afswtch af_pfsync = { static __constructor void pfsync_ctor(void) { - int i; - - for (i = 0; i < nitems(pfsync_cmds); i++) + for (size_t i = 0; i < nitems(pfsync_cmds); i++) cmd_register(&pfsync_cmds[i]); af_register(&af_pfsync); } diff --git a/sbin/ifconfig/ifstf.c b/sbin/ifconfig/ifstf.c index f6c3cb5d5447..035793ccd98f 100644 --- a/sbin/ifconfig/ifstf.c +++ b/sbin/ifconfig/ifstf.c @@ -144,9 +144,7 @@ static struct afswtch af_stf = { static __constructor void stf_ctor(void) { - int i; - - for (i = 0; i < nitems(stf_cmds); i++) + for (size_t i = 0; i < nitems(stf_cmds); i++) cmd_register(&stf_cmds[i]); af_register(&af_stf); } diff --git a/sbin/ifconfig/ifvxlan.c b/sbin/ifconfig/ifvxlan.c index fda435343a16..131bbc105973 100644 --- a/sbin/ifconfig/ifvxlan.c +++ b/sbin/ifconfig/ifvxlan.c @@ -128,10 +128,10 @@ vxlan_status(int s) dst[0] = dstport[0] = '\0'; if (!ipv6) { - struct sockaddr_in *sin = (struct sockaddr_in *)rsa; + struct sockaddr_in *sin = satosin(rsa); mc = IN_MULTICAST(ntohl(sin->sin_addr.s_addr)); } else { - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)rsa; + struct sockaddr_in6 *sin6 = satosin6(rsa); mc = IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr); } @@ -235,7 +235,7 @@ DECL_CMD_FUNC(setvxlan_local, addr, d) switch (ai->ai_family) { #ifdef INET case AF_INET: { - struct sockaddr_in *sin = (struct sockaddr_in *)sa; + struct sockaddr_in *sin = satosin(sa); if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) errx(1, "local address cannot be multicast"); @@ -246,7 +246,7 @@ DECL_CMD_FUNC(setvxlan_local, addr, d) #endif #ifdef INET6 case AF_INET6: { - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; + struct sockaddr_in6 *sin6 = satosin6(sa); if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) errx(1, "local address cannot be multicast"); @@ -295,7 +295,7 @@ DECL_CMD_FUNC(setvxlan_remote, addr, d) switch (ai->ai_family) { #ifdef INET case AF_INET: { - struct sockaddr_in *sin = (struct sockaddr_in *)sa; + struct sockaddr_in *sin = satosin(sa); if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) errx(1, "remote address cannot be multicast"); @@ -306,7 +306,7 @@ DECL_CMD_FUNC(setvxlan_remote, addr, d) #endif #ifdef INET6 case AF_INET6: { - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; + struct sockaddr_in6 *sin6 = satosin6(sa); if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) errx(1, "remote address cannot be multicast"); @@ -355,7 +355,7 @@ DECL_CMD_FUNC(setvxlan_group, addr, d) switch (ai->ai_family) { #ifdef INET case AF_INET: { - struct sockaddr_in *sin = (struct sockaddr_in *)sa; + struct sockaddr_in *sin = satosin(sa); if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) errx(1, "group address must be multicast"); @@ -366,7 +366,7 @@ DECL_CMD_FUNC(setvxlan_group, addr, d) #endif #ifdef INET6 case AF_INET6: { - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; + struct sockaddr_in6 *sin6 = satosin6(sa); if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) errx(1, "group address must be multicast");