- Remove #ifdef HAVE_POLL_H.
- Use nitems(). MFC after: 3 days
This commit is contained in:
parent
e3884653f6
commit
f74237f5b6
@ -14,15 +14,13 @@
|
|||||||
#
|
#
|
||||||
# $FreeBSD$
|
# $FreeBSD$
|
||||||
|
|
||||||
SRCDIR= ${.CURDIR}/../../usr.sbin/rtsold
|
.PATH: ${.CURDIR}/../../usr.sbin/rtsold
|
||||||
|
|
||||||
.PATH: ${SRCDIR}
|
|
||||||
|
|
||||||
PROG= rtsol
|
PROG= rtsol
|
||||||
SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
|
SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
|
||||||
MAN=
|
MAN=
|
||||||
|
|
||||||
WARNS?= 3
|
WARNS?= 3
|
||||||
CFLAGS+= -DHAVE_ARC4RANDOM -DHAVE_POLL_H -DSMALL
|
CFLAGS+= -DHAVE_ARC4RANDOM -DSMALL
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <bsd.prog.mk>
|
||||||
|
@ -20,6 +20,6 @@ MLINKS= rtsold.8 rtsol.8
|
|||||||
SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
|
SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
|
||||||
|
|
||||||
WARNS?= 3
|
WARNS?= 3
|
||||||
CFLAGS+= -DHAVE_ARC4RANDOM -DHAVE_POLL_H
|
CFLAGS+= -DHAVE_ARC4RANDOM
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <bsd.prog.mk>
|
||||||
|
@ -280,18 +280,18 @@ lladdropt_fill(struct sockaddr_dl *sdl, struct nd_opt_hdr *ndopt)
|
|||||||
struct sockaddr_dl *
|
struct sockaddr_dl *
|
||||||
if_nametosdl(char *name)
|
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;
|
char *buf, *next, *lim;
|
||||||
size_t len;
|
size_t len;
|
||||||
struct if_msghdr *ifm;
|
struct if_msghdr *ifm;
|
||||||
struct sockaddr *sa, *rti_info[RTAX_MAX];
|
struct sockaddr *sa, *rti_info[RTAX_MAX];
|
||||||
struct sockaddr_dl *sdl = NULL, *ret_sdl;
|
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);
|
return(NULL);
|
||||||
if ((buf = malloc(len)) == NULL)
|
if ((buf = malloc(len)) == NULL)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
|
if (sysctl(mib, nitems(mib), buf, &len, NULL, 0) < 0) {
|
||||||
free(buf);
|
free(buf);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@ -341,7 +341,7 @@ getinet6sysctl(int code)
|
|||||||
|
|
||||||
mib[3] = code;
|
mib[3] = code;
|
||||||
size = sizeof(value);
|
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);
|
return (-1);
|
||||||
else
|
else
|
||||||
return (value);
|
return (value);
|
||||||
@ -356,7 +356,7 @@ setinet6sysctl(int code, int newval)
|
|||||||
|
|
||||||
mib[3] = code;
|
mib[3] = code;
|
||||||
size = sizeof(value);
|
size = sizeof(value);
|
||||||
if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size,
|
if (sysctl(mib, nitems(mib), &value, &size,
|
||||||
&newval, sizeof(newval)) < 0)
|
&newval, sizeof(newval)) < 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
else
|
else
|
||||||
|
@ -57,9 +57,7 @@
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#ifdef HAVE_POLL_H
|
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "rtsold.h"
|
#include "rtsold.h"
|
||||||
|
|
||||||
@ -116,13 +114,7 @@ main(int argc, char **argv)
|
|||||||
int s, ch, once = 0;
|
int s, ch, once = 0;
|
||||||
struct timespec *timeout;
|
struct timespec *timeout;
|
||||||
const char *opts;
|
const char *opts;
|
||||||
#ifdef HAVE_POLL_H
|
|
||||||
struct pollfd set[2];
|
struct pollfd set[2];
|
||||||
#else
|
|
||||||
fd_set *fdsetp, *selectfdp;
|
|
||||||
int fdmasks;
|
|
||||||
int maxfd;
|
|
||||||
#endif
|
|
||||||
int rtsock;
|
int rtsock;
|
||||||
char *argv0;
|
char *argv0;
|
||||||
|
|
||||||
@ -254,40 +246,16 @@ main(int argc, char **argv)
|
|||||||
warnmsg(LOG_ERR, __func__, "failed to open a socket");
|
warnmsg(LOG_ERR, __func__, "failed to open a socket");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#ifdef HAVE_POLL_H
|
|
||||||
set[0].fd = s;
|
set[0].fd = s;
|
||||||
set[0].events = POLLIN;
|
set[0].events = POLLIN;
|
||||||
#else
|
|
||||||
maxfd = s;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_POLL_H
|
|
||||||
set[1].fd = -1;
|
set[1].fd = -1;
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((rtsock = rtsock_open()) < 0) {
|
if ((rtsock = rtsock_open()) < 0) {
|
||||||
warnmsg(LOG_ERR, __func__, "failed to open a socket");
|
warnmsg(LOG_ERR, __func__, "failed to open a socket");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#ifdef HAVE_POLL_H
|
|
||||||
set[1].fd = rtsock;
|
set[1].fd = rtsock;
|
||||||
set[1].events = POLLIN;
|
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 */
|
/* configuration per interface */
|
||||||
if (ifinit()) {
|
if (ifinit()) {
|
||||||
@ -328,18 +296,8 @@ main(int argc, char **argv)
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef HAVE_POLL_H
|
|
||||||
memset(fdsetp, 0, fdmasks);
|
|
||||||
FD_SET(s, fdsetp);
|
|
||||||
FD_SET(rtsock, fdsetp);
|
|
||||||
#endif
|
|
||||||
while (1) { /* main loop */
|
while (1) { /* main loop */
|
||||||
int e;
|
int e;
|
||||||
|
|
||||||
#ifndef HAVE_POLL_H
|
|
||||||
memcpy(selectfdp, fdsetp, fdmasks);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef SMALL
|
#ifndef SMALL
|
||||||
if (do_dump) { /* SIGUSR1 */
|
if (do_dump) { /* SIGUSR1 */
|
||||||
do_dump = 0;
|
do_dump = 0;
|
||||||
@ -364,11 +322,7 @@ main(int argc, char **argv)
|
|||||||
if (ifi == NULL)
|
if (ifi == NULL)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_POLL_H
|
|
||||||
e = poll(set, 2, timeout ? (timeout->tv_sec * 1000 + timeout->tv_nsec / 1000 / 1000) : INFTIM);
|
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 < 1) {
|
||||||
if (e < 0 && errno != EINTR) {
|
if (e < 0 && errno != EINTR) {
|
||||||
warnmsg(LOG_ERR, __func__, "select: %s",
|
warnmsg(LOG_ERR, __func__, "select: %s",
|
||||||
@ -378,17 +332,9 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* packet reception */
|
/* packet reception */
|
||||||
#ifdef HAVE_POLL_H
|
|
||||||
if (set[1].revents & POLLIN)
|
if (set[1].revents & POLLIN)
|
||||||
#else
|
|
||||||
if (FD_ISSET(rtsock, selectfdp))
|
|
||||||
#endif
|
|
||||||
rtsock_input(rtsock);
|
rtsock_input(rtsock);
|
||||||
#ifdef HAVE_POLL_H
|
|
||||||
if (set[0].revents & POLLIN)
|
if (set[0].revents & POLLIN)
|
||||||
#else
|
|
||||||
if (FD_ISSET(s, selectfdp))
|
|
||||||
#endif
|
|
||||||
rtsol_input(s);
|
rtsol_input(s);
|
||||||
}
|
}
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
|
Loading…
Reference in New Issue
Block a user