From abaa592c74adc23b06d51b902bbf6b11032af2cb Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Sun, 18 Feb 2018 01:02:08 +0100
Subject: [PATCH] NELEM WIP

---
 bin/df/df.c                                  |  2 +-
 lib/libcam/camlib.c                          |  2 +-
 lib/libcrypt/crypt-sha256.c                  |  4 ++--
 lib/libcrypt/crypt-sha512.c                  |  4 ++--
 lib/libipsec/pfkey.c                         |  6 ++----
 lib/libipsec/test-policy.c                   |  3 +--
 lib/libstand/ext2fs.c                        |  4 +---
 libexec/bootpd/hwaddr.c                      |  2 +-
 libexec/bootpd/tools/bootptest/print-bootp.c |  2 +-
 libexec/pppoed/pppoed.c                      |  3 +--
 libexec/rbootd/bpf.c                         |  2 +-
 libexec/rpc.rstatd/rstat_proc.c              |  2 +-
 libexec/talkd/print.c                        |  4 ++--
 sbin/fsdb/fsdb.c                             |  6 ++----
 sbin/ifconfig/ifbridge.c                     |  3 +--
 sbin/ifconfig/iflagg.c                       |  6 +++---
 sbin/kldconfig/kldconfig.c                   |  2 +-
 sbin/natd/natd.c                             |  4 ++--
 sbin/ping6/ping6.c                           |  2 +-
 sys/net/lagg/if_lagg.c                       |  3 +--
 test/testcases/crypto/aesctr/aesctr.c        |  2 +-
 test/testcases/crypto/aesxts/aes_xts.c       |  2 +-
 usr.bin/at/at.c                              |  2 +-
 usr.bin/gzip/gzip.c                          |  2 +-
 usr.bin/kdump/kdump.c                        |  3 +--
 usr.bin/netstat/ipsec.c                      |  3 +--
 usr.bin/rpcgen/rpc_main.c                    |  4 ++--
 usr.bin/systat/main.c                        |  5 ++---
 usr.bin/systat/mbufs.c                       |  2 +-
 usr.bin/systat/sensors.c                     |  2 +-
 usr.bin/talk/invite.c                        |  2 +-
 usr.bin/top/m_dragonfly.c                    |  3 +--
 usr.bin/uname/uname.c                        |  2 +-
 usr.bin/uuencode/uuencode.c                  |  3 +--
 usr.bin/ypcat/ypcat.c                        |  4 ++--
 usr.bin/ypmatch/ypmatch.c                    |  4 ++--
 usr.bin/ypwhich/ypwhich.c                    |  4 ++--
 usr.sbin/boot0cfg/boot0cfg.c                 |  4 ++--
 usr.sbin/config/main.c                       |  2 +-
 usr.sbin/cpucontrol/cpucontrol.c             |  2 +-
 usr.sbin/makewhatis/makewhatis.c             |  2 +-
 usr.sbin/moused/moused.c                     |  6 +++---
 usr.sbin/ndp/ndp.c                           |  8 ++++----
 usr.sbin/pfctl/pfctl_parser.c                | 24 ++++++++----------------
 usr.sbin/ppp/bundle.c                        |  3 +--
 usr.sbin/ppp/cbcp.c                          |  5 ++---
 usr.sbin/ppp/ccp.c                           |  5 ++---
 usr.sbin/ppp/chap.c                          |  3 +--
 usr.sbin/ppp/command.c                       | 12 ++++++------
 usr.sbin/ppp/datalink.c                      |  4 ++--
 usr.sbin/ppp/defs.c                          |  2 +-
 usr.sbin/ppp/filter.c                        |  4 ++--
 usr.sbin/ppp/fsm.c                           |  6 +++---
 usr.sbin/ppp/hdlc.c                          |  3 +--
 usr.sbin/ppp/iface.c                         |  2 +-
 usr.sbin/ppp/ip.c                            |  4 ++--
 usr.sbin/ppp/ipcp.c                          |  3 +--
 usr.sbin/ppp/ipv6cp.c                        |  2 +-
 usr.sbin/ppp/lcp.c                           |  3 +--
 usr.sbin/ppp/main.c                          |  5 ++---
 usr.sbin/ppp/ncp.c                           |  4 +---
 usr.sbin/ppp/pap.c                           |  3 +--
 usr.sbin/ppp/physical.c                      |  2 +-
 usr.sbin/pstat/pstat.c                       |  2 +-
 usr.sbin/rarpd/rarpd.c                       |  2 +-
 usr.sbin/rtsold/if.c                         |  3 +--
 usr.sbin/rwhod/rwhod.c                       |  2 +-
 usr.sbin/setkey/test-policy.c                |  3 +--
 usr.sbin/syslogd/syslogd.c                   |  2 +-
 usr.sbin/traceroute/traceroute.c             |  2 +-
 usr.sbin/traceroute6/traceroute6.c           |  2 +-
 71 files changed, 110 insertions(+), 146 deletions(-)

diff --git a/bin/df/df.c b/bin/df/df.c
index 15e5f8c99e..c4ebc4145e 100644
--- a/bin/df/df.c
+++ b/bin/df/df.c
@@ -513,7 +513,7 @@ makenetvfslist(void)
 
 	mib[0] = CTL_VFS; mib[1] = VFS_GENERIC; mib[2] = VFS_MAXTYPENUM;
 	miblen=sizeof(maxvfsconf);
-	if (sysctl(mib, (unsigned int)(sizeof(mib) / sizeof(mib[0])),
+	if (sysctl(mib, (unsigned int)(NELEM(mib)),
 	    &maxvfsconf, &miblen, NULL, 0)) {
 		warnx("sysctl failed");
 		return (NULL);
diff --git a/lib/libcam/camlib.c b/lib/libcam/camlib.c
index 5ffd8e8f4a..febd00d96a 100644
--- a/lib/libcam/camlib.c
+++ b/lib/libcam/camlib.c
@@ -285,7 +285,7 @@ cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
 	 * the user gave us is an old style device name.  If so, translate
 	 * it to the new style device name.
 	 */
-	for (i = 0;i < (sizeof(devmatchtable)/sizeof(struct cam_devequiv));i++){
+	for (i = 0; i < NELEM(devmatchtable); i++) {
 		if (strcmp(tmpstr, devmatchtable[i].given_dev) == 0) {
 			strlcpy(dev_name,devmatchtable[i].real_dev, devnamelen);
 			found = 1;
diff --git a/lib/libcrypt/crypt-sha256.c b/lib/libcrypt/crypt-sha256.c
index 1f7f7e3b8e..dbd17717ff 100644
--- a/lib/libcrypt/crypt-sha256.c
+++ b/lib/libcrypt/crypt-sha256.c
@@ -606,7 +606,7 @@ static const struct
       "\xf3\x71\xbc\x4a\x31\x1f\x2b\x00\x9e\xef\x95\x2d\xd8\x3c\xa8\x0e"
       "\x2b\x60\x02\x6c\x8e\x93\x55\x92\xd0\xf9\xc3\x08\x45\x3c\x81\x3e" }
   };
-#define ntests (sizeof (tests) / sizeof (tests[0]))
+#define ntests (NELEM(tests))
 
 
 static const struct
@@ -639,7 +639,7 @@ static const struct
     "$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY9l/gL97"
     "2bIC" },
 };
-#define ntests2 (sizeof (tests2) / sizeof (tests2[0]))
+#define ntests2 (NELEM(tests2))
 
 
 int
diff --git a/lib/libcrypt/crypt-sha512.c b/lib/libcrypt/crypt-sha512.c
index c11fc804c8..78a2f932ea 100644
--- a/lib/libcrypt/crypt-sha512.c
+++ b/lib/libcrypt/crypt-sha512.c
@@ -672,7 +672,7 @@ static const struct
       "\x23\x54\xe0\x93\xd7\x6f\x30\x48\xb4\x56\x76\x43\x46\x90\x0c\xb1"
       "\x30\xd2\xa4\xfd\x5d\xd1\x6a\xbb\x5e\x30\xbc\xb8\x50\xde\xe8\x43" }
   };
-#define ntests (sizeof (tests) / sizeof (tests[0]))
+#define ntests (NELEM(tests))
 
 
 static const struct
@@ -707,7 +707,7 @@ static const struct
     "$6$rounds=1000$roundstoolow$kUMsbe306n21p9R.FRkW3IGn.S9NPN0x50YhH1x"
     "hLsPuWGsUSklZt58jaTfF4ZEQpyUNGc0dqbpBYYBaHHrsX." },
 };
-#define ntests2 (sizeof (tests2) / sizeof (tests2[0]))
+#define ntests2 (NELEM(tests2))
 
 
 int
