46 #include <sys/ioctl.h>
47 #include <sys/socket.h>
48 #include <sys/types.h>
51 #include <sys/socket.h>
54 #include <sys/ioctl.h>
56 #include <linux/if_tun.h>
57 #define DEVTAP "/dev/net/tun"
59 #define DEVTAP "/dev/tap0"
62 #include "contiki-net.h"
73 static unsigned long lasttime;
75 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
79 #define PRINTF(...) fprintf(stderr, __VA_ARGS__)
96 snprintf(buf,
sizeof(buf),
"route delete -net 172.18.0.0");
98 fprintf(stderr,
"%s\n", buf);
107 fd = open(DEVTAP, O_RDWR);
109 perror(
"tapdev: tapdev_init: open");
116 memset(&ifr, 0,
sizeof(ifr));
117 ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
118 if (ioctl(fd, TUNSETIFF, (
void *) &ifr) < 0) {
119 perror(
"ioctl(TUNSETIFF)");
125 snprintf(buf,
sizeof(buf),
"ifconfig tap0 inet 172.18.0.1/16");
127 fprintf(stderr,
"%s\n", buf);
130 snprintf(buf,
sizeof(buf),
"route add -net 172.18.0.0/16 dev tap0");
133 snprintf(buf,
sizeof(buf),
"route add -net 172.18.0.0/16 -iface tap0");
137 fprintf(stderr,
"%s\n", buf);
138 atexit(remove_route);
158 ret = select(fd + 1, &fdset,
NULL,
NULL, &tv);
164 PRINTF(
"tapdev_poll: read %d bytes\n", ret);
167 perror(
"tapdev_poll: read");
187 fprintf(stderr,
"Dropped an output packet!\n");
192 PRINTF(
"tapdev_send: sending %d bytes\n",
uip_len);
193 ret = write(fd, uip_buf,
uip_len);
196 perror(
"tap_dev: tapdev_send: writev");
uip_len
The length of the packet in the uip_buf buffer.
Header file for the uIP TCP/IP stack.
#define NULL
The null pointer.
#define UIP_BUFSIZE
The size of the uIP packet buffer.
Configuration options for uIP.