summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorguy <guy>2006-04-07 08:02:45 +0000
committerguy <guy>2006-04-07 08:02:45 +0000
commit9651ac1a9b9ea29db946b3c30efe21b39af9ead3 (patch)
tree7ca322d3d321a51b9d8dc12c71f718733344daed
parent382177b574aa30c1b061e6ccd909433b7910f058 (diff)
downloadlibpcap-9651ac1a9b9ea29db946b3c30efe21b39af9ead3.tar.gz
From Ollie Wild: if we're bound to an interface, discard incoming
packets that didn't arrive on that interface, so packets from other interfaces that get onto the socket queue before we bind the socket to the interface don't get supplied to the application (binding the socket doesn't discard incoming packets).
-rw-r--r--CREDITS1
-rw-r--r--pcap-linux.c18
2 files changed, 18 insertions, 1 deletions
diff --git a/CREDITS b/CREDITS
index c1203360..483482d7 100644
--- a/CREDITS
+++ b/CREDITS
@@ -70,6 +70,7 @@ Additional people who have contributed patches:
Nicolas Dade <ndade@nsd.dyndns.org>
Octavian Cerna <tavy@ylabs.com>
Olaf Kirch <okir@caldera.de>
+ Ollie Wild <aaw@users.sourceforge.net>
Onno van der Linden <onno@simplex.nl>
Patrick Marie <mycroft@virgaria.org>
Paul Mundt <lethal@linux-sh.org>
diff --git a/pcap-linux.c b/pcap-linux.c
index 321847dd..5ad041b9 100644
--- a/pcap-linux.c
+++ b/pcap-linux.c
@@ -27,7 +27,7 @@
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.110.2.10 2006-02-23 07:35:35 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.110.2.11 2006-04-07 08:02:45 guy Exp $ (LBL)";
#endif
/*
@@ -527,6 +527,22 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata)
#ifdef HAVE_PF_PACKET_SOCKETS
if (!handle->md.sock_packet) {
/*
+ * Unfortunately, there is a window between socket() and
+ * bind() where the kernel may queue packets from any
+ * interface. If we're bound to a particular interface,
+ * discard packets not from that interface.
+ *
+ * (If socket filters are supported, we could do the
+ * same thing we do when changing the filter; however,
+ * that won't handle packet sockets without socket
+ * filter support, and it's a bit more complicated.
+ * It would save some instructions per packet, however.)
+ */
+ if (handle->md.ifindex != -1 &&
+ from.sll_ifindex != handle->md.ifindex)
+ return 0;
+
+ /*
* Do checks based on packet direction.
* We can only do this if we're using PF_PACKET; the
* address returned for SOCK_PACKET is a "sockaddr_pkt"