Skip to content

Commit f15b254

Browse files
committed
Return an appropriate error message for ERROR_GEN_FAILURE when capturing.
That's the error returned if the capture stops working because either 1) the device was removed (unplugged) or 2) the device becomes unusable for capturing due to a suspend/resume.
1 parent 8072538 commit f15b254

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

pcap-npf.c

+28-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,34 @@ pcap_read_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
523523
*/
524524
PacketInitPacket(&Packet, (BYTE *)p->buffer, p->bufsize);
525525
if (!PacketReceivePacket(pw->adapter, &Packet, TRUE)) {
526-
pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read error: PacketReceivePacket failed");
526+
/*
527+
* Did the device go away?
528+
* If so, the error we get is ERROR_GEN_FAILURE.
529+
*/
530+
DWORD errcode = GetLastError();
531+
532+
if (errcode == ERROR_GEN_FAILURE) {
533+
/*
534+
* The device on which we're capturing
535+
* went away, or it became unusable
536+
* by NPF due to a suspend/resume.
537+
*
538+
* XXX - hopefully no other error
539+
* conditions are indicated by this.
540+
*
541+
* XXX - we really should return an
542+
* appropriate error for that, but
543+
* pcap_dispatch() etc. aren't
544+
* documented as having error returns
545+
* other than PCAP_ERROR or PCAP_ERROR_BREAK.
546+
*/
547+
pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
548+
"The interface disappeared");
549+
} else {
550+
pcap_fmt_errmsg_for_win32_err(p->errbuf,
551+
PCAP_ERRBUF_SIZE, errcode,
552+
"PacketReceivePacket error");
553+
}
527554
return (PCAP_ERROR);
528555
}
529556

0 commit comments

Comments
 (0)