summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Lemon <source@isc.org>1996-06-12 23:52:38 +0000
committerTed Lemon <source@isc.org>1996-06-12 23:52:38 +0000
commitc5568eb50a41a6153a3cd3eedde12022c4f87b7d (patch)
tree5e3f8eeb6b7958bbc8ef6f18469f2f9cc3a70801
parent3b170e0d3280bbb7d045dca1cda16d0b3ca605c8 (diff)
downloadisc-dhcp-c5568eb50a41a6153a3cd3eedde12022c4f87b7d.tar.gz
Add code to read and discard incoming packets on fallback socket
-rw-r--r--common/dispatch.c26
-rw-r--r--common/socket.c15
-rw-r--r--dhcpd.h1
-rw-r--r--dispatch.c26
-rw-r--r--includes/dhcpd.h1
-rw-r--r--socket.c15
6 files changed, 82 insertions, 2 deletions
diff --git a/common/dispatch.c b/common/dispatch.c
index bc9ebe11..5c278ea1 100644
--- a/common/dispatch.c
+++ b/common/dispatch.c
@@ -280,7 +280,10 @@ void dispatch ()
for (l = interfaces; l; l = l -> next) {
++nfds;
}
- fds = (struct pollfd *)malloc (nfds * sizeof (struct pollfd));
+#ifdef USE_FALLBACK
+ ++nfds;
+#endif
+ fds = (struct pollfd *)malloc ((nfds) * sizeof (struct pollfd));
if (!fds)
error ("Can't allocate poll structures.");
@@ -292,6 +295,13 @@ void dispatch ()
++i;
}
+#ifdef USE_FALLBACK
+ fds [i].fd = fallback_interface.wfdesc;
+ fds [i].events = POLLIN;
+ fds [i].revents = 0;
+ ++i;
+#endif
+
do {
/* Wait for a packet or a timeout... XXX */
count = poll (fds, nfds, -1);
@@ -310,6 +320,10 @@ void dispatch ()
fds [i].revents = 0;
got_one (l);
}
+#ifdef USE_FALLBACK
+ if (fds [i].revents & POLLIN)
+ fallback_discard (&fallback_interface);
+#endif
} while (1);
}
#else
@@ -337,6 +351,12 @@ void dispatch ()
if (l -> rfdesc > max)
max = l -> rfdesc;
}
+#ifdef USE_FALLBACK
+ FD_SET (fallback_interface.wfdesc, &r);
+ FD_SET (fallback_interface.wfdesc, &w);
+ if (fallback_interface.wfdesc > max)
+ max = fallback_interface.wfdesc;
+#endif
/* Wait for a packet or a timeout... XXX */
count = select (max + 1, &r, &w, &x, (struct timeval *)0);
@@ -353,6 +373,10 @@ void dispatch ()
continue;
got_one (l);
}
+#ifdef USE_FALLBACK
+ if (FD_ISSET (fallback_interface.wfdesc, &r))
+ fallback_discard (&fallback_interface);
+#endif
} while (1);
}
#endif /* USE_POLL */
diff --git a/common/socket.c b/common/socket.c
index 2ce80452..56c84ddc 100644
--- a/common/socket.c
+++ b/common/socket.c
@@ -182,3 +182,18 @@ size_t receive_packet (interface, buf, len, from, hfrom)
(struct sockaddr *)from, &flen);
}
#endif /* USE_SOCKET_RECEIVE */
+
+#ifdef USE_SOCKET_FALLBACK
+/* This just reads in a packet and silently discards it. */
+
+size_t fallback_discard (interface)
+ struct interface_info *interface;
+{
+ char buf [1540];
+ struct sockaddr_in from;
+ int flen = sizeof from;
+
+ return recvfrom (interface -> wfdesc, buf, sizeof buf, 0,
+ (struct sockaddr *)&from, &flen);
+}
+#endif /* USE_SOCKET_RECEIVE */
diff --git a/dhcpd.h b/dhcpd.h
index 1856f343..9081d9bf 100644
--- a/dhcpd.h
+++ b/dhcpd.h
@@ -401,6 +401,7 @@ size_t send_fallback PROTO ((struct interface_info *,
struct packet *, struct dhcp_packet *, size_t,
struct in_addr,
struct sockaddr_in *, struct hardware *));
+size_t fallback_discard PROTO ((struct interface_info *));
#endif
#ifdef USE_SOCKET_SEND
diff --git a/dispatch.c b/dispatch.c
index bc9ebe11..5c278ea1 100644
--- a/dispatch.c
+++ b/dispatch.c
@@ -280,7 +280,10 @@ void dispatch ()
for (l = interfaces; l; l = l -> next) {
++nfds;
}
- fds = (struct pollfd *)malloc (nfds * sizeof (struct pollfd));
+#ifdef USE_FALLBACK
+ ++nfds;
+#endif
+ fds = (struct pollfd *)malloc ((nfds) * sizeof (struct pollfd));
if (!fds)
error ("Can't allocate poll structures.");
@@ -292,6 +295,13 @@ void dispatch ()
++i;
}
+#ifdef USE_FALLBACK
+ fds [i].fd = fallback_interface.wfdesc;
+ fds [i].events = POLLIN;
+ fds [i].revents = 0;
+ ++i;
+#endif
+
do {
/* Wait for a packet or a timeout... XXX */
count = poll (fds, nfds, -1);
@@ -310,6 +320,10 @@ void dispatch ()
fds [i].revents = 0;
got_one (l);
}
+#ifdef USE_FALLBACK
+ if (fds [i].revents & POLLIN)
+ fallback_discard (&fallback_interface);
+#endif
} while (1);
}
#else
@@ -337,6 +351,12 @@ void dispatch ()
if (l -> rfdesc > max)
max = l -> rfdesc;
}
+#ifdef USE_FALLBACK
+ FD_SET (fallback_interface.wfdesc, &r);
+ FD_SET (fallback_interface.wfdesc, &w);
+ if (fallback_interface.wfdesc > max)
+ max = fallback_interface.wfdesc;
+#endif
/* Wait for a packet or a timeout... XXX */
count = select (max + 1, &r, &w, &x, (struct timeval *)0);
@@ -353,6 +373,10 @@ void dispatch ()
continue;
got_one (l);
}
+#ifdef USE_FALLBACK
+ if (FD_ISSET (fallback_interface.wfdesc, &r))
+ fallback_discard (&fallback_interface);
+#endif
} while (1);
}
#endif /* USE_POLL */
diff --git a/includes/dhcpd.h b/includes/dhcpd.h
index 1856f343..9081d9bf 100644
--- a/includes/dhcpd.h
+++ b/includes/dhcpd.h
@@ -401,6 +401,7 @@ size_t send_fallback PROTO ((struct interface_info *,
struct packet *, struct dhcp_packet *, size_t,
struct in_addr,
struct sockaddr_in *, struct hardware *));
+size_t fallback_discard PROTO ((struct interface_info *));
#endif
#ifdef USE_SOCKET_SEND
diff --git a/socket.c b/socket.c
index 2ce80452..56c84ddc 100644
--- a/socket.c
+++ b/socket.c
@@ -182,3 +182,18 @@ size_t receive_packet (interface, buf, len, from, hfrom)
(struct sockaddr *)from, &flen);
}
#endif /* USE_SOCKET_RECEIVE */
+
+#ifdef USE_SOCKET_FALLBACK
+/* This just reads in a packet and silently discards it. */
+
+size_t fallback_discard (interface)
+ struct interface_info *interface;
+{
+ char buf [1540];
+ struct sockaddr_in from;
+ int flen = sizeof from;
+
+ return recvfrom (interface -> wfdesc, buf, sizeof buf, 0,
+ (struct sockaddr *)&from, &flen);
+}
+#endif /* USE_SOCKET_RECEIVE */