From 48859413cdeec6161df494fba1da66bead5b8ee3 Mon Sep 17 00:00:00 2001 From: dfr Date: Mon, 30 Jan 1995 11:11:43 +0000 Subject: 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. --- libexec/bootpd/rtmsg.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'libexec/bootpd') diff --git a/libexec/bootpd/rtmsg.c b/libexec/bootpd/rtmsg.c index 7d0e8f4..41b8273 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 @@ -50,6 +50,7 @@ #if BSD >= 199306 #include +#include #include #include @@ -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)); -- cgit v1.1