diff options
author | Ted Lemon <source@isc.org> | 1996-06-12 23:52:38 +0000 |
---|---|---|
committer | Ted Lemon <source@isc.org> | 1996-06-12 23:52:38 +0000 |
commit | c5568eb50a41a6153a3cd3eedde12022c4f87b7d (patch) | |
tree | 5e3f8eeb6b7958bbc8ef6f18469f2f9cc3a70801 | |
parent | 3b170e0d3280bbb7d045dca1cda16d0b3ca605c8 (diff) | |
download | isc-dhcp-c5568eb50a41a6153a3cd3eedde12022c4f87b7d.tar.gz |
Add code to read and discard incoming packets on fallback socket
-rw-r--r-- | common/dispatch.c | 26 | ||||
-rw-r--r-- | common/socket.c | 15 | ||||
-rw-r--r-- | dhcpd.h | 1 | ||||
-rw-r--r-- | dispatch.c | 26 | ||||
-rw-r--r-- | includes/dhcpd.h | 1 | ||||
-rw-r--r-- | socket.c | 15 |
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 */ @@ -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 @@ -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 @@ -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 */ |