Permalink
Browse files

Rename pcap_findalldevs() to pcap_findalldevs_interfaces().

pcap_findalldevs() is now a libpcap API, and expects the main "find all
interfaces" call for the platform to be named
pcap_findalldevs_interfaces(); make it so.

Also, note that the first PacketGetAdapterNames() is trying to find out
how big the packet buffer should be, and should always return FALSE.
Initialize the NameLength variable, because PacketGetAdapterNames() may
refer to it before it's set (harmlessly, but might as well be clean
here, at least until it's fixed to check the pointer argument first).
  • Loading branch information...
1 parent 73b5f03 commit 09d5e420b068ec4b587bc09c17e6b64c573889ae @guyharris guyharris committed Apr 4, 2013
Showing with 19 additions and 1 deletion.
  1. +19 −1 fad-win32.c
View
@@ -216,7 +216,7 @@ pcap_add_if_win32(pcap_if_t **devlist, char *name, const char *desc,
* Win32 implementation, based on WinPcap
*/
int
-pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
+pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
{
pcap_if_t *devlist = NULL;
int ret = 0;
@@ -225,6 +225,24 @@ pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
ULONG NameLength;
char *name;
+ /*
+ * Find out how big a buffer we need.
+ *
+ * This call should always return FALSE; if the error is
+ * ERROR_INSUFFICIENT_BUFFER, NameLength will be set to
+ * the size of the buffer we need, otherwise there's a
+ * problem, and NameLength should be set to 0.
+ *
+ * It shouldn't require NameLength to be set, but,
+ * at least as of WinPcap 4.1.3, it checks whether
+ * NameLength is big enough before it checks for a
+ * NULL buffer argument, so, while it'll still do
+ * the right thing if NameLength is uninitialized and
+ * whatever junk happens to be there is big enough
+ * (because the pointer argument will be null), it's
+ * still reading an uninitialized variable.
+ */
+ NameLength = 0;
if (!PacketGetAdapterNames(NULL, &NameLength))
{
DWORD last_error = GetLastError();

0 comments on commit 09d5e42

Please sign in to comment.