42 #include <sys/ioctl.h>
43 #include <sys/socket.h>
44 #include <sys/types.h>
47 #include <sys/socket.h>
50 #include <sys/ioctl.h>
52 #include <linux/if_tun.h>
53 #define DEVTAP "/dev/net/tun"
55 #define DEVTAP "/dev/tap0"
58 #include "contiki-net.h"
69 static unsigned long lasttime;
71 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
78 snprintf(buf,
sizeof(buf),
"route delete -net 172.16.0.0");
89 fd = open(DEVTAP, O_RDWR);
91 perror(
"tapdev: tapdev_init: open");
98 memset(&ifr, 0,
sizeof(ifr));
99 ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
100 if (ioctl(fd, TUNSETIFF, (
void *) &ifr) < 0) {
107 snprintf(buf,
sizeof(buf),
"ifconfig tap0 inet 192.168.1.1");
112 snprintf(buf,
sizeof(buf),
"route add -net 172.16.0.0/16 gw 192.168.1.2");
115 snprintf(buf,
sizeof(buf),
"route add -net 172.16.0.0/16 192.168.1.2");
120 atexit(remove_route);
140 ret = select(fd + 1, &fdset,
NULL,
NULL, &tv);
148 perror(
"tapdev_poll: read");
168 printf(
"Dropped an output packet!\n");
173 ret = write(fd, uip_buf,
uip_len);
176 perror(
"tap_dev: tapdev_send: writev");