Made wpcapslip work with IPv6 enabled. Added -l option to turn on logging.
This commit is contained in:
parent
f6c310d90a
commit
38f0ac4a36
|
@ -30,7 +30,7 @@
|
||||||
*
|
*
|
||||||
* Author: Oliver Schmidt <ol.sc@web.de>
|
* 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;
|
||||||
|
|
||||||
struct pcap_if {
|
|
||||||
struct pcap_if *next;
|
|
||||||
char *name;
|
|
||||||
char *description;
|
|
||||||
struct pcap_addr {
|
struct pcap_addr {
|
||||||
struct pcap_addr *next;
|
struct pcap_addr *next;
|
||||||
struct sockaddr *addr;
|
struct sockaddr *addr;
|
||||||
struct sockaddr *netmask;
|
struct sockaddr *netmask;
|
||||||
struct sockaddr *broadaddr;
|
struct sockaddr *broadaddr;
|
||||||
struct sockaddr *dstaddr;
|
struct sockaddr *dstaddr;
|
||||||
} *addresses;
|
};
|
||||||
|
|
||||||
|
struct pcap_if {
|
||||||
|
struct pcap_if *next;
|
||||||
|
char *name;
|
||||||
|
char *description;
|
||||||
|
struct pcap_addr *addresses;
|
||||||
DWORD flags;
|
DWORD flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -165,10 +167,14 @@ static uip_ipaddr_t ifaddr, netaddr, netmask;
|
||||||
|
|
||||||
static int arptime;
|
static int arptime;
|
||||||
|
|
||||||
|
static int logging;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
log_message(char *msg1, char *msg2)
|
log_message(char *msg1, char *msg2)
|
||||||
{
|
{
|
||||||
/* printf("Log: %s %s\n", msg1, msg2);*/
|
if(logging) {
|
||||||
|
printf("Log: %s %s\n", msg1, msg2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
|
@ -182,6 +188,7 @@ static void
|
||||||
init_pcap(struct in_addr addr)
|
init_pcap(struct in_addr addr)
|
||||||
{
|
{
|
||||||
struct pcap_if *interfaces;
|
struct pcap_if *interfaces;
|
||||||
|
struct pcap_addr *paddr;
|
||||||
char error[256];
|
char error[256];
|
||||||
|
|
||||||
if(pcap_findalldevs(&interfaces, error) == -1) {
|
if(pcap_findalldevs(&interfaces, error) == -1) {
|
||||||
|
@ -191,16 +198,24 @@ init_pcap(struct in_addr addr)
|
||||||
while(interfaces != NULL) {
|
while(interfaces != NULL) {
|
||||||
log_message("init_pcap: found interface: ", interfaces->description);
|
log_message("init_pcap: found interface: ", interfaces->description);
|
||||||
|
|
||||||
if(interfaces->addresses != NULL &&
|
if(interfaces->addresses != NULL) {
|
||||||
interfaces->addresses->addr != NULL &&
|
for(paddr = interfaces->addresses;
|
||||||
interfaces->addresses->addr->sa_family == AF_INET) {
|
paddr != NULL;
|
||||||
|
paddr = paddr->next) {
|
||||||
|
if(paddr->addr != NULL && paddr->addr->sa_family == AF_INET) {
|
||||||
|
|
||||||
struct in_addr interface_addr;
|
struct in_addr interface_addr;
|
||||||
interface_addr = ((struct sockaddr_in *)interfaces->addresses->addr)->sin_addr;
|
interface_addr = ((struct sockaddr_in *)paddr->addr)->sin_addr;
|
||||||
log_message("init_pcap: with address: ", inet_ntoa(interface_addr));
|
log_message("init_pcap: with address: ", inet_ntoa(interface_addr));
|
||||||
|
|
||||||
if(interface_addr.s_addr == addr.s_addr) {
|
if(interface_addr.s_addr == addr.s_addr) {
|
||||||
break;
|
pcap = pcap_open_live(interfaces->name, BUFSIZE, 0, -1, error);
|
||||||
|
if(pcap == NULL) {
|
||||||
|
error_exit(error);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
interfaces = interfaces->next;
|
interfaces = interfaces->next;
|
||||||
|
@ -209,11 +224,6 @@ 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 ip addr specified on cmdline\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
pcap = pcap_open_live(interfaces->name, BUFSIZE, 0, -1, error);
|
|
||||||
if(pcap == NULL) {
|
|
||||||
error_exit(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
|
@ -530,11 +540,13 @@ remove_route(int s)
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
wpcap_start(char *ethcardaddr, char *slipnetaddr, char *slipnetmask)
|
wpcap_start(char *ethcardaddr, char *slipnetaddr, char *slipnetmask, int log)
|
||||||
{
|
{
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
char buf[4000];
|
char buf[4000];
|
||||||
|
|
||||||
|
logging = log;
|
||||||
|
|
||||||
addr.s_addr = inet_addr(ethcardaddr);
|
addr.s_addr = inet_addr(ethcardaddr);
|
||||||
ifaddr.u32[0] = inet_addr(ethcardaddr);
|
ifaddr.u32[0] = inet_addr(ethcardaddr);
|
||||||
netaddr.u32[0] = inet_addr(slipnetaddr);
|
netaddr.u32[0] = inet_addr(slipnetaddr);
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
*
|
*
|
||||||
* Author: Oliver Schmidt <ol.sc@web.de>
|
* 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)
|
#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);
|
void wpcap_send(void *buf, int len);
|
||||||
|
|
||||||
|
@ -663,13 +663,13 @@ main(int argc, char **argv)
|
||||||
/* u_int16_t myport = BOOTPS, dhport = BOOTPS;*/
|
/* u_int16_t myport = BOOTPS, dhport = BOOTPS;*/
|
||||||
int baudrate = -2;
|
int baudrate = -2;
|
||||||
char buf[4000];
|
char buf[4000];
|
||||||
|
int logging = 0;
|
||||||
|
|
||||||
ip_id = getpid() * time(NULL);
|
ip_id = getpid() * time(NULL);
|
||||||
|
|
||||||
setvbuf(stdout, NULL, _IOLBF, 0); /* Line buffered output. */
|
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) {
|
switch (c) {
|
||||||
case 'B':
|
case 'B':
|
||||||
baudrate = atoi(optarg);
|
baudrate = atoi(optarg);
|
||||||
|
@ -701,6 +701,10 @@ main(int argc, char **argv)
|
||||||
should_print = 1;
|
should_print = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
logging = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
case 'h':
|
case 'h':
|
||||||
default:
|
default:
|
||||||
|
@ -716,7 +720,7 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
/* ipaddr = argv[1];
|
/* ipaddr = argv[1];
|
||||||
netmask = argv[2];*/
|
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);*/
|
/* netaddr = inet_addr(ipaddr) & inet_addr(netmask);*/
|
||||||
|
|
||||||
switch(baudrate) {
|
switch(baudrate) {
|
||||||
|
|
Loading…
Reference in a new issue