Changed pktif/pcap_helper again for portability

This commit is contained in:
goldsimon 2010-03-10 11:43:47 +00:00
parent b83a115953
commit 244e7eddd2
3 changed files with 18 additions and 10 deletions

View File

@ -4,7 +4,6 @@
/* get the windows definitions of the following 4 functions out of the way */
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#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, "}");

View File

@ -1,8 +1,11 @@
#ifndef __PCAP_HELPER_H__
#define __PCAP_HELPER_H__
#include "arch/cc.h"
#include <stdlib.h>
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__ */

View File

@ -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;