svn commit: r289987 - stable/9/sbin/ifconfig

Garrett Cooper ngie at FreeBSD.org
Mon Oct 26 03:48:17 UTC 2015


Author: ngie
Date: Mon Oct 26 03:48:14 2015
New Revision: 289987
URL: https://svnweb.freebsd.org/changeset/base/289987

Log:
  MFstable/10 r289986:
  
  MFC r288305:
  
  Replace N #defines with nitems to simplify ifconfig code slightly

Modified:
  stable/9/sbin/ifconfig/af_atalk.c
  stable/9/sbin/ifconfig/af_inet6.c
  stable/9/sbin/ifconfig/ifbridge.c
  stable/9/sbin/ifconfig/ifcarp.c
  stable/9/sbin/ifconfig/ifclone.c
  stable/9/sbin/ifconfig/ifconfig.c
  stable/9/sbin/ifconfig/iffib.c
  stable/9/sbin/ifconfig/ifgif.c
  stable/9/sbin/ifconfig/ifgre.c
  stable/9/sbin/ifconfig/ifgroup.c
  stable/9/sbin/ifconfig/ifieee80211.c
  stable/9/sbin/ifconfig/iflagg.c
  stable/9/sbin/ifconfig/ifmac.c
  stable/9/sbin/ifconfig/ifmedia.c
  stable/9/sbin/ifconfig/ifpfsync.c
  stable/9/sbin/ifconfig/ifvlan.c
Directory Properties:
  stable/9/   (props changed)
  stable/9/sbin/   (props changed)
  stable/9/sbin/ifconfig/   (props changed)

