Add wpcap for cygwin/Windows native border router

This commit is contained in:
David Kopf 2012-01-08 13:37:56 -05:00
parent 777cc88872
commit b251619a2f
7 changed files with 139 additions and 21 deletions

View file

@ -59,6 +59,15 @@
#include "net/wpcap.h"
/* Handle native-border-router case where the fallback has ethernet headers.
* The command line args for native-border-router conflice with the passing
* of the interface addresses to connect to, so both must be hard coded.
* See comments in wpcap-drv.c
*/
#ifdef SELECT_CALLBACK
#define FALLBACK_HAS_ETHERNET_HEADERS 1
#endif
#if UIP_CONF_IPV6
#include <ws2tcpip.h>
struct in6_addr addr6;
@ -173,19 +182,27 @@ init(void)
}
/*---------------------------------------------------------------------------*/
u8_t wfall_send(uip_lladdr_t *lladdr);
#if FALLBACK_HAS_ETHERNET_HEADERS
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
#define IPBUF ((struct uip_tcpip_hdr *)&uip_buf[14])
static uip_ipaddr_t last_sender;
#else
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
#define IPBUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
#endif
static void
output(void)
{
#if 0
#if FALLBACK_HAS_ETHERNET_HEADERS&&0
if(uip_ipaddr_cmp(&last_sender, &UIP_IP_BUF->srcipaddr)) {
/* Do not bounce packets back to fallback if the packet was received from it */
PRINTF("fallback: Destination off-link but no route src=");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF(" dst=");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("\n");
} else {
PRINTF("FUT: trapping pingpong");
return;
}
uip_ipaddr_copy(&last_sender, &UIP_IP_BUF->srcipaddr);
#endif
PRINTF("FUT: %u\n", uip_len);
wfall_send(0);
@ -197,9 +214,6 @@ const struct uip_fallback_interface rpl_interface = {
#endif
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
#define IPBUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
/*---------------------------------------------------------------------------*/
static void
error_exit(char *message)
@ -488,7 +502,7 @@ wpcap_init(void)
#ifdef UIP_FALLBACK_INTERFACE
if(addrfall.s_addr == INADDR_NONE) {
if(iszero_ip6addr(addrfall6)) {
#ifdef WPCAP_WPCAP_FALLBACK_ADDRESS
#ifdef WPCAP_FALLBACK_ADDRESS
addrfall.s_addr = inet_addr(WPCAP_FALLBACK_ADDRESS);
// if(addrfall.s_addr == INADDR_NONE) { //use ipv6 if contiki-conf.h override
uiplib_ipaddrconv(WPCAP_FALLBACK_ADDRESS,(uip_ipaddr_t*) &addrfall6.s6_addr);
@ -659,6 +673,11 @@ wfall_poll(void)
return 0;
}
#if UIP_CONF_IPV6
#if FALLBACK_HAS_ETHERNET_HEADERS
#define ETHERNET_LLADDR_LEN 6
#else
#define ETHERNET_LLADDR_LEN UIP_LLADDR_LEN
#endif
/* Since pcap_setdirection(PCAP_D_IN) is not implemented in winpcap all outgoing packets
* will be echoed back. The stack will ignore any packets not addressed to it, but initial
* ipv6 neighbor solicitations are addressed to everyone and the echoed NS sent on startup
@ -667,8 +686,8 @@ wfall_poll(void)
*
*/
int i;
for (i=0;i<UIP_LLADDR_LEN;i++) if (*(packet+UIP_LLADDR_LEN+i)!=uip_lladdr.addr[i]) break;
if (i==UIP_LLADDR_LEN) {
for (i=0;i<ETHERNET_LLADDR_LEN;i++) if (*(packet+ETHERNET_LLADDR_LEN+i)!=uip_lladdr.addr[i]) break;
if (i==ETHERNET_LLADDR_LEN) {
PRINTF("Discarding echoed packet\n");
return 0;
}
@ -727,6 +746,12 @@ return 0;
u8_t
wfall_send(uip_lladdr_t *lladdr)
{
#if FALLBACK_HAS_ETHERNET_HEADERS
//make room for ethernet header
//{int i;printf("\n");for (i=0;i<uip_len;i++) printf("%02x ",*(char*)(uip_buf+i));printf("\n");}
{int i;for(i=uip_len;i>=0;--i) *(char *)(uip_buf+i+14) = *(char *)(uip_buf+i);}
//{int i;printf("\n");for (i=0;i<uip_len;i++) printf("%02x ",*(char*)(uip_buf+i));printf("\n");}
#endif
if(lladdr == NULL) {
/* the dest must be multicast*/
(&BUF->dest)->addr[0] = 0x33;