ipv6 fixes and formatting

This commit is contained in:
dak664 2009-08-11 16:06:17 +00:00
parent c154985d7e
commit d37115f2c0
2 changed files with 95 additions and 75 deletions

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: wpcap-drv.c,v 1.5 2009/08/08 19:51:25 dak664 Exp $ * @(#)$Id: wpcap-drv.c,v 1.6 2009/08/11 16:06:17 dak664 Exp $
*/ */
#include "contiki-net.h" #include "contiki-net.h"
@ -52,7 +52,7 @@ wpcap_output(void)
return 0; return 0;
} }
#endif #endif /* !UIP_CONF_IPV6 */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
pollhandler(void) pollhandler(void)
@ -63,25 +63,24 @@ pollhandler(void)
if(uip_len > 0) { if(uip_len > 0) {
#if UIP_CONF_IPV6 #if UIP_CONF_IPV6
if(BUF->type == htons(UIP_ETHTYPE_IPV6)) { if(BUF->type == htons(UIP_ETHTYPE_IPV6)) {
// uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src);
tcpip_input(); tcpip_input();
} else } else
#endif /* UIP_CONF_IPV6 */ #endif /* UIP_CONF_IPV6 */
if(BUF->type == htons(UIP_ETHTYPE_IP)) { if(BUF->type == htons(UIP_ETHTYPE_IP)) {
uip_len -= sizeof(struct uip_eth_hdr); uip_len -= sizeof(struct uip_eth_hdr);
tcpip_input(); tcpip_input();
#if !UIP_CONF_IPV6
} else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
#if !UIP_CONF_IPV6 //math uip_arp_arpin(); //math
uip_arp_arpin();
/* If the above function invocation resulted in data that /* If the above function invocation resulted in data that
should be sent out on the network, the global variable should be sent out on the network, the global variable
uip_len is set to a value > 0. */ uip_len is set to a value > 0. */
if(uip_len > 0) { if(uip_len > 0) {
wpcap_send(); wpcap_send();
} }
#endif #endif /* !UIP_CONF_IPV6 */
// } else { } else {
// uip_len = 0; uip_len = 0;
} }
} }
} }
@ -98,7 +97,7 @@ PROCESS_THREAD(wpcap_process, ev, data)
tcpip_set_outputfunc(wpcap_output); tcpip_set_outputfunc(wpcap_output);
#else #else
tcpip_set_outputfunc(wpcap_send); tcpip_set_outputfunc(wpcap_send);
#endif #endif /* !UIP_CONF_IPV6 */
process_poll(&wpcap_process); process_poll(&wpcap_process);

View file

