From 244e7eddd25cd4d3ce13506daa549b7591692fbd Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 10 Mar 2010 11:43:47 +0000 Subject: [PATCH] Changed pktif/pcap_helper again for portability --- ports/win32/pcap_helper.c | 19 ++++++++++++------- ports/win32/pcap_helper.h | 7 +++++-- ports/win32/pktif.c | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ports/win32/pcap_helper.c b/ports/win32/pcap_helper.c index 0551386..8462cd3 100644 --- a/ports/win32/pcap_helper.c +++ b/ports/win32/pcap_helper.c @@ -4,7 +4,6 @@ /* get the windows definitions of the following 4 functions out of the way */ #include #include -#include #define HAVE_REMOTE #include "pcap.h" @@ -14,7 +13,7 @@ * @return index of the adapter or negative on error */ int -get_adapter_index_from_addr(u32_t netaddr, char *guid, u32_t guid_len) +get_adapter_index_from_addr(struct in_addr *netaddr, char *guid, size_t guid_len) { pcap_if_t *alldevs; pcap_if_t *d; @@ -34,14 +33,20 @@ get_adapter_index_from_addr(u32_t netaddr, char *guid, u32_t guid_len) pcap_addr_t *a; for(a = d->addresses; a != NULL; a = a->next) { if (a->addr->sa_family == AF_INET) { - u32_t a_addr = ((struct sockaddr_in *)a->addr)->sin_addr.s_addr; - u32_t a_netmask = ((struct sockaddr_in *)a->netmask)->sin_addr.s_addr; - u32_t a_netaddr = a_addr & a_netmask; - if (a_netaddr == netaddr) { + ULONG a_addr = ((struct sockaddr_in *)a->addr)->sin_addr.s_addr; + ULONG a_netmask = ((struct sockaddr_in *)a->netmask)->sin_addr.s_addr; + ULONG a_netaddr = a_addr & a_netmask; + ULONG addr = (*netaddr).s_addr; + if (a_netaddr == addr) { int ret = -1; char name[128]; char *start, *end; - strcpy(name, d->name); + size_t len = strlen(d->name); + if(len > 127) { + len = 127; + } + memcpy(name, d->name, len); + name[len] = 0; start = strstr(name, "{"); if (start != NULL) { end = strstr(start, "}"); diff --git a/ports/win32/pcap_helper.h b/ports/win32/pcap_helper.h index cb5de31..7e21aee 100644 --- a/ports/win32/pcap_helper.h +++ b/ports/win32/pcap_helper.h @@ -1,8 +1,11 @@ #ifndef __PCAP_HELPER_H__ #define __PCAP_HELPER_H__ -#include "arch/cc.h" +#include -int get_adapter_index_from_addr(u32_t netaddr, char *guid, u32_t guid_len); +struct in_addr; + + +int get_adapter_index_from_addr(struct in_addr* netaddr, char *guid, size_t guid_len); #endif /* __PCAP_HELPER_H__ */ \ No newline at end of file diff --git a/ports/win32/pktif.c b/ports/win32/pktif.c index 3560ee4..eea9f07 100644 --- a/ports/win32/pktif.c +++ b/ports/win32/pktif.c @@ -131,7 +131,7 @@ low_level_init(struct netif *netif) char guid[GUID_LEN + 1]; memset(&guid, 0, sizeof(guid)); PACKET_LIB_GET_ADAPTER_NETADDRESS(&netaddr); - if (get_adapter_index_from_addr(ip4_addr_get_u32(&netaddr), guid, GUID_LEN) < 0) { + if (get_adapter_index_from_addr((struct in_addr *)&netaddr, guid, GUID_LEN) < 0) { printf("ERROR initializing network adapter, failed to get GUID for network address %s\n", ip_ntoa(&netaddr)); LWIP_ASSERT("ERROR initializing network adapter, failed to get GUID for network address!", 0); return;