aboutsummaryrefslogtreecommitdiffstats
path: root/pcap-linux.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2009-10-11 22:15:24 -0700
committerGuy Harris <guy@alum.mit.edu>2009-10-11 22:15:24 -0700
commite6b89d9420708a324c1e4bc3e6a2021709b3e875 (patch)
treee4c26717eb6d6a10e8906879b266aa24ebc83a1b /pcap-linux.c
parent86ecdb83e0c1f507dd24b89c4c3f5829985d4f99 (diff)
If we get POLLERR when polling a socket in memory-mapped mode, do a
recv() on the socket to get the error code.
Diffstat (limited to 'pcap-linux.c')
-rw-r--r--pcap-linux.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/pcap-linux.c b/pcap-linux.c
index 29d79c4..8356ba5 100644
--- a/pcap-linux.c
+++ b/pcap-linux.c
@@ -1365,7 +1365,7 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata)
*
* XXX - we should really return
* PCAP_ERROR_IFACE_NOT_UP, but pcap_dispatch()
- * etc. aren't defined to retur that.
+ * etc. aren't defined to return that.
*/
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"The interface went down");
@@ -2934,6 +2934,7 @@ pcap_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback,
u_char *user)
{
int pkts = 0;
+ char c;
/* wait for frames availability.*/
if ((handle->md.timeout >= 0) &&
@@ -2970,9 +2971,35 @@ pcap_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback,
return PCAP_ERROR;
}
if (pollinfo.revents & POLLERR) {
- snprintf(handle->errbuf,
- PCAP_ERRBUF_SIZE,
- "Error condition on packet socket");
+ /*
+ * A recv() will give us the
+ * actual error code.
+ *
+ * XXX - make the socket non-blocking?
+ */
+ if (recv(handle->fd, c, sizeof c,
+ MSG_PEEK) != -1)
+ continue; /* what, no error? */
+ if (errno == ENETDOWN) {
+ /*
+ * The device on which we're
+ * capturing went away.
+ *
+ * XXX - we should really return
+ * PCAP_ERROR_IFACE_NOT_UP,
+ * but pcap_dispatch() etc.
+ * aren't defined to return
+ * that.
+ */
+ snprintf(handle->errbuf,
+ PCAP_ERRBUF_SIZE,
+ "The interface went down");
+ } else {
+ snprintf(handle->errbuf,
+ PCAP_ERRBUF_SIZE,
+ "Error condition on packet socket: %s",
+ strerror(errno));
+ }
return PCAP_ERROR;
}
if (pollinfo.revents & POLLNVAL) {