@ -30,7 +30,7 @@
* *
* Author: Oliver Schmidt <ol.sc@web.de> * Author: Oliver Schmidt <ol.sc@web.de>
* *
* $Id: wpcap.c,v 1.16 2009/08/09 20:44:42 oliverschmidt Exp $ * $Id: wpcap.c,v 1.17 2009/08/11 16:06:17 dak664 Exp $
*/ */
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
@ -47,6 +47,13 @@
#include <malloc.h> #include <malloc.h>
#endif /* __CYGWIN__ */ #endif /* __CYGWIN__ */
#define DEBUG 0
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
/* Avoid 'conflicting types' errors. */ /* Avoid 'conflicting types' errors. */
#define htonl #define htonl
#define htons #define htons
@ -60,11 +67,6 @@
__attribute__((dllimport)) extern char **__argv[]; __attribute__((dllimport)) extern char **__argv[];
#endif /* __CYGWIN__ */ #endif /* __CYGWIN__ */
#if UIP_CONF_IPV6 /*TODO: put this in the right place */
//CCIF struct uip_eth_addr uip_ethaddr={{0xff,0xff,0xff,0xff,0xff,0xff}};
struct uip_eth_addr uip_ethaddr={{0xff,0xff,0xff,0xff,0xff,0xff}};
#endif /* UIP_CONF_IPV6 */
struct pcap; struct pcap;
struct pcap_if { struct pcap_if {
@ -91,6 +93,13 @@ HMODULE wpcap;
static struct pcap *pcap; static struct pcap *pcap;
/* uip_ethaddr is defined in uip.c. It is not used in uip6.c.
* If needed for some purpose it can be defined here
*/
#if UIP_CONF_IPV6
//struct uip_eth_addr uip_ethaddr;
#endif
static int (* pcap_findalldevs)(struct pcap_if **, char *); static int (* pcap_findalldevs)(struct pcap_if **, char *);
static struct pcap *(* pcap_open_live)(char *, int, int, int, char *); static struct pcap *(* pcap_open_live)(char *, int, int, int, char *);
static int (* pcap_next_ex)(struct pcap *, struct pcap_pkthdr **, unsigned char **); static int (* pcap_next_ex)(struct pcap *, struct pcap_pkthdr **, unsigned char **);
@ -145,11 +154,10 @@ init_pcap(struct in_addr addr)
} }
if(interfaces == NULL) { if(interfaces == NULL) {
error_exit("no interface found with ip addr specified on cmdline\n"); error_exit("no interface found with specified ip address\n");
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if !UIP_CONF_IPV6
static void static void
set_ethaddr(struct in_addr addr) set_ethaddr(struct in_addr addr)
{ {
@ -194,7 +202,11 @@ set_ethaddr(struct in_addr addr)
adapters->PhysicalAddress[2], adapters->PhysicalAddress[3], adapters->PhysicalAddress[2], adapters->PhysicalAddress[3],
adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]); adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]);
log_message("set_ethaddr: ethernetaddr: ", buffer); log_message("set_ethaddr: ethernetaddr: ", buffer);
#if UIP_CONF_IPV6
// int i;for (i=0;i<6;i++) uip_ethaddr.addr[i] = adapters->PhysicalAddress[i];
#else
uip_setethaddr((*(struct uip_eth_addr *)adapters->PhysicalAddress)); uip_setethaddr((*(struct uip_eth_addr *)adapters->PhysicalAddress));
#endif
break; break;
} }
} }
@ -205,7 +217,6 @@ set_ethaddr(struct in_addr addr)
error_exit("no adapter found with ip addr specified on cmdline\n"); error_exit("no adapter found with ip addr specified on cmdline\n");
} }
} }
#endif /* !UIP_CONF_IPV6 */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
wpcap_init(void) wpcap_init(void)
@ -218,9 +229,12 @@ wpcap_init(void)
addr.s_addr = inet_addr(__argv[1]); addr.s_addr = inet_addr(__argv[1]);
#endif /* __CYGWIN__ */ #endif /* __CYGWIN__ */
if(addr.s_addr == INADDR_NONE) { if(addr.s_addr == INADDR_NONE) {
error_exit("usage: <program> <ip addr of ethernet card to share>\n"); // error_exit("usage: <program> <ip addr of ethernet card to share>\n");
addr.s_addr = inet_addr("10.10.10.10");
log_message("usage: <program> <ip addr of ethernet card to share>\n-->I'll try guessing ", inet_ntoa(addr));
} else {
log_message("wpcap_init:cmdline address: ", inet_ntoa(addr));
} }
log_message("wpcap_init: cmdline address: ", inet_ntoa(addr));
wpcap = LoadLibrary("wpcap.dll"); wpcap = LoadLibrary("wpcap.dll");
pcap_findalldevs = (int (*)(struct pcap_if **, char *)) pcap_findalldevs = (int (*)(struct pcap_if **, char *))
@ -238,9 +252,8 @@ wpcap_init(void)
} }
init_pcap(addr); init_pcap(addr);
#if !UIP_CONF_IPV6
set_ethaddr(addr); set_ethaddr(addr);
#endif
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
u16_t u16_t
@ -268,32 +281,40 @@ wpcap_poll(void)
u8_t u8_t
wpcap_send(uip_lladdr_t *lladdr) wpcap_send(uip_lladdr_t *lladdr)
{ {
static char cludge=0;
if(lladdr == NULL) { if(lladdr == NULL) {
/* the dest must be multicast */ /* the dest must be multicast*/
(&BUF->dest)->addr[0] = 0x33; (&BUF->dest)->addr[0] = 0x33;
(&BUF->dest)->addr[1] = 0x33; (&BUF->dest)->addr[1] = 0x33;
// (&BUF->dest)->addr[2] = IPBUF->destipaddr.u8[12]; //destipaddr is zero (&BUF->dest)->addr[2] = IPBUF->destipaddr.u8[12];
// (&BUF->dest)->addr[3] = IPBUF->destipaddr.u8[13]; (&BUF->dest)->addr[3] = IPBUF->destipaddr.u8[13];
// (&BUF->dest)->addr[4] = IPBUF->destipaddr.u8[14]; (&BUF->dest)->addr[4] = IPBUF->destipaddr.u8[14];
// (&BUF->dest)->addr[5] = IPBUF->destipaddr.u8[15]; (&BUF->dest)->addr[5] = IPBUF->destipaddr.u8[15];
(&BUF->dest)->addr[2] = uip_ethaddr.addr[2];
(&BUF->dest)->addr[3] = uip_ethaddr.addr[3];
(&BUF->dest)->addr[4] = uip_ethaddr.addr[4];
(&BUF->dest)->addr[5] = uip_ethaddr.addr[5];
} else { } else {
memcpy(&BUF->dest, lladdr, UIP_LLADDR_LEN); memcpy(&BUF->dest, lladdr, UIP_LLADDR_LEN);
} }
if ((&BUF->src)->addr[0]) { //Linux tap6 does this always
memcpy(&BUF->src, &uip_lladdr, UIP_LLADDR_LEN); memcpy(&BUF->src, &uip_lladdr, UIP_LLADDR_LEN);
}
// BUF->type = HTONS(UIP_ETHTYPE_IPV6); //math tmp //This causes a silent exit
/* TODO:After sending the initial NS a NS is received from 0 to me with my target address.
* This causes program exit -1 via uip_netif_dad_failed() from uip-nd6-io.c.
* It is OK once it receives an incoming packet
* Swallowing the first few output packets will (usually) get it going
* This is a cludge until the NS processing is resolved!
*/
if (cludge<3) {
cludge++; //gulp
} else {
PRINTF("Src= %02x %02x %02x %02x %02x %02x",(&BUF->src)->addr[0],(&BUF->src)->addr[1],(&BUF->src)->addr[2],(&BUF->src)->addr[3],(&BUF->src)->addr[4],(&BUF->src)->addr[5]);
PRINTF(" Dst= %02x %02x %02x %02x %02x %02x",(&BUF->dest)->addr[0],(&BUF->dest)->addr[1],(&BUF->dest)->addr[2],(&BUF->dest)->addr[3],(&BUF->dest)->addr[4],(&BUF->dest)->addr[5]);
PRINTF(" Type=%04x\n",BUF->type);
BUF->type = HTONS(UIP_ETHTYPE_IPV6);
uip_len += sizeof(struct uip_eth_hdr); uip_len += sizeof(struct uip_eth_hdr);
if(pcap_sendpacket(pcap, uip_buf, uip_len) == -1) { if(pcap_sendpacket(pcap, uip_buf, uip_len) == -1) {
error_exit("error on send\n"); error_exit("error on send\n");
} }
return 0;
} }
return 0;
} /* cludge */
#else /* UIP_CONF_IPV6 */ #else /* UIP_CONF_IPV6 */
void void
wpcap_send(void) wpcap_send(void)