diff options
author | hrs <hrs@FreeBSD.org> | 2015-09-10 06:40:28 +0000 |
---|---|---|
committer | hrs <hrs@FreeBSD.org> | 2015-09-10 06:40:28 +0000 |
commit | f39d1c8c533fb4dabb8124a02bca16f62df9bdd2 (patch) | |
tree | 32ea21e1e6acec85604bf8b22a55db44c944d01a /usr.sbin/rtsold | |
parent | e16dfdb9eff2cdcad4447658b212385fd9a73db3 (diff) | |
download | FreeBSD-src-f39d1c8c533fb4dabb8124a02bca16f62df9bdd2.zip FreeBSD-src-f39d1c8c533fb4dabb8124a02bca16f62df9bdd2.tar.gz |
- Remove #ifdef HAVE_POLL_H.
- Use nitems().
MFC after: 3 days
Diffstat (limited to 'usr.sbin/rtsold')
-rw-r--r-- | usr.sbin/rtsold/Makefile | 2 | ||||
-rw-r--r-- | usr.sbin/rtsold/if.c | 10 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsold.c | 54 |
3 files changed, 6 insertions, 60 deletions
diff --git a/usr.sbin/rtsold/Makefile b/usr.sbin/rtsold/Makefile index a235dfb..caef62c 100644 --- a/usr.sbin/rtsold/Makefile +++ b/usr.sbin/rtsold/Makefile @@ -20,6 +20,6 @@ MLINKS= rtsold.8 rtsol.8 SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c WARNS?= 3 -CFLAGS+= -DHAVE_ARC4RANDOM -DHAVE_POLL_H +CFLAGS+= -DHAVE_ARC4RANDOM .include <bsd.prog.mk> diff --git a/usr.sbin/rtsold/if.c b/usr.sbin/rtsold/if.c index b8a90b6..cb4b001 100644 --- a/usr.sbin/rtsold/if.c +++ b/usr.sbin/rtsold/if.c @@ -280,18 +280,18 @@ lladdropt_fill(struct sockaddr_dl *sdl, struct nd_opt_hdr *ndopt) struct sockaddr_dl * if_nametosdl(char *name) { - int mib[6] = {CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0}; + int mib[] = {CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0}; char *buf, *next, *lim; size_t len; struct if_msghdr *ifm; struct sockaddr *sa, *rti_info[RTAX_MAX]; struct sockaddr_dl *sdl = NULL, *ret_sdl; - if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) + if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) < 0) return(NULL); if ((buf = malloc(len)) == NULL) return(NULL); - if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) { + if (sysctl(mib, nitems(mib), buf, &len, NULL, 0) < 0) { free(buf); return (NULL); } @@ -341,7 +341,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, nitems(mib), &value, &size, NULL, 0) < 0) return (-1); else return (value); @@ -356,7 +356,7 @@ setinet6sysctl(int code, int newval) mib[3] = code; size = sizeof(value); - if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, + if (sysctl(mib, nitems(mib), &value, &size, &newval, sizeof(newval)) < 0) return (-1); else diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c index bba15bb..18621bd 100644 --- a/usr.sbin/rtsold/rtsold.c +++ b/usr.sbin/rtsold/rtsold.c @@ -57,9 +57,7 @@ #include <err.h> #include <stdarg.h> #include <ifaddrs.h> -#ifdef HAVE_POLL_H #include <poll.h> -#endif #include "rtsold.h" @@ -116,13 +114,7 @@ main(int argc, char **argv) int s, ch, once = 0; struct timespec *timeout; const char *opts; -#ifdef HAVE_POLL_H struct pollfd set[2]; -#else - fd_set *fdsetp, *selectfdp; - int fdmasks; - int maxfd; -#endif int rtsock; char *argv0; @@ -254,40 +246,16 @@ main(int argc, char **argv) warnmsg(LOG_ERR, __func__, "failed to open a socket"); exit(1); } -#ifdef HAVE_POLL_H set[0].fd = s; set[0].events = POLLIN; -#else - maxfd = s; -#endif - -#ifdef HAVE_POLL_H set[1].fd = -1; -#endif if ((rtsock = rtsock_open()) < 0) { warnmsg(LOG_ERR, __func__, "failed to open a socket"); exit(1); } -#ifdef HAVE_POLL_H set[1].fd = rtsock; set[1].events = POLLIN; -#else - if (rtsock > maxfd) - maxfd = rtsock; -#endif - -#ifndef HAVE_POLL_H - fdmasks = howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask); - if ((fdsetp = malloc(fdmasks)) == NULL) { - warnmsg(LOG_ERR, __func__, "malloc"); - exit(1); - } - if ((selectfdp = malloc(fdmasks)) == NULL) { - warnmsg(LOG_ERR, __func__, "malloc"); - exit(1); - } -#endif /* configuration per interface */ if (ifinit()) { @@ -328,18 +296,8 @@ main(int argc, char **argv) fclose(fp); } } -#ifndef HAVE_POLL_H - memset(fdsetp, 0, fdmasks); - FD_SET(s, fdsetp); - FD_SET(rtsock, fdsetp); -#endif while (1) { /* main loop */ int e; - -#ifndef HAVE_POLL_H - memcpy(selectfdp, fdsetp, fdmasks); -#endif - #ifndef SMALL if (do_dump) { /* SIGUSR1 */ do_dump = 0; @@ -364,11 +322,7 @@ main(int argc, char **argv) if (ifi == NULL) break; } -#ifdef HAVE_POLL_H e = poll(set, 2, timeout ? (timeout->tv_sec * 1000 + timeout->tv_nsec / 1000 / 1000) : INFTIM); -#else - e = select(maxfd + 1, selectfdp, NULL, NULL, timeout); -#endif if (e < 1) { if (e < 0 && errno != EINTR) { warnmsg(LOG_ERR, __func__, "select: %s", @@ -378,17 +332,9 @@ main(int argc, char **argv) } /* packet reception */ -#ifdef HAVE_POLL_H if (set[1].revents & POLLIN) -#else - if (FD_ISSET(rtsock, selectfdp)) -#endif rtsock_input(rtsock); -#ifdef HAVE_POLL_H if (set[0].revents & POLLIN) -#else - if (FD_ISSET(s, selectfdp)) -#endif rtsol_input(s); } /* NOTREACHED */ |