aboutsummaryrefslogtreecommitdiff
path: root/libexec/bootpd/rtmsg.c
diff options
context:
space:
mode:
authorDoug Rabson <dfr@FreeBSD.org>1995-01-30 11:11:43 +0000
committerDoug Rabson <dfr@FreeBSD.org>1995-01-30 11:11:43 +0000
commit7cb18415b8a370eef92a029067988617b4eb84f3 (patch)
treef7c0442786190552d5019cf6030f8b593c99682b /libexec/bootpd/rtmsg.c
parent3f4fff96f9d5159d91735c4c5593e16a11b9d87f (diff)
Discard any messages which are buffered on the routing socket before using
it otherwise the response to one of our routing messages could be lost due to buffer overflow.
Notes
svn path=/head/; revision=6034
Diffstat (limited to 'libexec/bootpd/rtmsg.c')
-rw-r--r--libexec/bootpd/rtmsg.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/libexec/bootpd/rtmsg.c b/libexec/bootpd/rtmsg.c
index 7d0e8f4e1e2c..41b8273dcc67 100644
--- a/libexec/bootpd/rtmsg.c
+++ b/libexec/bootpd/rtmsg.c
@@ -39,7 +39,7 @@
/*
* from arp.c 8.2 (Berkeley) 1/2/94
- * $Id: rtmsg.c,v 1.1.1.1 1994/09/30 05:45:06 pst Exp $
+ * $Id: rtmsg.c,v 1.2 1995/01/16 18:57:45 dfr Exp $
*/
#include <sys/param.h>
@@ -50,6 +50,7 @@
#if BSD >= 199306
#include <sys/socket.h>
+#include <sys/filio.h>
#include <net/if.h>
#include <net/if_dl.h>
@@ -85,6 +86,18 @@ static void getsocket () {
report(LOG_ERR, "socket %s", strerror(errno));
exit(1);
}
+ } else {
+ /*
+ * Drain the socket of any unwanted routing messages.
+ */
+ int n;
+ char buf[512];
+
+ ioctl(s, FIONREAD, &n);
+ while (n > 0) {
+ read(s, buf, sizeof buf);
+ ioctl(s, FIONREAD, &n);
+ }
}
}
@@ -228,7 +241,7 @@ static int rtmsg(cmd)
}
do {
l = read(s, (char *)&m_rtmsg, sizeof(m_rtmsg));
- } while (l > 0 && (rtm->rtm_seq != seq || rtm->rtm_pid != getpid()));
+ } while (l > 0 && (rtm->rtm_type != cmd || rtm->rtm_seq != seq || rtm->rtm_pid != getpid()));
if (l < 0)
report(LOG_WARNING, "arp: read from routing socket: %s\n",
strerror(errno));