39 #if !NETSTACK_CONF_WITH_IPV6
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__)
98 snprintf(buf,
sizeof(buf),
"route delete -net 172.18.0.0");
100 fprintf(stderr,
"ret %d\n", ret);
101 fprintf(stderr,
"%s\n", buf);
111 fd = open(DEVTAP, O_RDWR);
113 perror(
"tapdev: tapdev_init: open");
120 memset(&ifr, 0,
sizeof(ifr));
121 ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
122 if (ioctl(fd, TUNSETIFF, (
void *) &ifr) < 0) {
123 perror(
"ioctl(TUNSETIFF)");
129 snprintf(buf,
sizeof(buf),
"ifconfig tap0 inet 172.18.0.1/16");
131 fprintf(stderr,
"ret %d\n", ret);
132 fprintf(stderr,
"%s\n", buf);
135 snprintf(buf,
sizeof(buf),
"route add -net 172.18.0.0/16 dev tap0");
138 snprintf(buf,
sizeof(buf),
"route add -net 172.18.0.0/16 -iface tap0");
142 fprintf(stderr,
"ret %d\n", ret);
143 fprintf(stderr,
"%s\n", buf);
144 atexit(remove_route);
164 ret = select(fd + 1, &fdset,
NULL,
NULL, &tv);
170 PRINTF(
"tapdev_poll: read %d bytes\n", ret);
173 perror(
"tapdev_poll: read");
193 fprintf(stderr,
"Dropped an output packet!\n");
198 PRINTF(
"tapdev_send: sending %d bytes\n",
uip_len);
202 perror(
"tap_dev: tapdev_send: writev");
uip_len
The length of the packet in the uip_buf buffer.
Configuration options for uIP.
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
#define NULL
The null pointer.
Header file for the uIP TCP/IP stack.
#define UIP_BUFSIZE
The size of the uIP packet buffer.