From e3bcc2fe4ebe55b9ae96a934a4ced67ed9c67e3a Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Sun, 11 Sep 2011 12:49:57 +0200 Subject: [PATCH] pcapif: added the possibility to instantiate more than one pcap driver by passing the adapter index as 'state' to netif_add() --- ports/win32/pcapif.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ports/win32/pcapif.c b/ports/win32/pcapif.c index f5fd323..1708ee8 100644 --- a/ports/win32/pcapif.c +++ b/ports/win32/pcapif.c @@ -471,6 +471,18 @@ pcapif_low_level_init(struct netif *netif) int adapter_num = PACKET_LIB_ADAPTER_NR; struct pcapif_private *pa; + /* If 'state' is != NULL at this point, we assume it is an 'int' giving + the index of the adapter to use (+ 1 because 0==NULL is invalid). + This can be used to instantiate multiple PCAP drivers. */ + if (netif->state != NULL) { + adapter_num = ((int)netif->state) - 1; + if (adapter_num < 0) { + printf("ERROR: invalid adapter index \"%d\"!\n", adapter_num); + LWIP_ASSERT("ERROR initializing network adapter!\n", 0); + return; + } + } + #ifdef PACKET_LIB_GET_ADAPTER_NETADDRESS ip_addr_t netaddr; #define GUID_LEN 128 @@ -504,7 +516,7 @@ pcapif_low_level_init(struct netif *netif) /* Do whatever else is needed to initialize interface. */ pa = pcapif_init_adapter(adapter_num, netif); if (pa == NULL) { - printf("ERROR initializing network adapter %d!\n", PACKET_LIB_ADAPTER_NR); + printf("ERROR initializing network adapter %d!\n", adapter_num); LWIP_ASSERT("ERROR initializing network adapter!", 0); return; }