]> The Tcpdump Group git mirrors - libpcap/commitdiff
Handle kernels that don't support PACKET_RESERVE.
authorGuy Harris <[email protected]>
Fri, 13 May 2011 07:24:42 +0000 (00:24 -0700)
committerGuy Harris <[email protected]>
Fri, 13 May 2011 07:24:42 +0000 (00:24 -0700)
If, for some reason, the header files define PACKET_RESERVE but the
kernel fails with ENOPROTOOPT if we use it in getsockopt(), treat it the
same way we treat systems that don't define PACKET_RESERVE in the first
place.  One might argue that this "can't happen", but it apparently did
happen in Debian bug 625443:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=625443

pcap-linux.c

index a72aecdcce16f5a0a28081a597839b6c59b6b0d2..245c4859e294a0cd0c3c1531fe8ecce23b511af3 100644 (file)
@@ -3223,9 +3223,17 @@ create_ring(pcap_t *handle, int *status)
 #ifdef PACKET_RESERVE
        len = sizeof(tp_reserve);
        if (getsockopt(handle->fd, SOL_PACKET, PACKET_RESERVE, &tp_reserve, &len) < 0) {
-               snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "getsockopt: %s", pcap_strerror(errno));
-               *status = PCAP_ERROR;
-               return -1;
+               if (errno != ENOPROTOOPT) {
+                       /*
+                        * ENOPROTOOPT means "kernel doesn't support
+                        * PACKET_RESERVE", in which case we fall back
+                        * as best we can.
+                        */
+                       snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "getsockopt: %s", pcap_strerror(errno));
+                       *status = PCAP_ERROR;
+                       return -1;
+               }
+               tp_reserve = 0; /* older kernel, reserve not supported */
        }
 #else
        tp_reserve = 0; /* older kernel, reserve not supported */