summaryrefslogtreecommitdiff
path: root/usr.sbin/snmpd
diff options
context:
space:
mode:
authorjan <jan@cvs.openbsd.org>2020-09-06 16:12:24 +0000
committerjan <jan@cvs.openbsd.org>2020-09-06 16:12:24 +0000
commit6434cd697cf7023d58603887a594ab30b8a786ae (patch)
treee0bc833a75ad7e13ad9b6c43fa0de5ee601c14f1 /usr.sbin/snmpd
parent800ad640f1dffde8728ff1758c3941557044b2ea (diff)
replace duplicated sizeofa marco with predefined nitems
OK martijn@
Diffstat (limited to 'usr.sbin/snmpd')
-rw-r--r--usr.sbin/snmpd/mib.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/usr.sbin/snmpd/mib.c b/usr.sbin/snmpd/mib.c
index 991725cc261..663658d43e5 100644
--- a/usr.sbin/snmpd/mib.c
+++ b/usr.sbin/snmpd/mib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mib.c,v 1.100 2020/07/01 16:41:43 martijn Exp $ */
+/* $OpenBSD: mib.c,v 1.101 2020/09/06 16:12:23 jan Exp $ */
/*
* Copyright (c) 2012 Joel Knight <joel@openbsd.org>
@@ -71,8 +71,6 @@ int mib_setsnmp(struct oid *, struct ber_oid *, struct ber_element **);
static struct oid mib_tree[] = MIB_TREE;
static struct ber_oid zerodotzero = { { 0, 0 }, 2 };
-#define sizeofa(_a) (sizeof(_a) / sizeof((_a)[0]))
-
/* base MIB tree */
static struct oid base_mib[] = {
{ MIB(mib_2), OID_MIB },
@@ -548,7 +546,7 @@ mib_hrmemory(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
u_int64_t physmem;
size_t len = sizeof(physmem);
- if (sysctl(mib, sizeofa(mib), &physmem, &len, NULL, 0) == -1)
+ if (sysctl(mib, nitems(mib), &physmem, &len, NULL, 0) == -1)
return (-1);
ber = ober_add_integer(ber, physmem / 1024);
@@ -579,16 +577,16 @@ mib_hrstorage(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
/* Physical memory, real memory, swap */
mib[1] = HW_PHYSMEM64;
len = sizeof(physmem);
- if (sysctl(mib, sizeofa(mib), &physmem, &len, NULL, 0) == -1)
+ if (sysctl(mib, nitems(mib), &physmem, &len, NULL, 0) == -1)
return (-1);
mib[1] = HW_USERMEM64;
len = sizeof(realmem);
- if (sysctl(mib, sizeofa(mib), &realmem, &len, NULL, 0) == -1)
+ if (sysctl(mib, nitems(mib), &realmem, &len, NULL, 0) == -1)
return (-1);
mib[0] = CTL_VM;
mib[1] = VM_UVMEXP;
len = sizeof(uvm);
- if (sysctl(mib, sizeofa(mib), &uvm, &len, NULL, 0) == -1)
+ if (sysctl(mib, nitems(mib), &uvm, &len, NULL, 0) == -1)
return (-1);
maxsize = 10;
@@ -711,7 +709,7 @@ mib_hrdevice(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
ber = ober_add_oid(ber, o);
len = sizeof(descr);
- if (sysctl(mib, sizeofa(mib), &descr, &len, NULL, 0) == -1)
+ if (sysctl(mib, nitems(mib), &descr, &len, NULL, 0) == -1)
return (-1);
/* unknown(1), running(2), warning(3), testing(4), down(5) */
status = 2;
@@ -889,7 +887,7 @@ kinfo_proc(u_int32_t idx, struct kinfo_proc **kinfo)
for (;;) {
size = nkp * sizeof(*kp);
mib[5] = nkp;
- if (sysctl(mib, sizeofa(mib), kp, &size, NULL, 0) == -1) {
+ if (sysctl(mib, nitems(mib), kp, &size, NULL, 0) == -1) {
if (errno == ENOMEM) {
kinfo_proc_free();
continue;
@@ -975,7 +973,7 @@ kinfo_args(struct kinfo_proc *kinfo, char **s)
str[0] = '\0';
*s = str;
- while (sysctl(mib, sizeofa(mib), buf, &buflen, NULL, 0) == -1) {
+ while (sysctl(mib, nitems(mib), buf, &buflen, NULL, 0) == -1) {
if (errno != ENOMEM) {
/* some errors are expected, dont get too upset */
return (0);
@@ -2542,7 +2540,7 @@ mib_sensornum(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
for (i = c = 0; ; i++) {
mib[2] = i;
- if (sysctl(mib, sizeofa(mib),
+ if (sysctl(mib, nitems(mib),
&sensordev, &len, NULL, 0) == -1) {
if (errno == ENXIO)
continue;
@@ -3112,7 +3110,7 @@ mib_ipforwarding(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
int v;
size_t len = sizeof(v);
- if (sysctl(mib, sizeofa(mib), &v, &len, NULL, 0) == -1)
+ if (sysctl(mib, nitems(mib), &v, &len, NULL, 0) == -1)
return (-1);
/* ipForwarding: forwarding(1), notForwarding(2) */
@@ -3128,7 +3126,7 @@ mib_ipdefaultttl(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
int v;
size_t len = sizeof(v);
- if (sysctl(mib, sizeofa(mib), &v, &len, NULL, 0) == -1)
+ if (sysctl(mib, nitems(mib), &v, &len, NULL, 0) == -1)
return (-1);
*elm = ober_add_integer(*elm, v);
@@ -3142,7 +3140,7 @@ mib_getipstat(struct ipstat *ipstat)
int mib[] = { CTL_NET, PF_INET, IPPROTO_IP, IPCTL_STATS };
size_t len = sizeof(*ipstat);
- return (sysctl(mib, sizeofa(mib), ipstat, &len, NULL, 0));
+ return (sysctl(mib, nitems(mib), ipstat, &len, NULL, 0));
}
int
@@ -3806,7 +3804,7 @@ mib_diskio(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
len = sizeof(diskcount);
mib[1] = HW_DISKCOUNT;
- if (sysctl(mib, sizeofa(mib), &diskcount, &len, NULL, 0) == -1)
+ if (sysctl(mib, nitems(mib), &diskcount, &len, NULL, 0) == -1)
return (-1);
/* Get and verify the current row index */
@@ -3824,7 +3822,7 @@ mib_diskio(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
/* We know len won't overflow, otherwise calloc() would have failed. */
len = diskcount * sizeof(*stats);
mib[1] = HW_DISKSTATS;
- if (sysctl(mib, sizeofa(mib), stats, &len, NULL, 0) == -1) {
+ if (sysctl(mib, nitems(mib), stats, &len, NULL, 0) == -1) {
free(stats);
return (-1);
}