diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index b1529e23ff81..b8121a67aaf5 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -58,8 +58,8 @@ static const char rcsid[] = #include "ifconfig.h" static struct in6_ifreq in6_ridreq; -static struct in6_aliasreq in6_addreq = - { .ifra_flags = 0, +static struct in6_aliasreq in6_addreq = + { .ifra_flags = 0, .ifra_lifetime = { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } }; static int ip6lifetime; @@ -284,20 +284,23 @@ in6_status(int s __unused, const struct ifaddrs *ifa) if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0) printf("prefer_source "); - in6_print_scope((uint8_t *)&((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_addr); + in6_print_scope((uint8_t *)&((struct sockaddr_in6 *) + (ifa->ifa_addr))->sin6_addr); if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { printf("pltime "); if (lifetime.ia6t_preferred) { printf("%s ", lifetime.ia6t_preferred < now.tv_sec - ? "0" : sec2str(lifetime.ia6t_preferred - now.tv_sec)); + ? "0" : + sec2str(lifetime.ia6t_preferred - now.tv_sec)); } else printf("infty "); printf("vltime "); if (lifetime.ia6t_expire) { printf("%s ", lifetime.ia6t_expire < now.tv_sec - ? "0" : sec2str(lifetime.ia6t_expire - now.tv_sec)); + ? "0" : + sec2str(lifetime.ia6t_expire - now.tv_sec)); } else printf("infty "); } @@ -372,25 +375,25 @@ in6_getaddr(const char *s, int which) static int prefix(void *val, int size) { - u_char *name = (u_char *)val; - int byte, bit, plen = 0; + u_char *name = (u_char *)val; + int byte, bit, plen = 0; - for (byte = 0; byte < size; byte++, plen += 8) - if (name[byte] != 0xff) - break; + for (byte = 0; byte < size; byte++, plen += 8) + if (name[byte] != 0xff) + break; if (byte == size) return (plen); for (bit = 7; bit != 0; bit--, plen++) - if (!(name[byte] & (1 << bit))) - break; - for (; bit != 0; bit--) - if (name[byte] & (1 << bit)) - return(0); - byte++; - for (; byte < size; byte++) - if (name[byte]) - return(0); - return (plen); + if (!(name[byte] & (1 << bit))) + break; + for (; bit != 0; bit--) + if (name[byte] & (1 << bit)) + return(0); + byte++; + for (; byte < size; byte++) + if (name[byte]) + return(0); + return (plen); } static char * @@ -534,7 +537,11 @@ in6_Lopt_cb(const char *optarg __unused) { ip6lifetime++; /* print IPv6 address lifetime */ } -static struct option in6_Lopt = { .opt = "L", .opt_usage = "[-L]", .cb = in6_Lopt_cb }; +static struct option in6_Lopt = { + .opt = "L", + .opt_usage = "[-L]", + .cb = in6_Lopt_cb +}; static __constructor void inet6_ctor(void) diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index c449c9045368..73d84f52253d 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -151,12 +151,14 @@ usage(void) exit(1); } +#define ORDERS_SIZE(x) sizeof(x) / sizeof(x[0]) + static int calcorders(struct ifaddrs *ifa, struct ifa_queue *q) { - unsigned int ord, af, ifa_ord; struct ifaddrs *prev; struct ifa_order_elt *cur; + unsigned int ord, af, ifa_ord; prev = NULL; cur = NULL; @@ -164,7 +166,8 @@ calcorders(struct ifaddrs *ifa, struct ifa_queue *q) ifa_ord = 0; while (ifa != NULL) { - if (prev == NULL || strcmp(ifa->ifa_name, prev->ifa_name) != 0) { + if (prev == NULL || + strcmp(ifa->ifa_name, prev->ifa_name) != 0) { cur = calloc(1, sizeof(*cur)); if (cur == NULL) @@ -179,12 +182,12 @@ calcorders(struct ifaddrs *ifa, struct ifa_queue *q) if (ifa->ifa_addr) { af = ifa->ifa_addr->sa_family; - if (af < sizeof(cur->af_orders) / sizeof(cur->af_orders[0]) && - cur->af_orders[af] == 0) + if (af < ORDERS_SIZE(cur->af_orders) && + cur->af_orders[af] == 0) cur->af_orders[af] = ++ord; } prev = ifa; - ifa = ifa->ifa_next; + ifa = ifa->ifa_next; } return (0); @@ -193,15 +196,14 @@ calcorders(struct ifaddrs *ifa, struct ifa_queue *q) static int cmpifaddrs(struct ifaddrs *a, struct ifaddrs *b, struct ifa_queue *q) { - int ret; - unsigned int af1, af2; struct ifa_order_elt *cur, *e1, *e2; + unsigned int af1, af2; + int ret; e1 = e2 = NULL; ret = strcmp(a->ifa_name, b->ifa_name); if (ret != 0) { - /* We need to find elements corresponding to these different names */ TAILQ_FOREACH(cur, q, link) { if (e1 && e2) break; @@ -231,20 +233,21 @@ cmpifaddrs(struct ifaddrs *a, struct ifaddrs *b, struct ifa_queue *q) af1 = a->ifa_addr->sa_family; af2 = b->ifa_addr->sa_family; - if (af1 < sizeof(e1->af_orders) / sizeof(e1->af_orders[0]) && - af2 < sizeof(e1->af_orders) / sizeof(e1->af_orders[0])) + if (af1 < ORDERS_SIZE(e1->af_orders) && + af2 < ORDERS_SIZE(e1->af_orders)) return (e1->af_orders[af2] - e1->af_orders[af1]); } return (0); } +#undef ORDERS_SIZE + static struct ifaddrs * sortifaddrs(struct ifaddrs *list, - int (*compare)(struct ifaddrs *, struct ifaddrs *, struct ifa_queue *), - struct ifa_queue *q) + int (*compare)(struct ifaddrs *, struct ifaddrs *, struct ifa_queue *), + struct ifa_queue *q) { - struct ifaddrs *right, *temp, *last, *result, *next, *tail; right = list; @@ -499,7 +502,8 @@ main(int argc, char *argv[]) sdl->sdl_alen != ETHER_ADDR_LEN) continue; } else { - if (ifa->ifa_addr->sa_family != afp->af_af) + if (ifa->ifa_addr->sa_family + != afp->af_af) continue; } } @@ -835,7 +839,7 @@ settunnel(const char *src, const char *dst, int s, const struct afswtch *afp) errx(1, "error in parsing address string: %s", gai_strerror(ecode)); - if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0) + if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0) errx(1, "error in parsing address string: %s", gai_strerror(ecode));