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
24 changes: 24 additions & 0 deletions pcap-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -2426,6 +2426,30 @@ setup_socket(pcap_t *handle, int is_any_device)
int err = 0;
struct packet_mreq mr;

/*
* Check if the interface exists before attempting to open
* the privileged packet socket, so we can return the correct
* error for non-existent interfaces.
*/
if (!is_any_device) {
int fd;

fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
pcapint_fmt_errmsg_for_errno(handle->errbuf,
PCAP_ERRBUF_SIZE, errno, "socket");
return PCAP_ERROR;
}
arptype = iface_get_arptype(fd, device, handle->errbuf);
close(fd);
if (arptype < 0) {
/*
* Fatal error, including PCAP_ERROR_NO_SUCH_DEVICE.
*/
return arptype;
}
}

/*
* Open a socket with protocol family packet. If cooked is true,
* we open a SOCK_DGRAM socket for the cooked interface, otherwise
Expand Down