Made wpcapslip work with IPv6 enabled. Added -l option to turn on logging.

This commit is contained in:
adamdunkels 2008-06-19 07:52:28 +00:00
parent f6c310d90a
commit 38f0ac4a36
2 changed files with 46 additions and 30 deletions

View file

@ -30,7 +30,7 @@
*
* Author: Oliver Schmidt <ol.sc@web.de>
*
* $Id: wpcap.c,v 1.2 2008/02/24 21:14:25 adamdunkels Exp $
* $Id: wpcap.c,v 1.3 2008/06/19 07:52:28 adamdunkels Exp $
*/
@ -78,17 +78,19 @@ static void raw_send(void *buf, int len);
struct pcap;
struct pcap_addr {
struct pcap_addr *next;
struct sockaddr *addr;
struct sockaddr *netmask;
struct sockaddr *broadaddr;
struct sockaddr *dstaddr;
};
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;
struct pcap_addr *addresses;
DWORD flags;
};
@ -165,10 +167,14 @@ static uip_ipaddr_t ifaddr, netaddr, netmask;
static int arptime;
static int logging;
static void
log_message(char *msg1, char *msg2)
{
/* printf("Log: %s %s\n", msg1, msg2);*/
if(logging) {
printf("Log: %s %s\n", msg1, msg2);
}
}
/*---------------------------------------------------------------------------*/
static void
@ -182,6 +188,7 @@ 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) {
@ -191,16 +198,24 @@ init_pcap(struct in_addr addr)
while(interfaces != NULL) {
log_message("init_pcap: found interface: ", interfaces->description);
if(interfaces->addresses != NULL &&
interfaces->addresses->addr != NULL &&
interfaces->addresses->addr->sa_family == AF_INET) {
struct in_addr interface_addr;
interface_addr = ((struct sockaddr_in *)interfaces->addresses->addr)->sin_addr;
log_message("init_pcap: with address: ", inet_ntoa(interface_addr));
if(interface_addr.s_addr == addr.s_addr) {
break;
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, BUFSIZE, 0, -1, error);
if(pcap == NULL) {
error_exit(error);
}
return;
}
}
}
}
interfaces = interfaces->next;
@ -209,11 +224,6 @@ init_pcap(struct in_addr addr)
if(interfaces == NULL) {
error_exit("no interface found with ip addr specified on cmdline\n");
}
pcap = pcap_open_live(interfaces->name, BUFSIZE, 0, -1, error);
if(pcap == NULL) {
error_exit(error);
}
}
/*---------------------------------------------------------------------------*/
static void
@ -530,11 +540,13 @@ remove_route(int s)
}
/*---------------------------------------------------------------------------*/
void
wpcap_start(char *ethcardaddr, char *slipnetaddr, char *slipnetmask)
wpcap_start(char *ethcardaddr, char *slipnetaddr, char *slipnetmask, int log)
{
struct in_addr addr;
char buf[4000];
logging = log;
addr.s_addr = inet_addr(ethcardaddr);
ifaddr.u32[0] = inet_addr(ethcardaddr);
netaddr.u32[0] = inet_addr(slipnetaddr);

View file

@ -30,7 +30,7 @@
*
* Author: Oliver Schmidt <ol.sc@web.de>
*
* $Id: wpcapslip.c,v 1.2 2008/02/24 21:14:25 adamdunkels Exp $
* $Id: wpcapslip.c,v 1.3 2008/06/19 07:52:28 adamdunkels Exp $
*/
@ -65,7 +65,7 @@
#define PROGRESS(x)
void wpcap_start(char *ethifaddr, char *netaddr, char *netmask);
void wpcap_start(char *ethifaddr, char *netaddr, char *netmask, int logging);
void wpcap_send(void *buf, int len);
@ -663,13 +663,13 @@ main(int argc, char **argv)
/* u_int16_t myport = BOOTPS, dhport = BOOTPS;*/
int baudrate = -2;
char buf[4000];
int logging = 0;
ip_id = getpid() * time(NULL);
setvbuf(stdout, NULL, _IOLBF, 0); /* Line buffered output. */
while((c = getopt(argc, argv, "B:D:hs:t:T")) != -1) {
while((c = getopt(argc, argv, "B:D:hls:t:T")) != -1) {
switch (c) {
case 'B':
baudrate = atoi(optarg);
@ -700,6 +700,10 @@ main(int argc, char **argv)
case 'T':
should_print = 1;
break;
case 'l':
logging = 1;
break;
case '?':
case 'h':
@ -716,7 +720,7 @@ main(int argc, char **argv)
}
/* ipaddr = argv[1];
netmask = argv[2];*/
wpcap_start(argv[1], argv[2], argv[3]);
wpcap_start(argv[1], argv[2], argv[3], logging);
/* netaddr = inet_addr(ipaddr) & inet_addr(netmask);*/
switch(baudrate) {