2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-31 22:35:25 +00:00

Add code to read and discard incoming packets on fallback socket

This commit is contained in:
Ted Lemon
1996-06-12 23:52:38 +00:00
parent 3b170e0d32
commit c5568eb50a
6 changed files with 82 additions and 2 deletions

View File

@@ -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 */

View File

@@ -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 */

View File

@@ -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

View File

@@ -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 */

View File

@@ -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

View File

@@ -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 */