Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/dhcp_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ static const char copyright[] = "Copyright 2000-2021, The Trustees of Princeton
static const char contact[] = "networking at princeton dot edu";
#endif

#define PCAP_PACKET_BUFFER_TIMEOUT_DIVISOR 20
#define PCAP_PACKET_BUFFER_TIMEOUT_MIN_MS 1

/* initialize options to defaults */
int debug = 0;
int dont_fork = 0;
Expand Down Expand Up @@ -75,6 +78,9 @@ struct ether_addr my_eaddr;
int use_8021q = 0;
int vlan_id = 0;

/* Forward Declarations */
static int get_pcap_packet_buffer_timeout_ms(void);

int
main(int argc, char **argv)
{
Expand Down Expand Up @@ -517,7 +523,7 @@ main(int argc, char **argv)
pcap_open_retries = PCAP_OPEN_LIVE_RETRY_MAX;
while (pcap_open_retries--) {
pcap_errbuf[0] = '\0'; /* so we can tell if a warning was produced on success */
if ((pd = pcap_open_live(ifname, snaplen, promiscuous, GetResponse_wait_time(), pcap_errbuf)) != NULL) {
if ((pd = pcap_open_live(ifname, snaplen, promiscuous, get_pcap_packet_buffer_timeout_ms(), pcap_errbuf)) != NULL) {
break; /* success */
} else { /* failure */
if (pcap_open_retries == 0) {
Expand Down Expand Up @@ -1297,3 +1303,22 @@ usage(void)
return;
}

/*
* pcap_open_live()'s timeout is a packet buffer timeout, not the
* total amount of time dhcp_probe should wait for responses. Keep
* the pcap buffer timeout shorter than response_wait_time so
* pcap_dispatch() periodically returns and processes any buffered
* replies before our SIGALRM-based response window expires.
*/
static int
get_pcap_packet_buffer_timeout_ms(void)
{
int pcap_timeout;

pcap_timeout = GetResponse_wait_time() / PCAP_PACKET_BUFFER_TIMEOUT_DIVISOR;

if (pcap_timeout < PCAP_PACKET_BUFFER_TIMEOUT_MIN_MS)
pcap_timeout = PCAP_PACKET_BUFFER_TIMEOUT_MIN_MS;

return pcap_timeout;
}