diff --git a/lib/libipsec/pfkey.c b/lib/libipsec/pfkey.c
index bd111ba30b..8baec1bc0e 100644
--- a/lib/libipsec/pfkey.c
+++ b/lib/libipsec/pfkey.c
@@ -92,7 +92,7 @@ findsupportedmap(int satype)
 {
 	int i;
 
-	for (i = 0; i < sizeof(supported_map)/sizeof(supported_map[0]); i++)
+	for (i = 0; i < NELEM(supported_map); i++)
 		if (supported_map[i] == satype)
 			return i;
 	return -1;
@@ -623,9 +623,7 @@ pfkey_send_register(int so, u_int satype)
 	int len, algno;
 
 	if (satype == PF_UNSPEC) {
-		for (algno = 0;
-		     algno < sizeof(supported_map)/sizeof(supported_map[0]);
-		     algno++) {
+		for (algno = 0; algno < NELEM(supported_map); algno++) {
 			if (ipsec_supported[algno]) {
 				free(ipsec_supported[algno]);
 				ipsec_supported[algno] = NULL;
diff --git a/lib/libipsec/test-policy.c b/lib/libipsec/test-policy.c
index db0dcb4be4..865d24394b 100644
--- a/lib/libipsec/test-policy.c
+++ b/lib/libipsec/test-policy.c
@@ -1,5 +1,4 @@
 /*	$FreeBSD: src/lib/libipsec/test-policy.c,v 1.2.2.2 2001/07/03 11:01:15 ume Exp $	*/
-/*	$DragonFly: src/lib/libipsec/test-policy.c,v 1.3 2003/11/12 20:21:30 eirikn Exp $	*/
 /*	$KAME: test-policy.c,v 1.14 2000/12/27 11:38:11 sakane Exp $	*/
 
 /*
@@ -109,7 +108,7 @@ test1()
 	int result;
 
 	printf("TEST1\n");
-	for (i = 0; i < sizeof(reqs)/sizeof(reqs[0]); i++) {
+	for (i = 0; i < NELEM(reqs); i++) {
 		printf("#%d [%s]\n", i + 1, reqs[i].str);
 
 		result = test1sub1(&reqs[i]);
diff --git a/lib/libstand/ext2fs.c b/lib/libstand/ext2fs.c
index 38abafdd71..bca12c14b3 100644
--- a/lib/libstand/ext2fs.c
+++ b/lib/libstand/ext2fs.c
@@ -24,7 +24,6 @@
  * SUCH DAMAGE.
  *
  *	$FreeBSD: src/lib/libstand/ext2fs.c,v 1.1.2.2 2001/03/05 06:26:07 kris Exp $
- *	$DragonFly: src/lib/libstand/ext2fs.c,v 1.2 2003/06/17 04:26:51 dillon Exp $
  */
 /*-
  * Copyright (c) 1993
@@ -99,8 +98,7 @@ static int	ext2fs_readdir(struct open_file *f, struct dirent *d);
 
 static int dtmap[] = { DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR,
 			 DT_BLK, DT_FIFO, DT_SOCK, DT_LNK };
-#define EXTFTODT(x)	(x) > sizeof(dtmap) / sizeof(dtmap[0]) ? \
-			DT_UNKNOWN : dtmap[x]
+#define EXTFTODT(x)	(x) > NELEM(dtmap) ? DT_UNKNOWN : dtmap[(x)]
 
 struct fs_ops ext2fs_fsops = {
 	"ext2fs",
diff --git a/libexec/bootpd/hwaddr.c b/libexec/bootpd/hwaddr.c
index ccc3e6c501..8f12ed822c 100644
--- a/libexec/bootpd/hwaddr.c
+++ b/libexec/bootpd/hwaddr.c
@@ -81,7 +81,7 @@ struct hwinfo hwinfolist[] =
 	{6, "IEEE 802"},			/* Type 6:  IEEE 802 Networks		*/
 	{0, "ARCNET"}				/* Type 7:  ARCNET			*/
 };
-int hwinfocnt = sizeof(hwinfolist) / sizeof(hwinfolist[0]);
+int hwinfocnt = NELEM(hwinfolist);
 
 
 /*
diff --git a/libexec/bootpd/tools/bootptest/print-bootp.c b/libexec/bootpd/tools/bootptest/print-bootp.c
index 3e477ba612..4f7fbff6b6 100644
--- a/libexec/bootpd/tools/bootptest/print-bootp.c
+++ b/libexec/bootpd/tools/bootptest/print-bootp.c
@@ -268,7 +268,7 @@ rfc1048_opts[] = {
 	/* DHCP extensions (RFC-1533, sect. 9) */
 #endif
 };
-#define	KNOWN_OPTIONS (sizeof(rfc1048_opts) / sizeof(rfc1048_opts[0]))
+#define	KNOWN_OPTIONS NELEM(rfc1048_opts)
 
 static void
 rfc1048_print(u_char *bp, int length)
diff --git a/libexec/pppoed/pppoed.c b/libexec/pppoed/pppoed.c
index d856c3394c..8d32e74fa7 100644
--- a/libexec/pppoed/pppoed.c
+++ b/libexec/pppoed/pppoed.c
@@ -24,7 +24,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/libexec/pppoed/pppoed.c,v 1.2.6.8 2002/06/17 02:21:25 brian Exp $
- * $DragonFly: src/libexec/pppoed/pppoed.c,v 1.4 2007/06/04 00:40:31 swildner Exp $
  */
 
 #include <sys/param.h>
@@ -465,7 +464,7 @@ LoadModules(void)
   const char *module[] = { "netgraph", "ng_socket", "ng_ether", "ng_pppoe" };
   size_t f;
 
-  for (f = 0; f < sizeof module / sizeof *module; f++)
+  for (f = 0; f < NELEM(module); f++)
     if (modfind(module[f]) == -1 && kldload(module[f]) == -1) {
       fprintf(stderr, "kldload: %s: %s\n", module[f], strerror(errno));
       return 0;
diff --git a/libexec/rbootd/bpf.c b/libexec/rbootd/bpf.c
index 4e74830879..9f220836fa 100644
--- a/libexec/rbootd/bpf.c
+++ b/libexec/rbootd/bpf.c
@@ -180,7 +180,7 @@ BpfOpen(void)
 		};
 #undef	RMP
 		static struct bpf_program bpf_pgm = {
-		    sizeof(bpf_insn)/sizeof(bpf_insn[0]), bpf_insn
+		    NELEM(bpf_insn), bpf_insn
 		};
 
 		if (ioctl(BpfFd, BIOCSETF, (caddr_t)&bpf_pgm) < 0) {
diff --git a/libexec/rpc.rstatd/rstat_proc.c b/libexec/rpc.rstatd/rstat_proc.c
index 5a5e80f0ac..cfe93426fd 100644
--- a/libexec/rpc.rstatd/rstat_proc.c
+++ b/libexec/rpc.rstatd/rstat_proc.c
@@ -199,7 +199,7 @@ updatestat(void)
 	stats_all.s1.cp_time[2] = cp_time.cp_sys;
 	stats_all.s1.cp_time[3] = cp_time.cp_idle;
 
-        (void)getloadavg(avrun, sizeof(avrun) / sizeof(avrun[0]));
+        (void)getloadavg(avrun, NELEM(avrun));
 
 	stats_all.s2.avenrun[0] = avrun[0] * FSCALE;
 	stats_all.s2.avenrun[1] = avrun[1] * FSCALE;
diff --git a/libexec/talkd/print.c b/libexec/talkd/print.c
index 74f1d679ab..faf6c8a300 100644
--- a/libexec/talkd/print.c
+++ b/libexec/talkd/print.c
@@ -43,11 +43,11 @@
 
 static	const char *types[] =
     { "leave_invite", "look_up", "delete", "announce" };
-#define	NTYPES	(sizeof (types) / sizeof (types[0]))
+#define	NTYPES	NELEM(types)
 static	const char *answers[] =
     { "success", "not_here", "failed", "machine_unknown", "permission_denied",
       "unknown_request", "badversion", "badaddr", "badctladdr" };
-#define	NANSWERS	(sizeof (answers) / sizeof (answers[0]))
+#define	NANSWERS	NELEM(answers)
 
 void
 print_request(const char *cp, CTL_MSG *mp)
diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c
index 36d13e2466..667ae84d49 100644
--- a/sbin/fsdb/fsdb.c
+++ b/sbin/fsdb/fsdb.c
@@ -612,16 +612,14 @@ CMDFUNCSTART(newtype)
     if (!checkactive())
 	return 1;
     type = curinode->di_mode & IFMT;
-    for (tp = typenamemap;
-	 tp < &typenamemap[sizeof(typenamemap)/sizeof(*typenamemap)];
-	 tp++) {
+    for (tp = typenamemap; tp < &typenamemap[NELEM(typenamemap)]; tp++) {
 	if (!strcmp(argv[1], tp->typename)) {
 	    printf("setting type to %s\n", tp->typename);
 	    type = tp->typebits;
 	    break;
 	}
     }
-    if (tp == &typenamemap[sizeof(typenamemap)/sizeof(*typenamemap)]) {
+    if (tp == &typenamemap[NELEM(typenamemap)]) {
 	warnx("type `%s' not known", argv[1]);
 	warnx("try one of `file', `dir', `socket', `fifo'");
 	return 1;
diff --git a/sbin/ifconfig/ifbridge.c b/sbin/ifconfig/ifbridge.c
index 4b0409cffd..f508fd1303 100644
--- a/sbin/ifconfig/ifbridge.c
+++ b/sbin/ifconfig/ifbridge.c
@@ -156,8 +156,7 @@ bridge_interfaces(int s, const char *prefix)
 			printf("port %u priority %u",
 			    req->ifbr_portno, req->ifbr_priority);
 			printf(" pathcost %u", req->ifbr_path_cost);
-			if (req->ifbr_state <
-			    sizeof(stpstates) / sizeof(stpstates[0]))
+			if (req->ifbr_state < NELEM(stpstates))
 				printf(" %s", stpstates[req->ifbr_state]);
 			else
 				printf(" <unknown state %d>",
diff --git a/sbin/ifconfig/iflagg.c b/sbin/ifconfig/iflagg.c
index 084be6d5e0..ba2b5ef3a1 100644
--- a/sbin/ifconfig/iflagg.c
+++ b/sbin/ifconfig/iflagg.c
@@ -64,7 +64,7 @@ setlaggproto(const char *val, int d, int s, const struct afswtch *afp)
 	bzero(&ra, sizeof(ra));
 	ra.ra_proto = LAGG_PROTO_MAX;
 
-	for (i = 0; i < (sizeof(lpr) / sizeof(lpr[0])); i++) {
+	for (i = 0; i < (NELEM(lpr)); i++) {
 		if (strcmp(val, lpr[i].lpr_name) == 0) {
 			ra.ra_proto = lpr[i].lpr_proto;
 			break;
@@ -165,7 +165,7 @@ lagg_status(int s)
 	if (ioctl(s, SIOCGLAGG, &ra) == 0) {
 		lp = (struct lacp_opreq *)&ra.ra_lacpreq;
 
-		for (i = 0; i < (sizeof(lpr) / sizeof(lpr[0])); i++) {
+		for (i = 0; i < (NELEM(lpr)); i++) {
 			if (ra.ra_proto == lpr[i].lpr_proto) {
 				proto = lpr[i].lpr_name;
 				break;
@@ -211,7 +211,7 @@ lagg_status(int s)
 
 		if (0 /* XXX */) {
 			printf("\tsupported aggregation protocols:\n");
-			for (i = 0; i < (sizeof(lpr) / sizeof(lpr[0])); i++)
+			for (i = 0; i < (NELEM(lpr)); i++)
 				printf("\t\tlaggproto %s\n", lpr[i].lpr_name);
 		}
 	}
diff --git a/sbin/kldconfig/kldconfig.c b/sbin/kldconfig/kldconfig.c
index 4d32861226..01a75a1284 100644
--- a/sbin/kldconfig/kldconfig.c
+++ b/sbin/kldconfig/kldconfig.c
@@ -86,7 +86,7 @@ getmib(void)
 	if (miblen != 0)
 		return;
 	
-	miblen = sizeof(mib) / sizeof(mib[0]);
+	miblen = NELEM(mib);
 	if (sysctlnametomib(pathctl, mib, &miblen) != 0)
 		err(1, "sysctlnametomib(%s)", pathctl);
 }
diff --git a/sbin/natd/natd.c b/sbin/natd/natd.c
index c1684f846b..bde82f7964 100644
--- a/sbin/natd/natd.c
+++ b/sbin/natd/natd.c
@@ -1079,7 +1079,7 @@ ParseOption(const char *option, const char *parms)
 /*
  * Find option from table.
  */
-	max = sizeof(optionTable) / sizeof(struct OptionInfo);
+	max = NELEM(optionTable);
 	for (i = 0, info = optionTable; i < max; i++, info++) {
 		if (!strcmp(info->name, option))
 			break;
@@ -1316,7 +1316,7 @@ Usage(void)
 
 	fprintf(stderr, "Recognized options:\n\n");
 
-	max = sizeof(optionTable) / sizeof(struct OptionInfo);
+	max = NELEM(optionTable);
 	for (i = 0, info = optionTable; i < max; i++, info++) {
 		fprintf(stderr, "-%-20s %s\n", info->name,
 						info->parmDescription);
diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c
index 599dd60774..8fa42bd8e1 100644
--- a/sbin/ping6/ping6.c
+++ b/sbin/ping6/ping6.c
@@ -2349,7 +2349,7 @@ pr_icmph(struct icmp6_hdr *icp, u_char *end)
 			break;
 		}
 		if (options & F_VERBOSE) {
-			if (ni->ni_code > sizeof(nircode) / sizeof(nircode[0]))
+			if (ni->ni_code > NELEM(nircode))
 				printf(", invalid");
 			else
 				printf(", %s", nircode[ni->ni_code]);
diff --git a/sys/net/lagg/if_lagg.c b/sys/net/lagg/if_lagg.c
index 73c1fbf2b0..d911c42a2a 100644
--- a/sys/net/lagg/if_lagg.c
+++ b/sys/net/lagg/if_lagg.c
@@ -1106,8 +1106,7 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
 			LAGG_WUNLOCK(sc);
 			break;
 		}
-		for (int i = 0; i < (sizeof(lagg_protos) /
-		    sizeof(lagg_protos[0])); i++) {
+		for (int i = 0; i < (NELEM(lagg_protos)); i++) {
 			if (lagg_protos[i].ti_proto == ra->ra_proto) {
 				if (sc->sc_ifflags & IFF_DEBUG)
 					kprintf("%s: using proto %u\n",
diff --git a/test/testcases/crypto/aesctr/aesctr.c b/test/testcases/crypto/aesctr/aesctr.c
index f5261cdb99..f260ab73c3 100644
--- a/test/testcases/crypto/aesctr/aesctr.c
+++ b/test/testcases/crypto/aesctr/aesctr.c
@@ -287,7 +287,7 @@ main(int argc, char **argv)
 		if (allowed == 0)
 			setallowsoft(1);
 	}
-	for (i = 0; i < (sizeof(tests) / sizeof(tests[0])); i++)
+	for (i = 0; i < NELEM(tests); i++)
 		fail += run(i);
 	if (geteuid() == 0 && allowed == 0)
 		setallowsoft(0);
diff --git a/test/testcases/crypto/aesxts/aes_xts.c b/test/testcases/crypto/aesxts/aes_xts.c
index 112cc3016e..2553583b84 100644
--- a/test/testcases/crypto/aesxts/aes_xts.c
+++ b/test/testcases/crypto/aesxts/aes_xts.c
@@ -1795,7 +1795,7 @@ struct aes_xts_tv aes_xts_test_vectors[] = {
 		},
 	},
 };
-#define N_VECTORS (sizeof(aes_xts_test_vectors) / sizeof(*aes_xts_test_vectors))
+#define N_VECTORS NELEM(aes_xts_test_vectors)
 
 int
 main(int argc, char **argv)
diff --git a/usr.bin/at/at.c b/usr.bin/at/at.c
index 15ae6fae03..1ba8cd575c 100644
--- a/usr.bin/at/at.c
+++ b/usr.bin/at/at.c
@@ -356,7 +356,7 @@ writefile(time_t runtimer, char queue)
 	else
 	{
 	    size_t i;
-	    for (i=0; i<sizeof(no_export)/sizeof(no_export[0]); i++)
+	    for (i=0; i<NELEM(no_export); i++)
 	    {
 		export = export
 		    && (strncmp(*atenv, no_export[i], 
diff --git a/usr.bin/gzip/gzip.c b/usr.bin/gzip/gzip.c
index c26b74ba41..d2b937dfc9 100644
--- a/usr.bin/gzip/gzip.c
+++ b/usr.bin/gzip/gzip.c
@@ -142,7 +142,7 @@ static suffixes_t suffixes[] = {
 #endif /* SMALL */
 #undef SUFFIX
 };
-#define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
+#define NUM_SUFFIXES NELEM(suffixes)
 
 #define SUFFIX_MAXLEN  30
 
diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c
index 955ba2bad7..11d3bd548d 100644
--- a/usr.bin/kdump/kdump.c
+++ b/usr.bin/kdump/kdump.c
@@ -690,8 +690,7 @@ ktrsyscall(struct ktr_syscall *ktr)
 				ip++;
 				narg--;
 			} else if (ktr->ktr_code == SYS_ptrace) {
-				if (*ip < (register_t)(sizeof(ptrace_ops) /
-				    sizeof(ptrace_ops[0])) && *ip >= 0)
+				if (*ip < (register_t)NELEM(ptrace_ops) && *ip >= 0)
 					printf("(%s", ptrace_ops[*ip]);
 #ifdef PT_GETREGS
 				else if (*ip == PT_GETREGS)
diff --git a/usr.bin/netstat/ipsec.c b/usr.bin/netstat/ipsec.c
index 218bcc9da4..b2570df5b7 100644
--- a/usr.bin/netstat/ipsec.c
+++ b/usr.bin/netstat/ipsec.c
@@ -239,8 +239,7 @@ ipsec_stats(u_long off __unused, const char *name, int af1 __unused)
 static const char *
 pfkey_msgtype_names(int x)
 {
-	const int max =
-	    sizeof(pfkey_msgtypenames)/sizeof(pfkey_msgtypenames[0]);
+	const int max = NELEM(pfkey_msgtypenames);
 	static char buf[10];
 
 	if (x < max && pfkey_msgtypenames[x])
diff --git a/usr.bin/rpcgen/rpc_main.c b/usr.bin/rpcgen/rpc_main.c
index 5a962689e5..1bb3fffe1e 100644
--- a/usr.bin/rpcgen/rpc_main.c
+++ b/usr.bin/rpcgen/rpc_main.c
@@ -78,11 +78,11 @@ static char pathbuf[MAXPATHLEN + 1];
 static const char *allv[] = {
 	"rpcgen", "-s", "udp", "-s", "tcp",
 };
-static int allc = sizeof (allv)/sizeof (allv[0]);
+static int allc = NELEM(allv);
 static const char *allnv[] = {
 	"rpcgen", "-s", "netpath",
 };
-static int allnc = sizeof (allnv)/sizeof (allnv[0]);
+static int allnc = NELEM(allnv);
 
 /*
  * machinations for handling expanding argument list
diff --git a/usr.bin/systat/main.c b/usr.bin/systat/main.c
index 5593270534..12ff2a714b 100644
--- a/usr.bin/systat/main.c
+++ b/usr.bin/systat/main.c
@@ -29,7 +29,6 @@
  * @(#) Copyright (c) 1980, 1992, 1993 The Regents of the University of California.  All rights reserved.
  * @(#)main.c	8.1 (Berkeley) 6/6/93
  * $FreeBSD: src/usr.bin/systat/main.c,v 1.11.2.1 2001/06/06 20:26:01 tmm Exp $
- * $DragonFly: src/usr.bin/systat/main.c,v 1.7 2008/11/10 04:59:45 swildner Exp $
  */
 
 #include <sys/user.h>
@@ -173,7 +172,7 @@ display(int signo __unused)
 	struct itimerval ctv;
 
 	/* Get the load average over the last minute. */
-	(void) getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0]));
+	(void) getloadavg(avenrun, NELEM(avenrun));
 	(*curcmd->c_fetch)();
 	if (curcmd->c_flags & CF_LOADAV) {
 		j = 5.0*avenrun[0] + 0.5;
@@ -202,7 +201,7 @@ void
 load(void)
 {
 
-	(void) getloadavg(avenrun, sizeof(avenrun)/sizeof(avenrun[0]));
+	(void) getloadavg(avenrun, NELEM(avenrun));
 	mvprintw(CMDLINE, 0, "%4.1f %4.1f %4.1f",
 	    avenrun[0], avenrun[1], avenrun[2]);
 	clrtoeol();
diff --git a/usr.bin/systat/mbufs.c b/usr.bin/systat/mbufs.c
index db81f59695..ff5916349d 100644
--- a/usr.bin/systat/mbufs.c
+++ b/usr.bin/systat/mbufs.c
@@ -58,7 +58,7 @@ static struct mtnames {
 	{ MT_OOBDATA,	"oobdata"}
 };
 
-#define	NNAMES	(sizeof (mtnames) / sizeof (mtnames[0]))
+#define	NNAMES	NELEM(mtnames)
 
 WINDOW *
 openmbufs(void)
diff --git a/usr.bin/systat/sensors.c b/usr.bin/systat/sensors.c
index 6f5e5031e8..71dca9127f 100644
--- a/usr.bin/systat/sensors.c
+++ b/usr.bin/systat/sensors.c
@@ -227,7 +227,7 @@ printline(void)
 		break;
 	case SENSOR_DRIVE:
 		if (0 < sensor.value &&
-		    (size_t)sensor.value < sizeof(drvstat)/sizeof(drvstat[0])) {
+		    (size_t)sensor.value < NELEM(drvstat)) {
 			mvwprintw(wnd, row, 24, "%15s", drvstat[sensor.value]);
 			break;
 		}
diff --git a/usr.bin/talk/invite.c b/usr.bin/talk/invite.c
index 8256d85960..c2607bb39d 100644
--- a/usr.bin/talk/invite.c
+++ b/usr.bin/talk/invite.c
@@ -137,7 +137,7 @@ static	const char *answers[] = {
 	"Target machine indicates protocol botch (addr)",/* BADADDR */
 	"Target machine indicates protocol botch (ctl_addr)",/* BADCTLADDR */
 };
-#define	NANSWERS	(sizeof (answers) / sizeof (answers[0]))
+#define	NANSWERS	NELEM(answers)
 
 /*
  * Transmit the invitation and process the response
diff --git a/usr.bin/top/m_dragonfly.c b/usr.bin/top/m_dragonfly.c
index 7c0ffed24a..04b20c905e 100644
--- a/usr.bin/top/m_dragonfly.c
+++ b/usr.bin/top/m_dragonfly.c
@@ -710,8 +710,7 @@ format_next_process(caddr_t xhandle, char *(*get_userid) (int))
 		/* fall through */
 	default:
 
-		if (state >= 0 &&
-		    (unsigned)state < sizeof(state_abbrev) / sizeof(*state_abbrev))
+		if (state >= 0 && (unsigned)state < NELEM(state_abbrev))
 			sprintf(status, "%.6s", state_abbrev[(unsigned char)state]);
 		else
 			sprintf(status, "?%5d", state);
diff --git a/usr.bin/uname/uname.c b/usr.bin/uname/uname.c
index 05e00206a1..b872458a60 100644
--- a/usr.bin/uname/uname.c
+++ b/usr.bin/uname/uname.c
@@ -202,7 +202,7 @@ native_##var(void)				\
 	char **varp = &(var);			\
 						\
 	len = sizeof buf;			\
-	if (sysctl(mib, sizeof mib / sizeof mib[0],	\
+	if (sysctl(mib, NELEM(mib),		\
 	   &buf, &len, NULL, 0) == -1)		\
 		err(1, "sysctl");
 
diff --git a/usr.bin/uuencode/uuencode.c b/usr.bin/uuencode/uuencode.c
index 5f65c1a861..05505843ec 100644
--- a/usr.bin/uuencode/uuencode.c
+++ b/usr.bin/uuencode/uuencode.c
@@ -29,7 +29,6 @@
  * @(#) Copyright (c) 1983, 1993 The Regents of the University of California.  All rights reserved.
  * @(#)uuencode.c	8.2 (Berkeley) 4/2/94
  * $FreeBSD: src/usr.bin/uuencode/uuencode.c,v 1.4.2.5 2002/10/21 11:52:15 fanf Exp $
- * $DragonFly: src/usr.bin/uuencode/uuencode.c,v 1.3 2004/12/24 15:13:56 liamfoy Exp $
  */
 
 /*
@@ -146,7 +145,7 @@ base64_encode(void)
 	fprintf(output, "begin-base64 %o %s\n", mode, *av);
 	while ((n = fread(buf, 1, sizeof(buf), stdin))) {
 		++sequence;
-		rv = b64_ntop(buf, n, buf2, (sizeof(buf2) / sizeof(buf2[0])));
+		rv = b64_ntop(buf, n, buf2, NELEM(buf2));
 		if (rv == -1)
 			errx(1, "b64_ntop: error encoding base64");
 		fprintf(output, "%s%s", buf2, (sequence % GROUPS) ? "" : "\n");
diff --git a/usr.bin/ypcat/ypcat.c b/usr.bin/ypcat/ypcat.c
index ad973722dc..117508a0d6 100644
--- a/usr.bin/ypcat/ypcat.c
+++ b/usr.bin/ypcat/ypcat.c
@@ -96,7 +96,7 @@ main(int argc, char  *argv[])
 	while ((c = getopt(argc, argv, "xd:kt")) != -1)
 		switch (c) {
 		case 'x':
-			for (i = 0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+			for (i = 0; i < NELEM(ypaliases); i++)
 				printf("Use \"%s\" for \"%s\"\n",
 					ypaliases[i].alias,
 					ypaliases[i].name);
@@ -121,7 +121,7 @@ main(int argc, char  *argv[])
 		yp_get_default_domain(&domainname);
 
 	inmap = argv[optind];
-	for (i = 0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+	for (i = 0; (!notrans) && i < NELEM(ypaliases); i++)
 		if (strcmp(inmap, ypaliases[i].alias) == 0)
 			inmap = __DECONST(char *, ypaliases[i].name);
 	ypcb.foreach = printit;
diff --git a/usr.bin/ypmatch/ypmatch.c b/usr.bin/ypmatch/ypmatch.c
index ab84517c1f..af1ad706be 100644
--- a/usr.bin/ypmatch/ypmatch.c
+++ b/usr.bin/ypmatch/ypmatch.c
@@ -81,7 +81,7 @@ main(int argc, char *argv[])
 	while ((c = getopt(argc, argv, "xd:kt")) != -1)
 		switch (c) {
 		case 'x':
-			for (i = 0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+			for (i = 0; i < NELEM(ypaliases); i++)
 				printf("Use \"%s\" for \"%s\"\n",
 					ypaliases[i].alias,
 					ypaliases[i].name);
@@ -106,7 +106,7 @@ main(int argc, char *argv[])
 		yp_get_default_domain(&domainname);
 
 	inmap = argv[argc-1];
-	for (i = 0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+	for (i = 0; (!notrans) && i < NELEM(ypaliases); i++)
 		if (strcmp(inmap, ypaliases[i].alias) == 0)
 			inmap = __DECONST(char *, ypaliases[i].name);
 	for (; optind < argc-1; optind++) {
diff --git a/usr.bin/ypwhich/ypwhich.c b/usr.bin/ypwhich/ypwhich.c
index 674e643b8b..e886292841 100644
--- a/usr.bin/ypwhich/ypwhich.c
+++ b/usr.bin/ypwhich/ypwhich.c
@@ -149,7 +149,7 @@ main(int argc, char *argv[])
 	while ((c = getopt(argc, argv, "xd:mt")) != -1)
 		switch (c) {
 		case 'x':
-			for (i = 0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+			for (i = 0; i < NELEM(ypaliases); i++)
 				printf("\"%s\" is an alias for \"%s\"\n",
 					ypaliases[i].alias,
 					ypaliases[i].name);
@@ -204,7 +204,7 @@ main(int argc, char *argv[])
 
 	if (argv[optind]) {
 		map = argv[optind];
-		for (i = 0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+		for (i = 0; (!notrans) && i < NELEM(ypaliases); i++)
 			if (strcmp(map, ypaliases[i].alias) == 0)
 				map = ypaliases[i].name;
 		r = yp_master(domnam, map, &master);
diff --git a/usr.sbin/boot0cfg/boot0cfg.c b/usr.sbin/boot0cfg/boot0cfg.c
index a9f47ae08f..d9e6e67082 100644
--- a/usr.sbin/boot0cfg/boot0cfg.c
+++ b/usr.sbin/boot0cfg/boot0cfg.c
@@ -64,7 +64,7 @@ static const struct {
     {"update", 1},
     {"setdrv", 0}
 };
-static const int nopt = sizeof(opttbl) / sizeof(opttbl[0]);
+static const int nopt = NELEM(opttbl);
 
 static const char fmt0[] = "#   flag     start chs   type"
     "       end chs       offset         size\n";
@@ -355,7 +355,7 @@ boot0bs(const u_int8_t *bs)
     unsigned int i;
     int count = 0;
 
-    for (i = 0; i < sizeof(ident) / sizeof(ident[0]); i++) {
+    for (i = 0; i < NELEM(ident); i++) {
         if (memcmp(bs + ident[i].off, ident[i].key, ident[i].len) == 0)
 	    ++count;
     }
diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c
index 1d97f8cdaf..1e30df0c22 100644
--- a/usr.sbin/config/main.c
+++ b/usr.sbin/config/main.c
@@ -214,7 +214,7 @@ main(int argc, char *argv[])
 	 * create the symlinks automatically XXX
 	 */
 #if 0
-	for (i = 0; i < sizeof(emus) / sizeof(emus[0]); ++i) {
+	for (i = 0; i < NELEM(emus); ++i) {
 		if (*srcdir == 0)  {
 			snprintf(linkdest, sizeof(linkdest),
 			    "../../emulation/%s/%s",
diff --git a/usr.sbin/cpucontrol/cpucontrol.c b/usr.sbin/cpucontrol/cpucontrol.c
index ca78c21c15..acb431cad5 100644
--- a/usr.sbin/cpucontrol/cpucontrol.c
+++ b/usr.sbin/cpucontrol/cpucontrol.c
@@ -92,7 +92,7 @@ static struct ucode_handler {
 	{ amd_probe, amd_update },
 	{ via_probe, via_update },
 };
-#define NHANDLERS (sizeof(handlers) / sizeof(*handlers))
+#define NHANDLERS (NELEM(handlers))
 
 static void	usage(void);
 static int	isdir(const char *path);
diff --git a/usr.sbin/makewhatis/makewhatis.c b/usr.sbin/makewhatis/makewhatis.c
index aa961d95e7..261613eafa 100644
--- a/usr.sbin/makewhatis/makewhatis.c
+++ b/usr.sbin/makewhatis/makewhatis.c
@@ -639,7 +639,7 @@ process_mdoc_macro(char *line)
 	};
 	unsigned int i;
 
-	for (i = 0; i < sizeof(list) / sizeof(list[0]); ++i) {
+	for (i = 0; i < NELEM(list); ++i) {
 		if (!strcmp(line, list[i].mdoc)) {
 			sbuf_append(whatis_proto, list[i].text,
 			    strlen(list[i].text));
diff --git a/usr.sbin/moused/moused.c b/usr.sbin/moused/moused.c
index f78ced2c99..5d683a7bcf 100644
--- a/usr.sbin/moused/moused.c
+++ b/usr.sbin/moused/moused.c
@@ -926,7 +926,7 @@ moused(void)
 	bstate[i].count = 0;
 	bstate[i].tv = mouse_button_state_tv;
     }
-    for (i = 0; i < sizeof(zstate)/sizeof(zstate[0]); ++i) {
+    for (i = 0; i < NELEM(zstate); ++i) {
 	zstate[i].count = 0;
 	zstate[i].tv = mouse_button_state_tv;
     }
@@ -1294,7 +1294,7 @@ r_identify(void)
     rodent.mode.level = 0;
     if (ioctl(rodent.mfd, MOUSE_GETMODE, &rodent.mode) == 0) {
 	if ((rodent.mode.protocol == MOUSE_PROTO_UNKNOWN)
-	    || (rodent.mode.protocol >= sizeof(proto)/sizeof(proto[0]))) {
+	    || (rodent.mode.protocol >= NELEM(proto))) {
 	    logwarnx("unknown mouse protocol (%d)", rodent.mode.protocol);
 	    return MOUSE_PROTO_UNKNOWN;
 	} else {
@@ -1375,7 +1375,7 @@ static char *
 r_name(int type)
 {
     return ((type == MOUSE_PROTO_UNKNOWN)
-	|| (type > sizeof(rnames)/sizeof(rnames[0]) - 1))
+	|| (type > NELEM(rnames) - 1))
 	? "unknown" : rnames[type];
 }
 
diff --git a/usr.sbin/ndp/ndp.c b/usr.sbin/ndp/ndp.c
index 4d8a778d02..869b7eb828 100644
--- a/usr.sbin/ndp/ndp.c
+++ b/usr.sbin/ndp/ndp.c
@@ -988,7 +988,7 @@ rtrlist(void)
 	size_t l;
 	struct timeval time;
 
-	if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) {
+	if (sysctl(mib, NELEM(mib), NULL, &l, NULL, 0) < 0) {
 		err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
 		/*NOTREACHED*/
 	}
@@ -997,7 +997,7 @@ rtrlist(void)
 		errx(1, "not enough core");
 		/*NOTREACHED*/
 	}
-	if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) {
+	if (sysctl(mib, NELEM(mib), buf, &l, NULL, 0) < 0) {
 		err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
 		/*NOTREACHED*/
 	}
@@ -1090,7 +1090,7 @@ plist(void)
 #endif
 	char namebuf[NI_MAXHOST];
 
-	if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) {
+	if (sysctl(mib, NELEM(mib), NULL, &l, NULL, 0) < 0) {
 		err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
 		/*NOTREACHED*/
 	}
@@ -1099,7 +1099,7 @@ plist(void)
 		errx(1, "not enough core");
 		/*NOTREACHED*/
 	}
-	if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) {
+	if (sysctl(mib, NELEM(mib), buf, &l, NULL, 0) < 0) {
 		err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
 		/*NOTREACHED*/
 	}
diff --git a/usr.sbin/pfctl/pfctl_parser.c b/usr.sbin/pfctl/pfctl_parser.c
index 7587592004..083f73b657 100644
--- a/usr.sbin/pfctl/pfctl_parser.c
+++ b/usr.sbin/pfctl/pfctl_parser.c
@@ -210,14 +210,12 @@ geticmptypebynumber(u_int8_t type, sa_family_t af)
 	unsigned int	i;
 
 	if (af != AF_INET6) {
-		for (i=0; i < (sizeof (icmp_type) / sizeof(icmp_type[0]));
-		    i++) {
+		for (i=0; i < NELEM(icmp_type); i++) {
 			if (type == icmp_type[i].type)
 				return (&icmp_type[i]);
 		}
 	} else {
-		for (i=0; i < (sizeof (icmp6_type) /
-		    sizeof(icmp6_type[0])); i++) {
+		for (i=0; i < NELEM(icmp6_type); i++) {
 			if (type == icmp6_type[i].type)
 				 return (&icmp6_type[i]);
 		}
@@ -231,14 +229,12 @@ geticmptypebyname(char *w, sa_family_t af)
 	unsigned int	i;
 
 	if (af != AF_INET6) {
-		for (i=0; i < (sizeof (icmp_type) / sizeof(icmp_type[0]));
-		    i++) {
+		for (i=0; i < NELEM(icmp_type); i++) {
 			if (!strcmp(w, icmp_type[i].name))
 				return (&icmp_type[i]);
 		}
 	} else {
-		for (i=0; i < (sizeof (icmp6_type) /
-		    sizeof(icmp6_type[0])); i++) {
+		for (i=0; i < NELEM(icmp6_type); i++) {
 			if (!strcmp(w, icmp6_type[i].name))
 				return (&icmp6_type[i]);
 		}
@@ -252,15 +248,13 @@ geticmpcodebynumber(u_int8_t type, u_int8_t code, sa_family_t af)
 	unsigned int	i;
 
 	if (af != AF_INET6) {
-		for (i=0; i < (sizeof (icmp_code) / sizeof(icmp_code[0]));
-		    i++) {
+		for (i=0; i < NELEM(icmp_code); i++) {
 			if (type == icmp_code[i].type &&
 			    code == icmp_code[i].code)
 				return (&icmp_code[i]);
 		}
 	} else {
-		for (i=0; i < (sizeof (icmp6_code) /
-		    sizeof(icmp6_code[0])); i++) {
+		for (i=0; i < NELEM(icmp6_code); i++) {
 			if (type == icmp6_code[i].type &&
 			    code == icmp6_code[i].code)
 				return (&icmp6_code[i]);
@@ -275,15 +269,13 @@ geticmpcodebyname(u_long type, char *w, sa_family_t af)
 	unsigned int	i;
 
 	if (af != AF_INET6) {
-		for (i=0; i < (sizeof (icmp_code) / sizeof(icmp_code[0]));
-		    i++) {
+		for (i=0; i < NELEM(icmp_code); i++) {
 			if (type == icmp_code[i].type &&
 			    !strcmp(w, icmp_code[i].name))
 				return (&icmp_code[i]);
 		}
 	} else {
-		for (i=0; i < (sizeof (icmp6_code) /
-		    sizeof(icmp6_code[0])); i++) {
+		for (i=0; i < NELEM(icmp6_code); i++) {
 			if (type == icmp6_code[i].type &&
 			    !strcmp(w, icmp6_code[i].name))
 				return (&icmp6_code[i]);
diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c
index 41c5a9b494..fb334c6a47 100644
--- a/usr.sbin/ppp/bundle.c
+++ b/usr.sbin/ppp/bundle.c
@@ -24,7 +24,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.sbin/ppp/bundle.c,v 1.84.2.12 2002/09/01 02:12:22 brian Exp $
- * $DragonFly: src/usr.sbin/ppp/bundle.c,v 1.5 2005/11/24 23:42:54 swildner Exp $
  */
 
 #include <sys/param.h>
@@ -1502,7 +1501,7 @@ bundle_ReceiveDatalink(struct bundle *bundle, int s)
   onfd = nfd;	/* We've got this many in our array */
   nfd -= 2;	/* Don't include p->fd and our reply descriptor */
   niov = 1;	/* Skip the version id */
-  dl = iov2datalink(bundle, iov, &niov, sizeof iov / sizeof *iov, fd[0],
+  dl = iov2datalink(bundle, iov, &niov, NELEM(iov), fd[0],
                     fd + 2, &nfd);
   if (dl) {
 
diff --git a/usr.sbin/ppp/cbcp.c b/usr.sbin/ppp/cbcp.c
index 1521067dba..575cd8be73 100644
--- a/usr.sbin/ppp/cbcp.c
+++ b/usr.sbin/ppp/cbcp.c
@@ -24,7 +24,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.sbin/ppp/cbcp.c,v 1.18.2.3 2002/09/01 02:12:22 brian Exp $
- * $DragonFly: src/usr.sbin/ppp/cbcp.c,v 1.3 2004/02/03 07:11:47 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -153,7 +152,7 @@ static const char * const cbcpname[] = {
 static const char *
 cbcpstate(unsigned s)
 {
-  if (s < sizeof cbcpname / sizeof cbcpname[0])
+  if (s < NELEM(cbcpname))
     return cbcpname[s];
   return HexStr(s, NULL, 0);
 }
@@ -217,7 +216,7 @@ cbcp_data_Type(unsigned type)
     "No callback", "User-spec", "Server-spec", "list"
   };
 
-  if (type < 1 || type > sizeof types / sizeof types[0])
+  if (type < 1 || type > NELEM(types))
     return HexStr(type, NULL, 0);
   return types[type-1];
 }
diff --git a/usr.sbin/ppp/ccp.c b/usr.sbin/ppp/ccp.c
index 2b9606140d..74255b15a7 100644
--- a/usr.sbin/ppp/ccp.c
+++ b/usr.sbin/ppp/ccp.c
@@ -26,7 +26,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.sbin/ppp/ccp.c,v 1.54.2.7 2002/09/01 02:12:22 brian Exp $
- * $DragonFly: src/usr.sbin/ppp/ccp.c,v 1.2 2003/06/17 04:30:00 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -134,7 +133,7 @@ protoname(int proto)
     "DEFLATE",		/* 26: Deflate (rfc1979) */
   };
 
-  if (proto < 0 || (unsigned)proto > sizeof cftypes / sizeof *cftypes ||
+  if (proto < 0 || (unsigned)proto > NELEM(cftypes) ||
       cftypes[proto] == NULL) {
     if (proto == -1)
       return "none";
@@ -154,7 +153,7 @@ static const struct ccp_algorithm * const algorithm[] = {
 #endif
 };
 
-#define NALGORITHMS (sizeof algorithm/sizeof algorithm[0])
+#define NALGORITHMS NELEM(algorithm)
 
 int
 ccp_ReportStatus(struct cmdargs const *arg)
diff --git a/usr.sbin/ppp/chap.c b/usr.sbin/ppp/chap.c
index 76842df77a..96d2cf1e74 100644
--- a/usr.sbin/ppp/chap.c
+++ b/usr.sbin/ppp/chap.c
@@ -26,7 +26,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.sbin/ppp/chap.c,v 1.61.2.7 2002/09/01 02:12:23 brian Exp $
- * $DragonFly: src/usr.sbin/ppp/chap.c,v 1.2 2003/06/17 04:30:00 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -95,7 +94,7 @@
 static const char * const chapcodes[] = {
   "???", "CHALLENGE", "RESPONSE", "SUCCESS", "FAILURE"
 };
-#define MAXCHAPCODE (sizeof chapcodes / sizeof chapcodes[0] - 1)
+#define MAXCHAPCODE (NELEM(chapcodes) - 1)
 
 static void
 ChapOutput(struct physical *physical, u_int code, u_int id,
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c
index f9ae672977..ace6ffad58 100644
--- a/usr.sbin/ppp/command.c
+++ b/usr.sbin/ppp/command.c
@@ -362,8 +362,8 @@ LogCommand(struct cmdargs const *arg)
     char *argv[MAXARGS];
     int argc = arg->argc - arg->argn;
 
-    if (argc >= (int)(sizeof argv / sizeof argv[0])) {
-      argc = sizeof argv / sizeof argv[0] - 1;
+    if (argc >= (int)NELEM(argv)) {
+      argc = NELEM(argv) - 1;
       log_Printf(LogWARN, "Truncating log command to %d args\n", argc);
     }
     command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 1, getpid());
@@ -651,8 +651,8 @@ ShellCommand(struct cmdargs const *arg, int bg)
       char *argv[MAXARGS];
       int argc = arg->argc - arg->argn;
 
-      if (argc >= (int)(sizeof argv / sizeof argv[0])) {
-        argc = sizeof argv / sizeof argv[0] - 1;
+      if (argc >= (int)NELEM(argv)) {
+        argc = NELEM(argv) - 1;
         log_Printf(LogWARN, "Truncating shell command to %d args\n", argc);
       }
       command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 0, pid);
@@ -3174,8 +3174,8 @@ SetProcTitle(struct cmdargs const *arg)
     return 0;
   }
 
-  if ((unsigned)argc >= sizeof argv / sizeof argv[0]) {
-    argc = sizeof argv / sizeof argv[0] - 1;
+  if ((unsigned)argc >= NELEM(argv)) {
+    argc = NELEM(argv) - 1;
     log_Printf(LogWARN, "Truncating proc title to %d args\n", argc);
   }
   command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 1, getpid());
diff --git a/usr.sbin/ppp/datalink.c b/usr.sbin/ppp/datalink.c
index e34d47bfb1..602ef6e8b8 100644
--- a/usr.sbin/ppp/datalink.c
+++ b/usr.sbin/ppp/datalink.c
@@ -1268,7 +1268,7 @@ static const char * const states[] = {
 const char *
 datalink_State(struct datalink *dl)
 {
-  if (dl->state >= sizeof states / sizeof states[0])
+  if (dl->state >= NELEM(states))
     return "unknown";
   return states[dl->state];
 }
@@ -1277,7 +1277,7 @@ static void
 datalink_NewState(struct datalink *dl, unsigned state)
 {
   if (state != dl->state) {
-    if (state < sizeof states / sizeof states[0]) {
+    if (state < NELEM(states)) {
       log_Printf(LogPHASE, "%s: %s -> %s\n", dl->name, datalink_State(dl),
                  states[state]);
       dl->state = state;
diff --git a/usr.sbin/ppp/defs.c b/usr.sbin/ppp/defs.c
index 84056cd7d7..a4d98d2b4e 100644
--- a/usr.sbin/ppp/defs.c
+++ b/usr.sbin/ppp/defs.c
@@ -371,7 +371,7 @@ ex_desc(int ex)
     "redial", "reconnect"
   };
 
-  if (ex >= 0 && ex < (int)(sizeof desc / sizeof *desc))
+  if (ex >= 0 && ex < (int)NELEM(desc))
     return desc[ex];
   snprintf(num, sizeof num, "%d", ex);
   return num;
diff --git a/usr.sbin/ppp/filter.c b/usr.sbin/ppp/filter.c
index 56b513f98b..839fbebfa9 100644
--- a/usr.sbin/ppp/filter.c
+++ b/usr.sbin/ppp/filter.c
@@ -539,7 +539,7 @@ static const char * const opname[] = {"none", "eq", "gt", "lt"};
 const char *
 filter_Op2Nam(unsigned op)
 {
-  if (op >= sizeof opname / sizeof opname[0])
+  if (op >= NELEM(opname))
     return "unknown";
   return opname[op];
 
@@ -550,7 +550,7 @@ filter_Nam2Op(const char *cp)
 {
   unsigned op;
 
-  for (op = sizeof opname / sizeof opname[0] - 1; op; op--)
+  for (op = NELEM(opname) - 1; op; op--)
     if (!strcasecmp(cp, opname[op]))
       break;
 
diff --git a/usr.sbin/ppp/fsm.c b/usr.sbin/ppp/fsm.c
index 415e0bf66a..e831852861 100644
--- a/usr.sbin/ppp/fsm.c
+++ b/usr.sbin/ppp/fsm.c
@@ -105,7 +105,7 @@ static const struct fsmcodedesc {
 static const char *
 Code2Nam(u_int code)
 {
-  if (code == 0 || code > sizeof FsmCodes / sizeof FsmCodes[0])
+  if (code == 0 || code > NELEM(FsmCodes))
     return "Unknown";
   return FsmCodes[code-1].name;
 }
@@ -118,7 +118,7 @@ State2Nam(u_int state)
     "Req-Sent", "Ack-Rcvd", "Ack-Sent", "Opened",
   };
 
-  if (state >= sizeof StateNames / sizeof StateNames[0])
+  if (state >= NELEM(StateNames))
     return "unknown";
   return StateNames[state];
 }
@@ -1063,7 +1063,7 @@ fsm_Input(struct fsm *fp, struct mbuf *bp)
   }
 
   if (lh.code < fp->min_code || lh.code > fp->max_code ||
-      lh.code > sizeof FsmCodes / sizeof *FsmCodes) {
+      lh.code > NELEM(FsmCodes)) {
     /*
      * Use a private id.  This is really a response-type packet, but we
      * MUST send a unique id for each REQ....
diff --git a/usr.sbin/ppp/hdlc.c b/usr.sbin/ppp/hdlc.c
index 3468cc007e..7487b4cd0a 100644
--- a/usr.sbin/ppp/hdlc.c
+++ b/usr.sbin/ppp/hdlc.c
@@ -26,7 +26,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.sbin/ppp/hdlc.c,v 1.46.2.2 2002/09/01 02:12:27 brian Exp $
- * $DragonFly: src/usr.sbin/ppp/hdlc.c,v 1.2 2003/06/17 04:30:00 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -283,7 +282,7 @@ static struct {
   { 0xc481, 0xc481, "Proprietary Node ID Authentication Protocol" }
 };
 
-#define NPROTOCOLS (sizeof protocols/sizeof protocols[0])
+#define NPROTOCOLS NELEM(protocols)
 
 const char *
 hdlc_Protocol2Nam(u_short proto)
diff --git a/usr.sbin/ppp/iface.c b/usr.sbin/ppp/iface.c
index 026b106b2b..6c1020f97c 100644
--- a/usr.sbin/ppp/iface.c
+++ b/usr.sbin/ppp/iface.c
@@ -655,7 +655,7 @@ iface_Show(struct cmdargs const *arg)
   iface_Destroy(current);
 
   prompt_Printf(arg->prompt, "%s (idx %d) <", iface->name, iface->index);
-  for (f = 0; f < sizeof if_flags / sizeof if_flags[0]; f++)
+  for (f = 0; f < NELEM(if_flags); f++)
     if ((if_flags[f].flag & flags)) {
       prompt_Printf(arg->prompt, "%s%s", flags == iface->flags ? "" : ",",
                     if_flags[f].value);
diff --git a/usr.sbin/ppp/ip.c b/usr.sbin/ppp/ip.c
index f2c7a48bd2..86ea88a612 100644
--- a/usr.sbin/ppp/ip.c
+++ b/usr.sbin/ppp/ip.c
@@ -112,7 +112,7 @@ dns_Qclass2Txt(u_short qclass)
   };
   unsigned f;
 
-  for (f = 0; f < sizeof qtxt / sizeof *qtxt; f++)
+  for (f = 0; f < NELEM(qtxt); f++)
     if (qtxt[f].id == qclass)
       return qtxt[f].txt;
 
@@ -139,7 +139,7 @@ dns_Qtype2Txt(u_short qtype)
   };
   unsigned f;
 
-  for (f = 0; f < sizeof qtxt / sizeof *qtxt; f++)
+  for (f = 0; f < NELEM(qtxt); f++)
     if (qtxt[f].id == qtype)
       return qtxt[f].txt;
 
diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c
index 0d62ed6de8..c2aa08be31 100644
--- a/usr.sbin/ppp/ipcp.c
+++ b/usr.sbin/ppp/ipcp.c
@@ -26,7 +26,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.sbin/ppp/ipcp.c,v 1.90.2.12 2002/09/28 10:16:25 brian Exp $
- * $DragonFly: src/usr.sbin/ppp/ipcp.c,v 1.2 2003/06/17 04:30:00 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -151,7 +150,7 @@ protoname(int proto)
   };
   unsigned f;
 
-  for (f = 0; f < sizeof cftypes / sizeof *cftypes; f++)
+  for (f = 0; f < NELEM(cftypes); f++)
     if (cftypes[f].id == proto)
       return cftypes[f].txt;
 
diff --git a/usr.sbin/ppp/ipv6cp.c b/usr.sbin/ppp/ipv6cp.c
index 7fd605149b..2292686500 100644
--- a/usr.sbin/ppp/ipv6cp.c
+++ b/usr.sbin/ppp/ipv6cp.c
@@ -613,7 +613,7 @@ protoname(unsigned proto)
 {
   static const char *cftypes[] = { "IFACEID", "COMPPROTO" };
 
-  if (proto > 0 && proto <= sizeof cftypes / sizeof *cftypes)
+  if (proto > 0 && proto <= NELEM(cftypes))
     return cftypes[proto - 1];
 
   return NumStr(proto, NULL, 0);
diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c
index 2f5a5aa83d..8f785a1532 100644
--- a/usr.sbin/ppp/lcp.c
+++ b/usr.sbin/ppp/lcp.c
@@ -26,7 +26,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.sbin/ppp/lcp.c,v 1.81.2.13 2002/09/01 02:12:28 brian Exp $
- * $DragonFly: src/usr.sbin/ppp/lcp.c,v 1.2 2003/06/17 04:30:00 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -147,7 +146,7 @@ protoname(unsigned proto)
     "LDBACP",		/* 23: Link Discriminator for BACP */
   };
 
-  if (proto > sizeof cftypes / sizeof *cftypes || cftypes[proto] == NULL)
+  if (proto > NELEM(cftypes) || cftypes[proto] == NULL)
     return HexStr(proto, NULL, 0);
 
   return cftypes[proto];
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index f7509e78f9..7a19f4fdde 100644
--- a/usr.sbin/ppp/main.c
+++ b/usr.sbin/ppp/main.c
@@ -26,7 +26,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.sbin/ppp/main.c,v 1.167.2.8 2002/09/01 02:12:28 brian Exp $
- * $DragonFly: src/usr.sbin/ppp/main.c,v 1.2 2003/06/17 04:30:00 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -321,7 +320,7 @@ main(int argc, char **argv)
     fprintf(stderr, "Cannot open %s !\n", _PATH_DEVNULL);
     return 2;
   }
-  for (f = 1; f < sizeof holdfd / sizeof *holdfd; f++)
+  for (f = 1; f < NELEM(holdfd); f++)
     holdfd[f] = dup(holdfd[0]);
 
   name = strrchr(argv[0], '/');
@@ -523,7 +522,7 @@ main(int argc, char **argv)
   }
 
   /* We can get rid of these now */
-  for (f = 0; f < sizeof holdfd / sizeof *holdfd; f++)
+  for (f = 0; f < NELEM(holdfd); f++)
     close(holdfd[f]);
 
   log_Printf(LogPHASE, "PPP Started (%s mode).\n", mode2Nam(sw.mode));
diff --git a/usr.sbin/ppp/ncp.c b/usr.sbin/ppp/ncp.c
index 936656d9f7..a2f925e1fd 100644
--- a/usr.sbin/ppp/ncp.c
+++ b/usr.sbin/ppp/ncp.c
@@ -24,7 +24,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.sbin/ppp/ncp.c,v 1.5.2.1 2002/09/01 02:12:29 brian Exp $
- * $DragonFly: src/usr.sbin/ppp/ncp.c,v 1.2 2003/06/17 04:30:00 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -90,8 +89,7 @@ static u_short default_urgent_tcp_ports[] = {
   544	/* kshell */
 };
 
-#define NDEFTCPPORTS \
-  (sizeof default_urgent_tcp_ports / sizeof default_urgent_tcp_ports[0])
+#define NDEFTCPPORTS NELEM(default_urgent_tcp_ports)
 
 void
 ncp_Init(struct ncp *ncp, struct bundle *bundle)
diff --git a/usr.sbin/ppp/pap.c b/usr.sbin/ppp/pap.c
index 801e745ab7..e5a4b840d8 100644
--- a/usr.sbin/ppp/pap.c
+++ b/usr.sbin/ppp/pap.c
@@ -26,7 +26,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.sbin/ppp/pap.c,v 1.42.2.4 2002/09/01 02:12:29 brian Exp $
- * $DragonFly: src/usr.sbin/ppp/pap.c,v 1.2 2003/06/17 04:30:00 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -78,7 +77,7 @@
 static const char * const papcodes[] = {
   "???", "REQUEST", "SUCCESS", "FAILURE"
 };
-#define MAXPAPCODE (sizeof papcodes / sizeof papcodes[0] - 1)
+#define MAXPAPCODE (NELEM(papcodes) - 1)
 
 static void
 pap_Req(struct authinfo *authp)
diff --git a/usr.sbin/ppp/physical.c b/usr.sbin/ppp/physical.c
index 238349b499..7baaf1c0b8 100644
--- a/usr.sbin/ppp/physical.c
+++ b/usr.sbin/ppp/physical.c
@@ -133,7 +133,7 @@ struct {
   { exec_Create, exec_iov2device, exec_DeviceSize }
 };
 
-#define NDEVICES (sizeof devices / sizeof devices[0])
+#define NDEVICES NELEM(devices)
 
 static int
 physical_UpdateSet(struct fdescriptor *d, fd_set *r, fd_set *w, fd_set *e,
diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c
index 3d7ef801bd..5ee4dd388f 100644
--- a/usr.sbin/pstat/pstat.c
+++ b/usr.sbin/pstat/pstat.c
@@ -933,7 +933,7 @@ swapmode(void)
 	n = kvm_getswapinfo(
 	    kd, 
 	    kswap,
-	    sizeof(kswap)/sizeof(kswap[0]),
+	    NELEM(kswap),
 	    ((swapflag > 1) ? SWIF_DUMP_TREE : 0) | SWIF_DEV_PREFIX
 	);
 
diff --git a/usr.sbin/rarpd/rarpd.c b/usr.sbin/rarpd/rarpd.c
index 54bc64142d..9571aed455 100644
--- a/usr.sbin/rarpd/rarpd.c
+++ b/usr.sbin/rarpd/rarpd.c
@@ -381,7 +381,7 @@ rarp_open(char *device)
 		BPF_STMT(BPF_RET|BPF_K, 0),
 	};
 	static struct bpf_program filter = {
-		sizeof insns / sizeof(insns[0]),
+		NELEM(insns),
 		insns
 	};
 
diff --git a/usr.sbin/rtsold/if.c b/usr.sbin/rtsold/if.c
index cb273c3cab..4778f0b73a 100644
--- a/usr.sbin/rtsold/if.c
+++ b/usr.sbin/rtsold/if.c
@@ -29,7 +29,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.sbin/rtsold/if.c,v 1.2.2.3 2001/07/03 11:02:16 ume Exp $
- * $DragonFly: src/usr.sbin/rtsold/if.c,v 1.6 2005/12/05 00:56:37 swildner Exp $
  */
 
 #include <sys/param.h>
@@ -308,7 +307,7 @@ getinet6sysctl(int code)
 
 	mib[3] = code;
 	size = sizeof(value);
-	if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, NULL, 0) < 0)
+	if (sysctl(mib, NELEM(mib), &value, &size, NULL, 0) < 0)
 		return -1;
 	else
 		return value;
diff --git a/usr.sbin/rwhod/rwhod.c b/usr.sbin/rwhod/rwhod.c
index 90cd09929b..c503e9ebe4 100644
--- a/usr.sbin/rwhod/rwhod.c
+++ b/usr.sbin/rwhod/rwhod.c
@@ -508,7 +508,7 @@ send_host_information(void)
 			we->we_idle = htonl(now - stb.st_atime);
 		we++;
 	}
-	getloadavg(avenrun, sizeof(avenrun)/sizeof(avenrun[0]));
+	getloadavg(avenrun, NELEM(avenrun));
 	for (i = 0; i < 3; i++)
 		mywd.wd_loadav[i] = htonl((u_long)(avenrun[i] * 100));
 	cc = (char *)we - (char *)&mywd;
diff --git a/usr.sbin/setkey/test-policy.c b/usr.sbin/setkey/test-policy.c
index 5014bd2160..a58d671c8b 100644
--- a/usr.sbin/setkey/test-policy.c
+++ b/usr.sbin/setkey/test-policy.c
@@ -27,7 +27,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/usr.sbin/setkey/test-policy.c,v 1.1 2000/01/06 12:40:53 shin Exp $
- * $DragonFly: src/usr.sbin/setkey/test-policy.c,v 1.3 2004/03/24 18:23:47 cpressey Exp $
  */
 
 #include <sys/types.h>
@@ -79,7 +78,7 @@ main(int argc __unused, char **argv __unused)
 	int i;
 	char *buf;
 
-	for (i = 0; i < sizeof(requests)/sizeof(requests[0]); i++) {
+	for (i = 0; i < NELEM(requests); i++) {
 		printf("* requests:[%s]\n", requests[i]);
 		if ((buf = setpolicy(requests[i])) == NULL)
 			continue;
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index 40ffb7e3ff..d7dbcfe831 100644
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -234,7 +234,7 @@ struct allowedpeer {
  * we move to the next interval until we reach the largest.
  */
 int	repeatinterval[] = { 30, 120, 600 };	/* # of secs before flush */
-#define	MAXREPEAT ((sizeof(repeatinterval) / sizeof(repeatinterval[0])) - 1)
+#define	MAXREPEAT (NELEM(repeatinterval) - 1)
 #define	REPEATTIME(f)	((f)->f_time + repeatinterval[(f)->f_repeatcount])
 #define	BACKOFF(f)	{ if (++(f)->f_repeatcount > MAXREPEAT) \
 				 (f)->f_repeatcount = MAXREPEAT; \
diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c
index ca74ae409a..85050fc362 100644
--- a/usr.sbin/traceroute/traceroute.c
+++ b/usr.sbin/traceroute/traceroute.c
@@ -337,7 +337,7 @@ main(int argc, char *argv[])
 	seteuid(getuid());
 	setuid(getuid());
 
-	sysctl(mib, sizeof(mib)/sizeof(mib[0]), &max_ttl, &size, NULL, 0);
+	sysctl(mib, NELEM(mib), &max_ttl, &size, NULL, 0);
 
 	while ((ch = getopt(argc, argv, "SDIdg:f:m:np:q:rs:t:w:vlP:cM")) != -1)
 		switch (ch) {
diff --git a/usr.sbin/traceroute6/traceroute6.c b/usr.sbin/traceroute6/traceroute6.c
index 86ee12c513..18788ccec4 100644
--- a/usr.sbin/traceroute6/traceroute6.c
+++ b/usr.sbin/traceroute6/traceroute6.c
@@ -361,7 +361,7 @@ main(int argc, char **argv)
 	}
 
 	size = sizeof(i);
-	(void) sysctl(mib, sizeof(mib)/sizeof(mib[0]), &i, &size, NULL, 0);
+	(void) sysctl(mib, NELEM(mib), &i, &size, NULL, 0);
 	max_hops = i;
 
 	/* specify to tell receiving interface */
-- 
2.15.1

