aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fad-win32.c104
-rw-r--r--inet.c21
-rw-r--r--pcap-int.h3
3 files changed, 29 insertions, 99 deletions
diff --git a/fad-win32.c b/fad-win32.c
index 743539aa..0de893ef 100644
--- a/fad-win32.c
+++ b/fad-win32.c
@@ -40,102 +40,6 @@
#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,
@@ -184,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.
diff --git a/inet.c b/inet.c
index b2b37cea..b7ea42b3 100644
--- a/inet.c
+++ b/inet.c
@@ -424,7 +424,6 @@ add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
{
pcap_if_t *curdev;
char *description = NULL;
- pcap_addr_t *curaddr, *prevaddr, *nextaddr;
#ifdef SIOCGIFDESCR
int s;
struct ifreq ifrdesc;
@@ -521,6 +520,26 @@ add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
*
* Allocate the new entry and fill it in.
*/
+ return (add_addr_to_dev(curdev, addr, addr_size, netmask, netmask_size,
+ broadaddr, broadaddr_size, dstaddr, dstaddr_size, errbuf));
+}
+
+/*
+ * Add an entry to the list of addresses for an interface.
+ * "curdev" is the entry for that interface.
+ * If this is the first IP address added to the interface, move it
+ * in the list as appropriate.
+ */
+int
+add_addr_to_dev(pcap_if_t *curdev,
+ struct sockaddr *addr, size_t addr_size,
+ struct sockaddr *netmask, size_t netmask_size,
+ struct sockaddr *broadaddr, size_t broadaddr_size,
+ struct sockaddr *dstaddr, size_t dstaddr_size,
+ char *errbuf)
+{
+ pcap_addr_t *curaddr, *prevaddr, *nextaddr;
+
curaddr = malloc(sizeof(pcap_addr_t));
if (curaddr == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
diff --git a/pcap-int.h b/pcap-int.h
index 9f80fa6f..6d6febe9 100644
--- a/pcap-int.h
+++ b/pcap-int.h
@@ -385,6 +385,9 @@ int pcap_platform_finddevs(pcap_if_t **, char *);
int add_addr_to_iflist(pcap_if_t **, const char *, u_int, struct sockaddr *,
size_t, struct sockaddr *, size_t, struct sockaddr *, size_t,
struct sockaddr *, size_t, char *);
+int add_addr_to_dev(pcap_if_t *, struct sockaddr *, size_t,
+ struct sockaddr *, size_t, struct sockaddr *, size_t,
+ struct sockaddr *dstaddr, size_t, char *errbuf);
int pcap_add_if(pcap_if_t **, const char *, u_int, const char *, char *);
struct sockaddr *dup_sockaddr(struct sockaddr *, size_t);
int add_or_find_if(pcap_if_t **, pcap_if_t **, const char *, u_int,