From 955052cf21930fcf2c9665a5484432e19f738c85 Mon Sep 17 00:00:00 2001 From: Bill Fumerola Date: Sun, 20 Jan 2002 12:13:28 +0000 Subject: [PATCH] from select(2): Any of readfds, writefds, and exceptfds may be given as nil pointers if no descriptors are of interest. neither wfds nor efds were of interest so now they are nil. also, do a little better then making an educated guess for nfds. --- sbin/nos-tun/nos-tun.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sbin/nos-tun/nos-tun.c b/sbin/nos-tun/nos-tun.c index 79519fa08999..38678faf77c8 100644 --- a/sbin/nos-tun/nos-tun.c +++ b/sbin/nos-tun/nos-tun.c @@ -251,8 +251,9 @@ int main (int argc, char **argv) char buf[0x2000]; /* Packets buffer */ struct ip *ip = (struct ip *)buf; - fd_set rfds, wfds, efds; /* File descriptors for select() */ + fd_set rfds; /* File descriptors for select() */ int nfds; /* Return from select() */ + int lastfd; /* highest fd we care about */ while ((c = getopt(argc, argv, "d:s:t:p:")) != -1) { @@ -335,12 +336,17 @@ int main (int argc, char **argv) (void)signal(SIGINT,Finish); (void)signal(SIGTERM,Finish); + if (tun > net) + lastfd = tun; + else + lastfd = net; + for (;;) { /* Set file descriptors for select() */ - FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&efds); + FD_ZERO(&rfds); FD_SET(tun,&rfds); FD_SET(net,&rfds); - nfds = select(net+10,&rfds,&wfds,&efds,NULL); + nfds = select(lastfd+1,&rfds,NULL,NULL,NULL); if(nfds < 0) { syslog(LOG_ERR,"interrupted select"); close(net);