Modified: stable/9/sbin/ifconfig/af_atalk.c
==============================================================================
--- stable/9/sbin/ifconfig/af_atalk.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/af_atalk.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -32,7 +32,7 @@ static const char rcsid[] =
   "$FreeBSD$";
 #endif /* not lint */
 
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <net/if.h>
@@ -172,11 +172,9 @@ static struct afswtch af_atalk = {
 static __constructor void
 atalk_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	size_t i;
 
-	for (i = 0; i < N(atalk_cmds);  i++)
+	for (i = 0; i < nitems(atalk_cmds);  i++)
 		cmd_register(&atalk_cmds[i]);
 	af_register(&af_atalk);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/af_inet6.c
==============================================================================
--- stable/9/sbin/ifconfig/af_inet6.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/af_inet6.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -546,7 +546,6 @@ static struct option in6_Lopt = { .opt =
 static __constructor void
 inet6_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	size_t i;
 
 #ifndef RESCUE
@@ -554,9 +553,8 @@ inet6_ctor(void)
 		return;
 #endif
 
-	for (i = 0; i < N(inet6_cmds);  i++)
+	for (i = 0; i < nitems(inet6_cmds);  i++)
 		cmd_register(&inet6_cmds[i]);
 	af_register(&af_inet6);
 	opt_register(&in6_Lopt);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/ifbridge.c
==============================================================================
--- stable/9/sbin/ifconfig/ifbridge.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/ifbridge.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -749,11 +749,9 @@ static struct afswtch af_bridge = {
 static __constructor void
 bridge_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	int i;
 
-	for (i = 0; i < N(bridge_cmds);  i++)
+	for (i = 0; i < nitems(bridge_cmds);  i++)
 		cmd_register(&bridge_cmds[i]);
 	af_register(&af_bridge);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/ifcarp.c
==============================================================================
--- stable/9/sbin/ifconfig/ifcarp.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/ifcarp.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -214,11 +214,9 @@ static struct afswtch af_carp = {
 static __constructor void
 carp_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	int i;
 
-	for (i = 0; i < N(carp_cmds);  i++)
+	for (i = 0; i < nitems(carp_cmds);  i++)
 		cmd_register(&carp_cmds[i]);
 	af_register(&af_carp);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/ifclone.c
==============================================================================
--- stable/9/sbin/ifconfig/ifclone.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/ifclone.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -32,9 +32,9 @@ static const char rcsid[] =
   "$FreeBSD$";
 #endif /* not lint */
 
-#include <sys/queue.h>
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/ioctl.h>
+#include <sys/queue.h>
 #include <sys/socket.h>
 #include <net/if.h>
 
@@ -184,11 +184,9 @@ static struct option clone_Copt = { .opt
 static __constructor void
 clone_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	size_t i;
 
-	for (i = 0; i < N(clone_cmds);  i++)
+	for (i = 0; i < nitems(clone_cmds);  i++)
 		cmd_register(&clone_cmds[i]);
 	opt_register(&clone_Copt);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/ifconfig.c
==============================================================================
--- stable/9/sbin/ifconfig/ifconfig.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/ifconfig.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -43,10 +43,10 @@ static const char rcsid[] =
 
 #include <sys/param.h>
 #include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/time.h>
 #include <sys/module.h>
 #include <sys/linker.h>
+#include <sys/socket.h>
+#include <sys/time.h>
 
 #include <net/ethernet.h>
 #include <net/if.h>
@@ -431,7 +431,6 @@ cmd_register(struct cmd *p)
 static const struct cmd *
 cmd_lookup(const char *name, int iscreate)
 {
-#define	N(a)	(sizeof(a)/sizeof(a[0]))
 	const struct cmd *p;
 
 	for (p = cmds; p != NULL; p = p->c_next)
@@ -445,7 +444,6 @@ cmd_lookup(const char *name, int iscreat
 			}
 		}
 	return NULL;
-#undef N
 }
 
 struct callback {
@@ -1210,10 +1208,8 @@ static struct cmd basic_cmds[] = {
 static __constructor void
 ifconfig_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	size_t i;
 
-	for (i = 0; i < N(basic_cmds);  i++)
+	for (i = 0; i < nitems(basic_cmds);  i++)
 		cmd_register(&basic_cmds[i]);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/iffib.c
==============================================================================
--- stable/9/sbin/ifconfig/iffib.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/iffib.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -93,11 +93,9 @@ static struct afswtch af_fib = {
 static __constructor void
 fib_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	size_t i;
 
-	for (i = 0; i < N(fib_cmds);  i++)
+	for (i = 0; i < nitems(fib_cmds);  i++)
 		cmd_register(&fib_cmds[i]);
 	af_register(&af_fib);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/ifgif.c
==============================================================================
--- stable/9/sbin/ifconfig/ifgif.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/ifgif.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -108,11 +108,9 @@ static struct afswtch af_gif = {
 static __constructor void
 gif_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	size_t i;
 
-	for (i = 0; i < N(gif_cmds); i++)
+	for (i = 0; i < nitems(gif_cmds); i++)
 		cmd_register(&gif_cmds[i]);
 	af_register(&af_gif);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/ifgre.c
==============================================================================
--- stable/9/sbin/ifconfig/ifgre.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/ifgre.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -88,11 +88,9 @@ static struct afswtch af_gre = {
 static __constructor void
 gre_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	size_t i;
 
-	for (i = 0; i < N(gre_cmds);  i++)
+	for (i = 0; i < nitems(gre_cmds);  i++)
 		cmd_register(&gre_cmds[i]);
 	af_register(&af_gre);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/ifgroup.c
==============================================================================
--- stable/9/sbin/ifconfig/ifgroup.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/ifgroup.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -28,7 +28,7 @@ static const char rcsid[] =
   "$FreeBSD$";
 #endif /* not lint */
 
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <net/if.h>
@@ -175,12 +175,10 @@ static struct option group_gopt = { "g:"
 static __constructor void
 group_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	int i;
 
-	for (i = 0; i < N(group_cmds);  i++)
+	for (i = 0; i < nitems(group_cmds);  i++)
 		cmd_register(&group_cmds[i]);
 	af_register(&af_group);
 	opt_register(&group_gopt);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/ifieee80211.c
==============================================================================
--- stable/9/sbin/ifconfig/ifieee80211.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/ifieee80211.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -2820,7 +2820,6 @@ printrsnie(const char *tag, const u_int8
 static void
 printwpsie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	u_int8_t len = ie[1];
 
 	printf("%s", tag);
@@ -2861,7 +2860,7 @@ printwpsie(const char *tag, const u_int8
 				break;
 			case IEEE80211_WPS_DEV_PASS_ID:
 				n = LE_READ_2(ie);
-				if (n < N(dev_pass_id))
+				if (n < nitems(dev_pass_id))
 					printf(" dpi:%s", dev_pass_id[n]);
 				break;
 			case IEEE80211_WPS_UUID_E:
@@ -2875,7 +2874,6 @@ printwpsie(const char *tag, const u_int8
 		}
 		printf(">");
 	}
-#undef N
 }
 
 static void
@@ -3382,7 +3380,6 @@ list_stations(int s)
 static const char *
 mesh_linkstate_string(uint8_t state)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	static const char *state_names[] = {
 	    [0] = "IDLE",
 	    [1] = "OPEN-TX",
@@ -3392,13 +3389,12 @@ mesh_linkstate_string(uint8_t state)
 	    [5] = "HOLDING",
 	};
 
-	if (state >= N(state_names)) {
+	if (state >= nitems(state_names)) {
 		static char buf[10];
 		snprintf(buf, sizeof(buf), "#%u", state);
 		return buf;
 	} else
 		return state_names[state];
-#undef N
 }
 
 static const char *
@@ -5266,12 +5262,10 @@ static struct afswtch af_ieee80211 = {
 static __constructor void
 ieee80211_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	int i;
 
-	for (i = 0; i < N(ieee80211_cmds);  i++)
+	for (i = 0; i < nitems(ieee80211_cmds);  i++)
 		cmd_register(&ieee80211_cmds[i]);
 	af_register(&af_ieee80211);
 	clone_setdefcallback("wlan", wlan_create);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/iflagg.c
==============================================================================
--- stable/9/sbin/ifconfig/iflagg.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/iflagg.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -236,11 +236,9 @@ static struct afswtch af_lagg = {
 static __constructor void
 lagg_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	int i;
 
-	for (i = 0; i < N(lagg_cmds);  i++)
+	for (i = 0; i < nitems(lagg_cmds);  i++)
 		cmd_register(&lagg_cmds[i]);
 	af_register(&af_lagg);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/ifmac.c
==============================================================================
--- stable/9/sbin/ifconfig/ifmac.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/ifmac.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -111,11 +111,9 @@ static struct afswtch af_mac = {
 static __constructor void
 mac_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	size_t i;
 
-	for (i = 0; i < N(mac_cmds);  i++)
+	for (i = 0; i < nitems(mac_cmds);  i++)
 		cmd_register(&mac_cmds[i]);
 	af_register(&af_mac);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/ifmedia.c
==============================================================================
--- stable/9/sbin/ifconfig/ifmedia.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/ifmedia.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -825,11 +825,9 @@ static struct afswtch af_media = {
 static __constructor void
 ifmedia_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	size_t i;
 
-	for (i = 0; i < N(media_cmds);  i++)
+	for (i = 0; i < nitems(media_cmds);  i++)
 		cmd_register(&media_cmds[i]);
 	af_register(&af_media);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/ifpfsync.c
==============================================================================
--- stable/9/sbin/ifconfig/ifpfsync.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/ifpfsync.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -26,7 +26,7 @@
  * $FreeBSD$
  */
 
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 
@@ -205,11 +205,9 @@ static struct afswtch af_pfsync = {
 static __constructor void
 pfsync_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	int i;
 
-	for (i = 0; i < N(pfsync_cmds);  i++)
+	for (i = 0; i < nitems(pfsync_cmds);  i++)
 		cmd_register(&pfsync_cmds[i]);
 	af_register(&af_pfsync);
-#undef N
 }

Modified: stable/9/sbin/ifconfig/ifvlan.c
==============================================================================
--- stable/9/sbin/ifconfig/ifvlan.c	Mon Oct 26 03:43:28 2015	(r289986)
+++ stable/9/sbin/ifconfig/ifvlan.c	Mon Oct 26 03:48:14 2015	(r289987)
@@ -195,13 +195,11 @@ static struct afswtch af_vlan = {
 static __constructor void
 vlan_ctor(void)
 {
-#define	N(a)	(sizeof(a) / sizeof(a[0]))
 	size_t i;
 
-	for (i = 0; i < N(vlan_cmds);  i++)
+	for (i = 0; i < nitems(vlan_cmds);  i++)
 		cmd_register(&vlan_cmds[i]);
 	af_register(&af_vlan);
 	callback_register(vlan_cb, NULL);
 	clone_setdefcallback("vlan", vlan_create);
-#undef N
 }


More information about the svn-src-stable-9 mailing list