summaryrefslogtreecommitdiff
path: root/fad-win32.c
diff options
context:
space:
mode:
Diffstat (limited to 'fad-win32.c')
-rw-r--r--fad-win32.c129
1 files changed, 25 insertions, 104 deletions
diff --git a/fad-win32.c b/fad-win32.c
index 241a92690665..0de893ef5487 100644
--- a/fad-win32.c
+++ b/fad-win32.c
@@ -31,11 +31,6 @@
*
*/
-#ifndef lint
-static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/fad-win32.c,v 1.15 2007-09-25 20:34:36 guy Exp $ (LBL)";
-#endif
-
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -45,102 +40,6 @@ static const char rcsid[] _U_ =
#include <Packet32.h>
#include <errno.h>
-
-/*
- * Add an entry to the list of addresses for an interface.
- * "curdev" is the entry for that interface.
- */
-static int
-add_addr_to_list(pcap_if_t *curdev, struct sockaddr *addr,
- struct sockaddr *netmask, struct sockaddr *broadaddr,
- struct sockaddr *dstaddr, char *errbuf)
-{
- pcap_addr_t *curaddr, *prevaddr, *nextaddr;
-
- /*
- * Allocate the new entry and fill it in.
- */
- curaddr = (pcap_addr_t*)malloc(sizeof(pcap_addr_t));
- if (curaddr == NULL) {
- (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
- "malloc: %s", pcap_strerror(errno));
- return (-1);
- }
-
- curaddr->next = NULL;
- if (addr != NULL) {
- curaddr->addr = (struct sockaddr*)dup_sockaddr(addr, sizeof(struct sockaddr_storage));
- if (curaddr->addr == NULL) {
- (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
- "malloc: %s", pcap_strerror(errno));
- free(curaddr);
- return (-1);
- }
- } else
- curaddr->addr = NULL;
-
- if (netmask != NULL) {
- curaddr->netmask = (struct sockaddr*)dup_sockaddr(netmask, sizeof(struct sockaddr_storage));
- if (curaddr->netmask == NULL) {
- (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
- "malloc: %s", pcap_strerror(errno));
- free(curaddr);
- return (-1);
- }
- } else
- curaddr->netmask = NULL;
-
- if (broadaddr != NULL) {
- curaddr->broadaddr = (struct sockaddr*)dup_sockaddr(broadaddr, sizeof(struct sockaddr_storage));
- if (curaddr->broadaddr == NULL) {
- (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
- "malloc: %s", pcap_strerror(errno));
- free(curaddr);
- return (-1);
- }
- } else
- curaddr->broadaddr = NULL;
-
- if (dstaddr != NULL) {
- curaddr->dstaddr = (struct sockaddr*)dup_sockaddr(dstaddr, sizeof(struct sockaddr_storage));
- if (curaddr->dstaddr == NULL) {
- (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
- "malloc: %s", pcap_strerror(errno));
- free(curaddr);
- return (-1);
- }
- } else
- curaddr->dstaddr = NULL;
-
- /*
- * Find the end of the list of addresses.
- */
- for (prevaddr = curdev->addresses; prevaddr != NULL; prevaddr = nextaddr) {
- nextaddr = prevaddr->next;
- if (nextaddr == NULL) {
- /*
- * This is the end of the list.
- */
- break;
- }
- }
-
- if (prevaddr == NULL) {
- /*
- * The list was empty; this is the first member.
- */
- curdev->addresses = curaddr;
- } else {
- /*
- * "prevaddr" is the last member of the list; append
- * this member to it.
- */
- prevaddr->next = curaddr;
- }
-
- return (0);
-}
-
static int
pcap_add_if_win32(pcap_if_t **devlist, char *name, const char *desc,
@@ -189,12 +88,16 @@ pcap_add_if_win32(pcap_if_t **devlist, char *name, const char *desc,
*/
if(curdev == NULL)
break;
- res = add_addr_to_list(curdev,
+ res = add_addr_to_dev(curdev,
(struct sockaddr *)&if_addrs[if_addr_size].IPAddress,
+ sizeof (struct sockaddr_storage),
(struct sockaddr *)&if_addrs[if_addr_size].SubnetMask,
+ sizeof (struct sockaddr_storage),
(struct sockaddr *)&if_addrs[if_addr_size].Broadcast,
+ sizeof (struct sockaddr_storage),
NULL,
- errbuf);
+ 0,
+ errbuf);
if (res == -1) {
/*
* Failure.
@@ -216,7 +119,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 +128,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();