2007-03-26 02:53:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007, Swedish Institute of Computer Science.
|
2007-11-17 18:01:00 +00:00
|
|
|
* All rights reserved.
|
2007-03-26 02:53:54 +00:00
|
|
|
*
|
2007-11-17 18:01:00 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2007-03-26 02:53:54 +00:00
|
|
|
*
|
2007-11-17 18:01:00 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2007-03-26 02:53:54 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
2007-11-17 18:01:00 +00:00
|
|
|
*
|
2007-03-26 02:53:54 +00:00
|
|
|
* Author: Oliver Schmidt <ol.sc@web.de>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#define _WIN32_WINNT 0x0501
|
|
|
|
#include <windows.h>
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <iphlpapi.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2011-06-28 12:19:48 +00:00
|
|
|
|
2007-11-17 21:33:53 +00:00
|
|
|
#ifdef __CYGWIN__
|
2007-11-17 18:01:00 +00:00
|
|
|
#include <alloca.h>
|
2008-01-04 21:53:32 +00:00
|
|
|
#else /* __CYGWIN__ */
|
2007-11-17 21:33:53 +00:00
|
|
|
#include <malloc.h>
|
2008-01-04 21:53:32 +00:00
|
|
|
#endif /* __CYGWIN__ */
|
2007-03-26 02:53:54 +00:00
|
|
|
|
2009-08-11 16:06:17 +00:00
|
|
|
#define DEBUG 0
|
|
|
|
#if DEBUG
|
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define PRINTF(...)
|
|
|
|
#endif
|
|
|
|
|
2007-03-26 02:53:54 +00:00
|
|
|
#include "contiki-net.h"
|
2007-04-11 00:21:28 +00:00
|
|
|
#include "sys/log.h"
|
2007-11-27 20:54:10 +00:00
|
|
|
|
|
|
|
#include "net/wpcap.h"
|
2007-03-26 02:53:54 +00:00
|
|
|
|
2012-01-08 18:37:56 +00:00
|
|
|
/* 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
|
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
#if UIP_CONF_IPV6
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
struct in6_addr addr6;
|
|
|
|
char addr6str[64];
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
uint8_t
|
|
|
|
issame_ip6addr(struct in6_addr addr1, struct in6_addr addr2)
|
|
|
|
{
|
|
|
|
return ((addr1.s6_addr32[0]==addr2.s6_addr32[0]) &&
|
|
|
|
(addr1.s6_addr32[1]==addr2.s6_addr32[1]) &&
|
|
|
|
(addr1.s6_addr32[2]==addr2.s6_addr32[2]) &&
|
|
|
|
(addr1.s6_addr32[3]==addr2.s6_addr32[3]) );
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
uint8_t
|
|
|
|
iszero_ip6addr(struct in6_addr addr)
|
|
|
|
{
|
|
|
|
return ((addr.s6_addr32[0]==0) &&
|
|
|
|
(addr.s6_addr32[1]==0) &&
|
|
|
|
(addr.s6_addr32[2]==0) &&
|
|
|
|
(addr.s6_addr32[3]==0) );
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
uint8_t
|
|
|
|
sprint_ip6addr(struct in6_addr addr, char * result)
|
|
|
|
{
|
|
|
|
unsigned char i = 0;
|
|
|
|
unsigned char zerocnt = 0;
|
|
|
|
unsigned char numprinted = 0;
|
|
|
|
char * starting = result;
|
|
|
|
|
|
|
|
*result++='[';
|
|
|
|
while (numprinted < 8) {
|
|
|
|
if ((addr.s6_addr16[i] == 0) && (zerocnt == 0)) {
|
|
|
|
while(addr.s6_addr16[zerocnt + i] == 0) zerocnt++;
|
|
|
|
if (zerocnt == 1) {
|
|
|
|
*result++ = '0';
|
|
|
|
numprinted++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i += zerocnt;
|
|
|
|
numprinted += zerocnt;
|
|
|
|
} else {
|
|
|
|
result += sprintf(result, "%x", (unsigned int) uip_ntohs(addr.s6_addr16[i]));
|
|
|
|
i++;
|
|
|
|
numprinted++;
|
|
|
|
}
|
|
|
|
if (numprinted != 8) *result++ = ':';
|
|
|
|
}
|
|
|
|
*result++=']';
|
|
|
|
*result=0;
|
|
|
|
return (result - starting);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* UIP_CONF_IPV6 */
|
|
|
|
|
|
|
|
|
2007-04-11 00:21:28 +00:00
|
|
|
#ifdef __CYGWIN__
|
2007-04-07 00:27:22 +00:00
|
|
|
__attribute__((dllimport)) extern char **__argv[];
|
2008-01-04 21:53:32 +00:00
|
|
|
#endif /* __CYGWIN__ */
|
2007-03-26 02:53:54 +00:00
|
|
|
|
|
|
|
struct pcap;
|
|
|
|
|
|
|
|
struct pcap_if {
|
|
|
|
struct pcap_if *next;
|
|
|
|
char *name;
|
|
|
|
char *description;
|
|
|
|
struct pcap_addr {
|
|
|
|
struct pcap_addr *next;
|
|
|
|
struct sockaddr *addr;
|
|
|
|
struct sockaddr *netmask;
|
|
|
|
struct sockaddr *broadaddr;
|
|
|
|
struct sockaddr *dstaddr;
|
|
|
|
} *addresses;
|
2007-04-11 00:21:28 +00:00
|
|
|
DWORD flags;
|
2007-03-26 02:53:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pcap_pkthdr {
|
|
|
|
struct timeval ts;
|
2007-04-11 00:21:28 +00:00
|
|
|
DWORD caplen;
|
|
|
|
DWORD len;
|
2007-03-26 02:53:54 +00:00
|
|
|
};
|
|
|
|
|
2007-05-22 22:01:03 +00:00
|
|
|
HMODULE wpcap;
|
|
|
|
|
2007-03-26 02:53:54 +00:00
|
|
|
static struct pcap *pcap;
|
|
|
|
|
2013-01-09 16:03:57 +00:00
|
|
|
/* uip_lladdr is defined in uip.c. It is not used in uip6.c.
|
2009-08-11 16:06:17 +00:00
|
|
|
* If needed for some purpose it can be defined here
|
|
|
|
*/
|
|
|
|
#if UIP_CONF_IPV6
|
2013-01-09 16:03:57 +00:00
|
|
|
//struct uip_eth_addr uip_lladdr;
|
2009-08-11 16:06:17 +00:00
|
|
|
#endif
|
|
|
|
|
2007-03-26 02:53:54 +00:00
|
|
|
static int (* pcap_findalldevs)(struct pcap_if **, 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_sendpacket)(struct pcap *, unsigned char *, int);
|
|
|
|
|
2012-02-11 20:03:24 +00:00
|
|
|
#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])
|
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
static struct pcap *pfall;
|
|
|
|
struct in_addr addrfall;
|
|
|
|
#if UIP_CONF_IPV6
|
|
|
|
struct in_addr6 addrfall6;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
init(void)
|
|
|
|
{
|
|
|
|
/* Nothing to do here */
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-11-18 22:26:37 +00:00
|
|
|
uint8_t wfall_send(const uip_lladdr_t *lladdr);
|
2012-01-08 18:37:56 +00:00
|
|
|
#if FALLBACK_HAS_ETHERNET_HEADERS
|
2012-02-11 20:03:24 +00:00
|
|
|
#undef IPBUF
|
2012-01-08 18:37:56 +00:00
|
|
|
#define IPBUF ((struct uip_tcpip_hdr *)&uip_buf[14])
|
|
|
|
static uip_ipaddr_t last_sender;
|
|
|
|
#endif
|
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
static void
|
|
|
|
output(void)
|
|
|
|
{
|
2012-01-08 18:37:56 +00:00
|
|
|
#if FALLBACK_HAS_ETHERNET_HEADERS&&0
|
2011-06-28 12:19:48 +00:00
|
|
|
if(uip_ipaddr_cmp(&last_sender, &UIP_IP_BUF->srcipaddr)) {
|
|
|
|
/* Do not bounce packets back to fallback if the packet was received from it */
|
2012-01-08 18:37:56 +00:00
|
|
|
PRINTF("FUT: trapping pingpong");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uip_ipaddr_copy(&last_sender, &UIP_IP_BUF->srcipaddr);
|
2011-06-28 12:19:48 +00:00
|
|
|
#endif
|
|
|
|
PRINTF("FUT: %u\n", uip_len);
|
|
|
|
wfall_send(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct uip_fallback_interface rpl_interface = {
|
|
|
|
init, output
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-03-26 02:53:54 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
error_exit(char *message)
|
|
|
|
{
|
|
|
|
printf("error_exit: %s", message);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2011-06-28 12:19:48 +00:00
|
|
|
set_ethaddr(struct in_addr addr)
|
2007-03-26 02:53:54 +00:00
|
|
|
{
|
2011-06-28 12:19:48 +00:00
|
|
|
PIP_ADAPTER_ADDRESSES adapters;
|
|
|
|
ULONG size = 0;
|
2007-03-26 02:53:54 +00:00
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
if(GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST |
|
|
|
|
GAA_FLAG_SKIP_MULTICAST |
|
|
|
|
GAA_FLAG_SKIP_DNS_SERVER,
|
|
|
|
NULL, NULL, &size) != ERROR_BUFFER_OVERFLOW) {
|
|
|
|
error_exit("error on access to adapter list size\n");
|
|
|
|
}
|
|
|
|
adapters = alloca(size);
|
|
|
|
if(GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST |
|
|
|
|
GAA_FLAG_SKIP_MULTICAST |
|
|
|
|
GAA_FLAG_SKIP_DNS_SERVER,
|
|
|
|
NULL, adapters, &size) != ERROR_SUCCESS) {
|
|
|
|
error_exit("error on access to adapter list\n");
|
2007-03-26 02:53:54 +00:00
|
|
|
}
|
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
while(adapters != NULL) {
|
2007-03-26 02:53:54 +00:00
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
char buffer[256];
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, adapters->Description, -1,
|
|
|
|
buffer, sizeof(buffer), NULL, NULL);
|
|
|
|
log_message("set_ethaddr: found adapter: ", buffer);
|
2009-08-11 16:06:17 +00:00
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
if(adapters->FirstUnicastAddress != NULL &&
|
|
|
|
adapters->FirstUnicastAddress->Address.lpSockaddr != NULL &&
|
|
|
|
adapters->FirstUnicastAddress->Address.lpSockaddr->sa_family == AF_INET) {
|
2009-08-11 16:06:17 +00:00
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
struct in_addr adapter_addr;
|
|
|
|
adapter_addr = ((struct sockaddr_in *)adapters->FirstUnicastAddress->Address.lpSockaddr)->sin_addr;
|
|
|
|
log_message("set_ethaddr: with address: ", inet_ntoa(adapter_addr));
|
|
|
|
|
|
|
|
if(adapter_addr.s_addr == addr.s_addr) {
|
|
|
|
if(adapters->PhysicalAddressLength != 6) {
|
|
|
|
error_exit("ip addr specified on cmdline does not belong to an ethernet card\n");
|
2009-08-11 16:06:17 +00:00
|
|
|
}
|
2011-06-28 12:19:48 +00:00
|
|
|
wsprintf(buffer, "%02X-%02X-%02X-%02X-%02X-%02X",
|
|
|
|
adapters->PhysicalAddress[0], adapters->PhysicalAddress[1],
|
|
|
|
adapters->PhysicalAddress[2], adapters->PhysicalAddress[3],
|
|
|
|
adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]);
|
|
|
|
log_message("set_ethaddr: ethernetaddr: ", buffer);
|
|
|
|
#if UIP_CONF_IPV6
|
2013-01-09 16:03:57 +00:00
|
|
|
// int i;for (i=0;i<6;i++) uip_lladdr.addr[i] = adapters->PhysicalAddress[i];
|
2011-06-28 12:19:48 +00:00
|
|
|
#else
|
|
|
|
uip_setethaddr((*(struct uip_eth_addr *)adapters->PhysicalAddress));
|
|
|
|
#endif
|
|
|
|
break;
|
2007-11-17 18:01:00 +00:00
|
|
|
}
|
2007-03-26 02:53:54 +00:00
|
|
|
}
|
2011-06-28 12:19:48 +00:00
|
|
|
adapters = adapters->Next;
|
2007-03-26 02:53:54 +00:00
|
|
|
}
|
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
if(adapters == NULL) {
|
|
|
|
error_exit("no adapter found with ip addr specified on cmdline\n");
|
2007-03-26 02:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-28 12:19:48 +00:00
|
|
|
|
|
|
|
#if UIP_CONF_IPV6
|
2007-03-26 02:53:54 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2011-06-28 12:19:48 +00:00
|
|
|
set_ethaddr6(struct in_addr6 addr)
|
2007-03-26 02:53:54 +00:00
|
|
|
{
|
|
|
|
PIP_ADAPTER_ADDRESSES adapters;
|
|
|
|
ULONG size = 0;
|
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
if(GetAdaptersAddresses(AF_INET6, GAA_FLAG_SKIP_ANYCAST |
|
2009-08-11 16:06:17 +00:00
|
|
|
GAA_FLAG_SKIP_MULTICAST |
|
|
|
|
GAA_FLAG_SKIP_DNS_SERVER,
|
|
|
|
NULL, NULL, &size) != ERROR_BUFFER_OVERFLOW) {
|
2007-03-26 02:53:54 +00:00
|
|
|
error_exit("error on access to adapter list size\n");
|
|
|
|
}
|
|
|
|
adapters = alloca(size);
|
2011-06-28 12:19:48 +00:00
|
|
|
if(GetAdaptersAddresses(AF_INET6, GAA_FLAG_SKIP_ANYCAST |
|
2009-08-11 16:06:17 +00:00
|
|
|
GAA_FLAG_SKIP_MULTICAST |
|
|
|
|
GAA_FLAG_SKIP_DNS_SERVER,
|
|
|
|
NULL, adapters, &size) != ERROR_SUCCESS) {
|
2007-03-26 02:53:54 +00:00
|
|
|
error_exit("error on access to adapter list\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
while(adapters != NULL) {
|
|
|
|
|
2007-04-11 00:21:28 +00:00
|
|
|
char buffer[256];
|
2007-03-26 02:53:54 +00:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, adapters->Description, -1,
|
2009-08-11 16:06:17 +00:00
|
|
|
buffer, sizeof(buffer), NULL, NULL);
|
2007-04-11 00:21:28 +00:00
|
|
|
log_message("set_ethaddr: found adapter: ", buffer);
|
2007-03-26 02:53:54 +00:00
|
|
|
|
|
|
|
if(adapters->FirstUnicastAddress != NULL &&
|
|
|
|
adapters->FirstUnicastAddress->Address.lpSockaddr != NULL &&
|
2011-06-28 12:19:48 +00:00
|
|
|
adapters->FirstUnicastAddress->Address.lpSockaddr->sa_family == AF_INET6) {
|
2007-03-26 02:53:54 +00:00
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
struct in_addr6 adapter_addr;
|
|
|
|
adapter_addr = ((struct sockaddr_in6 *)adapters->FirstUnicastAddress->Address.lpSockaddr)->sin6_addr;
|
|
|
|
sprint_ip6addr(adapter_addr, addr6str);
|
|
|
|
log_message("set_ethaddr: with ipv6 address: : ", addr6str);
|
|
|
|
if(issame_ip6addr(adapter_addr,addr6)) {
|
2009-08-11 16:06:17 +00:00
|
|
|
if(adapters->PhysicalAddressLength != 6) {
|
|
|
|
error_exit("ip addr specified on cmdline does not belong to an ethernet card\n");
|
|
|
|
}
|
|
|
|
wsprintf(buffer, "%02X-%02X-%02X-%02X-%02X-%02X",
|
|
|
|
adapters->PhysicalAddress[0], adapters->PhysicalAddress[1],
|
|
|
|
adapters->PhysicalAddress[2], adapters->PhysicalAddress[3],
|
|
|
|
adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]);
|
|
|
|
log_message("set_ethaddr: ethernetaddr: ", buffer);
|
|
|
|
#if UIP_CONF_IPV6
|
2013-01-09 16:03:57 +00:00
|
|
|
// int i;for (i=0;i<6;i++) uip_lladdr.addr[i] = adapters->PhysicalAddress[i]; //does this need doing?
|
2009-08-11 16:06:17 +00:00
|
|
|
#else
|
|
|
|
uip_setethaddr((*(struct uip_eth_addr *)adapters->PhysicalAddress));
|
|
|
|
#endif
|
|
|
|
break;
|
2007-03-26 02:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
adapters = adapters->Next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(adapters == NULL) {
|
|
|
|
error_exit("no adapter found with ip addr specified on cmdline\n");
|
|
|
|
}
|
|
|
|
}
|
2011-06-28 12:19:48 +00:00
|
|
|
#endif
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
init_pcap(struct in_addr addr)
|
|
|
|
{
|
|
|
|
struct pcap_if *interfaces;
|
|
|
|
struct pcap_addr *paddr;
|
|
|
|
char error[256];
|
|
|
|
|
|
|
|
if(pcap_findalldevs(&interfaces, error) == -1) {
|
|
|
|
error_exit(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
while(interfaces != NULL) {
|
|
|
|
log_message("init_pcap: found interface: ", interfaces->description);
|
|
|
|
|
|
|
|
if(interfaces->addresses != NULL) {
|
|
|
|
for(paddr = interfaces->addresses;
|
|
|
|
paddr != NULL;
|
|
|
|
paddr = paddr->next) {
|
|
|
|
if(paddr->addr != NULL && paddr->addr->sa_family == AF_INET) {
|
|
|
|
struct in_addr interface_addr;
|
|
|
|
interface_addr = ((struct sockaddr_in *)paddr->addr)->sin_addr;
|
|
|
|
log_message("init_pcap: with address: ", inet_ntoa(interface_addr));
|
|
|
|
|
|
|
|
if(interface_addr.s_addr == addr.s_addr) {
|
|
|
|
pcap = pcap_open_live(interfaces->name, UIP_BUFSIZE, 0, -1, error);
|
|
|
|
if(pcap == NULL) {
|
|
|
|
error_exit(error);
|
|
|
|
}
|
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
log_message("init_pcap: Opened as primary interface","");
|
2012-02-11 20:03:24 +00:00
|
|
|
#else
|
|
|
|
log_message("init_pcap: Opened as interface","");
|
2011-06-28 12:19:48 +00:00
|
|
|
#endif
|
|
|
|
// pcap_setdirection(PCAP_D_IN); //Not implemented in windows yet?
|
|
|
|
set_ethaddr(addr);
|
|
|
|
|
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
}
|
|
|
|
if (pfall && pcap) return;
|
|
|
|
if(interface_addr.s_addr == addrfall.s_addr) {
|
|
|
|
pfall = pcap_open_live(interfaces->name, UIP_BUFSIZE, 0, -1, error);
|
|
|
|
if(pfall == NULL) {
|
|
|
|
error_exit(error);
|
|
|
|
}
|
|
|
|
log_message("init_pcap: Opened as fallback interface","");
|
|
|
|
if (pcap) return;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if UIP_CONF_IPV6
|
|
|
|
|
|
|
|
} else if(paddr->addr != NULL && paddr->addr->sa_family == AF_INET6) {
|
|
|
|
struct in6_addr interface_addr;
|
|
|
|
interface_addr = ((struct sockaddr_in6 *)paddr->addr)->sin6_addr;
|
|
|
|
|
|
|
|
sprint_ip6addr(interface_addr, addr6str);
|
|
|
|
log_message("init_pcap: with ipv6 address: ", addr6str);
|
|
|
|
|
|
|
|
if (issame_ip6addr(interface_addr, addr6)) {
|
|
|
|
pcap = pcap_open_live(interfaces->name, UIP_BUFSIZE, 0, -1, error);
|
|
|
|
if(pcap == NULL) {
|
|
|
|
error_exit(error);
|
|
|
|
}
|
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
log_message("init_pcap: Opened as primary interface","");
|
|
|
|
#endif
|
|
|
|
set_ethaddr6(addr6);
|
|
|
|
// pcap_setdirection(PCAP_D_IN); //Not implemented in windows yet?
|
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
}
|
|
|
|
if (pfall && pcap) return; //exit when we have both interfaces
|
|
|
|
|
|
|
|
if (issame_ip6addr(interface_addr, addrfall6)) {
|
|
|
|
pfall = pcap_open_live(interfaces->name, UIP_BUFSIZE, 0, -1, error);
|
|
|
|
if(pfall == NULL) {
|
|
|
|
error_exit(error);
|
|
|
|
}
|
|
|
|
log_message("init_pcap: Opened as fallback interface","");
|
|
|
|
if (pcap) return;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* UIP_CONF_IPV6 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
interfaces = interfaces->next;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(interfaces == NULL) {
|
|
|
|
error_exit("no interface found with specified ip address\n");
|
|
|
|
}
|
|
|
|
}
|
2007-03-26 02:53:54 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
wpcap_init(void)
|
|
|
|
{
|
|
|
|
struct in_addr addr;
|
2011-06-28 12:19:48 +00:00
|
|
|
addr.s_addr = INADDR_NONE; //255.255.255.255
|
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
addrfall.s_addr = INADDR_NONE;
|
|
|
|
#endif
|
2007-03-26 02:53:54 +00:00
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
/* Pick up possible ip addresses from command line */
|
2007-04-11 00:21:28 +00:00
|
|
|
#ifdef __CYGWIN__
|
2011-06-28 12:19:48 +00:00
|
|
|
if ((*__argv)[1]) {
|
|
|
|
addr.s_addr = inet_addr((*__argv)[1]);
|
|
|
|
#if UIP_CONF_IPV6
|
|
|
|
uiplib_ipaddrconv((*__argv)[1],(uip_ipaddr_t*) &addr6.s6_addr);
|
|
|
|
#endif
|
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
if ((*__argv)[2]) {
|
|
|
|
addrfall.s_addr = inet_addr((*__argv)[2]);
|
|
|
|
#if UIP_CONF_IPV6
|
|
|
|
uiplib_ipaddrconv((*__argv)[2],(uip_ipaddr_t*) &addrfall6.s6_addr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-01-04 21:53:32 +00:00
|
|
|
#else /* __CYGWIN__ */
|
2011-06-28 12:19:48 +00:00
|
|
|
/* VC++ build on win32 platform. Currently the platform has no ipv6 support */
|
2007-04-11 00:21:28 +00:00
|
|
|
addr.s_addr = inet_addr(__argv[1]);
|
2011-06-28 12:19:48 +00:00
|
|
|
#if UIP_CONF_IPV6
|
|
|
|
if((__argv)[1])
|
|
|
|
uiplib_ipaddrconv((__argv)[1],(uip_ipaddr_t*) &addr6.s6_addr);
|
|
|
|
#endif
|
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
addrfall.s_addr = inet_addr(__argv[2]);
|
|
|
|
#if UIP_CONF_IPV6
|
|
|
|
if((__argv)[2])
|
|
|
|
uiplib_ipaddrconv((__argv)[2],(uip_ipaddr_t*) &addrfall6.s6_addr);
|
|
|
|
#endif
|
|
|
|
#endif
|
2008-01-04 21:53:32 +00:00
|
|
|
#endif /* __CYGWIN__ */
|
2011-06-28 12:19:48 +00:00
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
log_message("wpcap_init:Passed ipv4 ", inet_ntoa(addr));
|
|
|
|
sprint_ip6addr(addr6, addr6str);
|
|
|
|
log_message("wpcap_init:Passed ipv6 ", addr6str);
|
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
log_message("wpcap_init:Passed fallback ipv4 ", inet_ntoa(addrfall));
|
|
|
|
sprint_ip6addr(addrfall6, addr6str);
|
|
|
|
log_message("wpcap_init:Passed fallback ipv6 ", addr6str);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Use build defaults if not enough addresses passed */
|
|
|
|
#if UIP_CONF_IPV6
|
|
|
|
|
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
if(addrfall.s_addr == INADDR_NONE) {
|
|
|
|
if(iszero_ip6addr(addrfall6)) {
|
2012-01-08 18:37:56 +00:00
|
|
|
#ifdef WPCAP_FALLBACK_ADDRESS
|
2011-06-28 12:19:48 +00:00
|
|
|
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);
|
|
|
|
// }
|
|
|
|
#else
|
|
|
|
// addrfall.s_addr = inet_addr("10.2.10.10");
|
|
|
|
uiplib_ipaddrconv("bbbb::1",(uip_ipaddr_t*) &addrfall6.s6_addr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(addr.s_addr == INADDR_NONE) {
|
|
|
|
if(iszero_ip6addr(addr6)) {
|
|
|
|
#ifdef WPCAP_INTERFACE_ADDRESS
|
|
|
|
addr.s_addr = inet_addr(WPCAP_INTERFACE_ADDRESS);
|
|
|
|
// if(addr.s_addr == INADDR_NONE) {
|
|
|
|
uiplib_ipaddrconv(WPCAP_INTERFACE_ADDRESS,(uip_ipaddr_t*) &addr6.s6_addr);
|
|
|
|
// }
|
|
|
|
#else
|
|
|
|
addr.s_addr = inet_addr("10.10.10.10"); //prefer ipv4 default for legacy compatibility
|
|
|
|
// uiplib_ipaddrconv("aaaa::1",(uip_ipaddr_t*) &addr6.s6_addr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
log_message("usage: <program> <ip addr of interface> <ip addr of fallback>\n","");
|
|
|
|
if(addr.s_addr != INADDR_NONE) {
|
|
|
|
log_message("-->I'll try interface address ", inet_ntoa(addr));
|
|
|
|
} else {
|
|
|
|
sprint_ip6addr(addr6, addr6str);
|
|
|
|
log_message("-->I'll try interface address ", addr6str);
|
|
|
|
}
|
|
|
|
if(addrfall.s_addr != INADDR_NONE) {
|
|
|
|
log_message("--> and fallback address ", inet_ntoa(addrfall));
|
|
|
|
} else {
|
|
|
|
sprint_ip6addr(addrfall6, addr6str);
|
|
|
|
log_message("--> and fallback address ", addr6str);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if(addr.s_addr != INADDR_NONE) {
|
|
|
|
log_message("usage: <program> <ip addr of ethernet card to share>\n-->I'll try guessing ", inet_ntoa(addr));
|
|
|
|
} else {
|
|
|
|
sprint_ip6addr(addr6, addr6str);
|
|
|
|
log_message("usage: <program> <ip addr of ethernet card to share>\n-->I'll try guessing ", addr6str);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else /* ip4 build */
|
2007-03-26 02:53:54 +00:00
|
|
|
if(addr.s_addr == INADDR_NONE) {
|
2011-06-28 12:19:48 +00:00
|
|
|
#ifdef WPCAP_INTERFACE_ADDRESS
|
|
|
|
addr.s_addr = inet_addr(WPCAP_INTERFACE_ADDRESS);
|
|
|
|
#else
|
2009-08-11 16:06:17 +00:00
|
|
|
addr.s_addr = inet_addr("10.10.10.10");
|
2011-06-28 12:19:48 +00:00
|
|
|
#endif
|
2009-08-11 16:06:17 +00:00
|
|
|
log_message("usage: <program> <ip addr of ethernet card to share>\n-->I'll try guessing ", inet_ntoa(addr));
|
2007-03-26 02:53:54 +00:00
|
|
|
}
|
2011-06-28 12:19:48 +00:00
|
|
|
#endif /* UIP_CONF_IPV6 */
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
log_message("wpcap_init:Using ipv4 ", inet_ntoa(addr));
|
|
|
|
sprint_ip6addr(addr6, addr6str);
|
|
|
|
log_message("wpcap_init:Using ipv6 ", addr6str);
|
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
log_message("wpcap_init:Using fallback ipv4 ", inet_ntoa(addrfall));
|
|
|
|
sprint_ip6addr(addrfall6, addr6str);
|
|
|
|
log_message("wpcap_init:Using fallback ipv6 ", addr6str);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// log_message("wpcap_init:cmdline address: ", inet_ntoa(addr));
|
|
|
|
|
2007-03-26 02:53:54 +00:00
|
|
|
|
|
|
|
wpcap = LoadLibrary("wpcap.dll");
|
2007-11-17 20:00:42 +00:00
|
|
|
pcap_findalldevs = (int (*)(struct pcap_if **, char *))
|
2009-08-11 16:06:17 +00:00
|
|
|
GetProcAddress(wpcap, "pcap_findalldevs");
|
2007-11-17 20:00:42 +00:00
|
|
|
pcap_open_live = (struct pcap *(*)(char *, int, int, int, char *))
|
2009-08-11 16:06:17 +00:00
|
|
|
GetProcAddress(wpcap, "pcap_open_live");
|
2007-11-17 20:00:42 +00:00
|
|
|
pcap_next_ex = (int (*)(struct pcap *, struct pcap_pkthdr **, unsigned char **))
|
2009-08-11 16:06:17 +00:00
|
|
|
GetProcAddress(wpcap, "pcap_next_ex");
|
2007-11-17 20:00:42 +00:00
|
|
|
pcap_sendpacket = (int (*)(struct pcap *, unsigned char *, int))
|
2009-08-11 16:06:17 +00:00
|
|
|
GetProcAddress(wpcap, "pcap_sendpacket");
|
2007-03-26 02:53:54 +00:00
|
|
|
|
|
|
|
if(pcap_findalldevs == NULL || pcap_open_live == NULL ||
|
|
|
|
pcap_next_ex == NULL || pcap_sendpacket == NULL) {
|
|
|
|
error_exit("error on access to winpcap library\n");
|
|
|
|
}
|
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
init_pcap(addr);
|
2009-08-11 16:06:17 +00:00
|
|
|
|
2007-03-26 02:53:54 +00:00
|
|
|
}
|
2009-08-13 18:41:00 +00:00
|
|
|
|
2007-03-26 02:53:54 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2012-02-20 18:42:51 +00:00
|
|
|
uint16_t
|
2007-03-26 02:53:54 +00:00
|
|
|
wpcap_poll(void)
|
|
|
|
{
|
|
|
|
struct pcap_pkthdr *packet_header;
|
|
|
|
unsigned char *packet;
|
|
|
|
|
|
|
|
switch(pcap_next_ex(pcap, &packet_header, &packet)) {
|
2007-11-17 18:01:00 +00:00
|
|
|
case -1:
|
2007-03-26 02:53:54 +00:00
|
|
|
error_exit("error on poll\n");
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-13 18:41:00 +00:00
|
|
|
#if UIP_CONF_IPV6
|
|
|
|
/* 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
|
|
|
|
* would be processed as a conflicting NS race which would cause a stack shutdown.
|
|
|
|
* So discard all packets with our source address (packet starts destaddr, srcaddr, ...)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
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) {
|
2011-06-28 12:19:48 +00:00
|
|
|
PRINTF("SIN: Discarding echoed packet\n");
|
2009-08-13 18:41:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-06-30 16:12:07 +00:00
|
|
|
|
|
|
|
/* To implement multihop, ignore packets to us from specified source macs
|
|
|
|
*/
|
|
|
|
// printf("ethtype=%x %x",*(packet+2*UIP_LLADDR_LEN),*(packet+2*UIP_LLADDR_LEN+1));
|
|
|
|
// printf("hopcount=%u",*(packet+21));
|
|
|
|
#if 0
|
|
|
|
if (0
|
|
|
|
// || (*(packet+11) ==0x1) //20 ignores router
|
|
|
|
// || (*(packet+11) ==0x10)
|
|
|
|
|| (*(packet+11) ==0x20) //router ignores 20
|
|
|
|
) {
|
|
|
|
printf("i%x",*(packet+11));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* If we are not the recipient, ignore packets from other RPL nodes */
|
|
|
|
if (0
|
|
|
|
|| (*(packet+5) !=0x1) //router
|
|
|
|
// || (*(packet+11) ==0x10)
|
|
|
|
// || (*(packet+11) ==0x20) //router ignores 20
|
|
|
|
) {
|
|
|
|
printf("r%x",*(packet+11));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-08-13 18:41:00 +00:00
|
|
|
#endif /* UIP_CONF_IPV6 */
|
|
|
|
|
2007-04-08 20:06:56 +00:00
|
|
|
if(packet_header->caplen > UIP_BUFSIZE) {
|
|
|
|
return 0;
|
|
|
|
}
|
2011-06-28 12:19:48 +00:00
|
|
|
// PRINTF("SIN: %lu\n", packet_header->caplen);
|
|
|
|
CopyMemory(uip_buf, packet, packet_header->caplen);
|
2012-02-20 18:42:51 +00:00
|
|
|
return (uint16_t)packet_header->caplen;
|
2011-06-28 12:19:48 +00:00
|
|
|
|
|
|
|
}
|
2007-04-08 20:06:56 +00:00
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
2012-02-20 18:42:51 +00:00
|
|
|
uint16_t
|
2011-06-28 12:19:48 +00:00
|
|
|
wfall_poll(void)
|
|
|
|
{
|
|
|
|
struct pcap_pkthdr *packet_header;
|
|
|
|
unsigned char *packet;
|
|
|
|
|
|
|
|
switch(pcap_next_ex(pfall, &packet_header, &packet)) {
|
|
|
|
case -1:
|
|
|
|
error_exit("error on fallback poll\n");
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#if UIP_CONF_IPV6
|
2012-01-08 18:37:56 +00:00
|
|
|
#if FALLBACK_HAS_ETHERNET_HEADERS
|
|
|
|
#define ETHERNET_LLADDR_LEN 6
|
|
|
|
#else
|
|
|
|
#define ETHERNET_LLADDR_LEN UIP_LLADDR_LEN
|
|
|
|
#endif
|
2011-06-28 12:19:48 +00:00
|
|
|
/* 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
|
|
|
|
* would be processed as a conflicting NS race which would cause a stack shutdown.
|
|
|
|
* So discard all packets with our source address (packet starts destaddr, srcaddr, ...)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int i;
|
2012-01-08 18:37:56 +00:00
|
|
|
for (i=0;i<ETHERNET_LLADDR_LEN;i++) if (*(packet+ETHERNET_LLADDR_LEN+i)!=uip_lladdr.addr[i]) break;
|
|
|
|
if (i==ETHERNET_LLADDR_LEN) {
|
2011-06-28 12:19:48 +00:00
|
|
|
PRINTF("Discarding echoed packet\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* UIP_CONF_IPV6 */
|
|
|
|
|
|
|
|
if(packet_header->caplen > UIP_BUFSIZE) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
PRINTF("FIN: %lu\n", packet_header->caplen);
|
2007-03-26 02:53:54 +00:00
|
|
|
CopyMemory(uip_buf, packet, packet_header->caplen);
|
2012-02-20 18:42:51 +00:00
|
|
|
return (uint16_t)packet_header->caplen;
|
2009-08-13 18:41:00 +00:00
|
|
|
|
2007-03-26 02:53:54 +00:00
|
|
|
}
|
2009-08-13 18:41:00 +00:00
|
|
|
|
2011-06-28 12:19:48 +00:00
|
|
|
#endif
|
|
|
|
|
2007-03-26 02:53:54 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2009-08-08 19:51:25 +00:00
|
|
|
#if UIP_CONF_IPV6
|
2012-02-20 18:42:51 +00:00
|
|
|
uint8_t
|
2013-11-18 22:26:37 +00:00
|
|
|
wpcap_send(const uip_lladdr_t *lladdr)
|
2009-08-08 19:51:25 +00:00
|
|
|
{
|
2011-06-30 16:12:07 +00:00
|
|
|
if(lladdr == NULL) {
|
2009-08-11 16:06:17 +00:00
|
|
|
/* the dest must be multicast*/
|
2009-08-08 19:51:25 +00:00
|
|
|
(&BUF->dest)->addr[0] = 0x33;
|
|
|
|
(&BUF->dest)->addr[1] = 0x33;
|
2009-08-11 16:06:17 +00:00
|
|
|
(&BUF->dest)->addr[2] = IPBUF->destipaddr.u8[12];
|
|
|
|
(&BUF->dest)->addr[3] = IPBUF->destipaddr.u8[13];
|
|
|
|
(&BUF->dest)->addr[4] = IPBUF->destipaddr.u8[14];
|
|
|
|
(&BUF->dest)->addr[5] = IPBUF->destipaddr.u8[15];
|
2009-08-08 19:51:25 +00:00
|
|
|
} else {
|
2011-06-30 16:12:07 +00:00
|
|
|
//when fallback used this gets ptr to lladdr of all zeroes on forwarded packets, turn them into multicast(?)
|
|
|
|
if ((lladdr->addr[0]==0)&&(lladdr->addr[1]==0)&&(lladdr->addr[2]==0)&&(lladdr->addr[3]==0)&&(lladdr->addr[4]==0)&&(lladdr->addr[5]==0)) {
|
|
|
|
(&BUF->dest)->addr[0] = 0x33;
|
|
|
|
(&BUF->dest)->addr[1] = 0x33;
|
|
|
|
(&BUF->dest)->addr[2] = IPBUF->destipaddr.u8[12];
|
|
|
|
(&BUF->dest)->addr[3] = IPBUF->destipaddr.u8[13];
|
|
|
|
(&BUF->dest)->addr[4] = IPBUF->destipaddr.u8[14];
|
|
|
|
(&BUF->dest)->addr[5] = IPBUF->destipaddr.u8[15];
|
|
|
|
} else {
|
|
|
|
memcpy(&BUF->dest, lladdr, UIP_LLADDR_LEN);
|
|
|
|
}
|
2009-08-08 19:51:25 +00:00
|
|
|
}
|
2009-08-11 16:06:17 +00:00
|
|
|
memcpy(&BUF->src, &uip_lladdr, UIP_LLADDR_LEN);
|
2011-06-28 12:19:48 +00:00
|
|
|
PRINTF("SUT: %u\n", uip_len);
|
2009-08-11 16:06:17 +00:00
|
|
|
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);
|
2010-10-19 18:29:03 +00:00
|
|
|
BUF->type = UIP_HTONS(UIP_ETHTYPE_IPV6);
|
2009-08-08 19:51:25 +00:00
|
|
|
uip_len += sizeof(struct uip_eth_hdr);
|
|
|
|
if(pcap_sendpacket(pcap, uip_buf, uip_len) == -1) {
|
|
|
|
error_exit("error on send\n");
|
|
|
|
}
|
2009-08-11 16:06:17 +00:00
|
|
|
return 0;
|
2009-08-13 18:41:00 +00:00
|
|
|
}
|
2011-06-28 12:19:48 +00:00
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
2012-02-20 18:42:51 +00:00
|
|
|
uint8_t
|
2013-11-18 22:26:37 +00:00
|
|
|
wfall_send(const uip_lladdr_t *lladdr)
|
2011-06-28 12:19:48 +00:00
|
|
|
{
|
2012-01-08 18:37:56 +00:00
|
|
|
#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
|
2011-06-28 12:19:48 +00:00
|
|
|
if(lladdr == NULL) {
|
|
|
|
/* the dest must be multicast*/
|
|
|
|
(&BUF->dest)->addr[0] = 0x33;
|
|
|
|
(&BUF->dest)->addr[1] = 0x33;
|
|
|
|
(&BUF->dest)->addr[2] = IPBUF->destipaddr.u8[12];
|
|
|
|
(&BUF->dest)->addr[3] = IPBUF->destipaddr.u8[13];
|
|
|
|
(&BUF->dest)->addr[4] = IPBUF->destipaddr.u8[14];
|
|
|
|
(&BUF->dest)->addr[5] = IPBUF->destipaddr.u8[15];
|
|
|
|
} else {
|
|
|
|
memcpy(&BUF->dest, lladdr, UIP_LLADDR_LEN);
|
|
|
|
}
|
|
|
|
memcpy(&BUF->src, &uip_lladdr, UIP_LLADDR_LEN);
|
|
|
|
PRINTF("FUT: %u\n", uip_len);
|
|
|
|
PRINTF("Srcf= %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(" Dstf= %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(" Typef=%04x\n",BUF->type);
|
|
|
|
BUF->type = UIP_HTONS(UIP_ETHTYPE_IPV6);
|
|
|
|
uip_len += sizeof(struct uip_eth_hdr);
|
|
|
|
if(pcap_sendpacket(pfall, uip_buf, uip_len) == -1) {
|
|
|
|
error_exit("error on fallback send\n");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2009-08-08 19:51:25 +00:00
|
|
|
#else /* UIP_CONF_IPV6 */
|
2007-03-26 02:53:54 +00:00
|
|
|
void
|
|
|
|
wpcap_send(void)
|
|
|
|
{
|
2008-06-23 19:52:44 +00:00
|
|
|
/* if(rand() % 1000 > 900) {
|
|
|
|
printf("Drop\n");
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
printf("Send\n");
|
|
|
|
}*/
|
|
|
|
|
2009-08-09 20:44:42 +00:00
|
|
|
if(pcap_sendpacket(pcap, uip_buf, uip_len) == -1) {
|
2007-03-26 02:53:54 +00:00
|
|
|
error_exit("error on send\n");
|
|
|
|
}
|
|
|
|
}
|
2009-08-08 19:51:25 +00:00
|
|
|
#endif /* UIP_CONF_IPV6 */
|
2007-03-26 02:53:54 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-05-20 21:29:39 +00:00
|
|
|
void
|
|
|
|
wpcap_exit(void)
|
|
|
|
{
|
2007-05-22 22:01:03 +00:00
|
|
|
FreeLibrary(wpcap);
|
2007-05-20 21:29:39 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|