From 9e9f5dde21c9ad4a67e8b0eb2b07792faffcee41 Mon Sep 17 00:00:00 2001 From: gianluca Date: Mon, 19 Feb 2007 18:33:37 +0000 Subject: [PATCH] Fixed a bug in pcap_open_live(). The return value of PacketSetHwFilter was not checked. This was the culprit of WinPcap failing to capture on wireless adapters when in promiscuous mode. Most of the wireless adapters drivers do not support the promiscuous hardware, and fail the HW filter OID request. This failure was not detected by pcap_open_live(), and resulted in no packets being captured as no hw filter was actually set at the driver level (no hw filter means "reject all"). --- pcap-win32.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/pcap-win32.c b/pcap-win32.c index acd50d9..8f58f64 100644 --- a/pcap-win32.c +++ b/pcap-win32.c @@ -1,6 +1,6 @@ /* * Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy) - * Copyright (c) 2005 - 2006 CACE Technologies, Davis (California) + * Copyright (c) 2005 - 2007 CACE Technologies, Davis (California) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,7 +33,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.25.2.5 2006-08-09 19:18:41 gianluca Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.25.2.6 2007-02-19 18:33:37 gianluca Exp $ (LBL)"; #endif #include @@ -500,9 +500,24 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms, break; } - /* Set promisquous mode */ - if (promisc) PacketSetHwFilter(p->adapter,NDIS_PACKET_TYPE_PROMISCUOUS); - else PacketSetHwFilter(p->adapter,NDIS_PACKET_TYPE_ALL_LOCAL); + /* Set promiscuous mode */ + if (promisc) + { + + if (PacketSetHwFilter(p->adapter,NDIS_PACKET_TYPE_PROMISCUOUS) == FALSE) + { + snprintf(ebuf, PCAP_ERRBUF_SIZE, "failed to set hardware filter to promiscuous mode"); + goto bad; + } + } + else + { + if (PacketSetHwFilter(p->adapter,NDIS_PACKET_TYPE_ALL_LOCAL) == FALSE) + { + snprintf(ebuf, PCAP_ERRBUF_SIZE, "failed to set hardware filter to non-promiscuous mode"); + goto bad; + } + } /* Set the buffer size */ p->bufsize = PcapBufSize;