43 #include <sys/ioctl.h>
44 #include <sys/socket.h>
45 #include <sys/types.h>
48 #include <sys/socket.h>
52 #include <sys/ioctl.h>
54 #include <linux/if_tun.h>
55 #define DEVTAP "/dev/net/tun"
57 #define DEVTAP "/dev/tap0"
62 #include "contiki-net.h"
72 static unsigned long lasttime;
74 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
75 #define IPBUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
79 #define PRINTF(...) printf(__VA_ARGS__)
80 #define PRINT6ADDR(addr) PRINTF("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15])
83 #define PRINT6ADDR(addr)
86 static void do_send(
void);
105 ret = select(fd + 1, &fdset,
NULL,
NULL, &tv);
112 PRINTF(
"tapdev6: read %d bytes (max %d)\n", ret,
UIP_BUFSIZE);
115 perror(
"tapdev_poll: read");
125 fd = open(DEVTAP, O_RDWR);
127 perror(
"tapdev: tapdev_init: open");
134 memset(&ifr, 0,
sizeof(ifr));
135 ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
136 if (ioctl(fd, TUNSETIFF, (
void *) &ifr) < 0) {
155 snprintf(buf,
sizeof(buf),
"ifconfig tap0 up");
177 PRINTF(
"tapdev_send: sending %d bytes\n",
uip_len);
182 PRINTF(
"Dropped an output packet!\n");
187 ret = write(fd, uip_buf,
uip_len);
190 perror(
"tap_dev: tapdev_send: writev");
204 (&BUF->dest)->addr[0] = 0x33;
205 (&BUF->dest)->addr[1] = 0x33;
206 (&BUF->dest)->addr[2] = IPBUF->destipaddr.u8[12];
207 (&BUF->dest)->addr[3] = IPBUF->destipaddr.u8[13];
208 (&BUF->dest)->addr[4] = IPBUF->destipaddr.u8[14];
209 (&BUF->dest)->addr[5] = IPBUF->destipaddr.u8[15];
211 memcpy(&BUF->dest, lladdr, UIP_LLADDR_LEN);
213 memcpy(&BUF->src, &
uip_lladdr, UIP_LLADDR_LEN);