2 * Copyright (c) 2001, Swedish Institute of Computer Science.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the Institute nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * Author: Adam Dunkels <adam@sics.se>
34 * $Id: tapdev6.c,v 1.2 2006/08/10 19:22:23 bg- Exp $
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])
77 static void do_send(void);
78 u8_t
tapdev_send(void);
96 ret
= select(fd
+ 1, &fdset
, NULL
, NULL
, &tv
);
101 ret
= read(fd
, uip_buf
, UIP_BUFSIZE
);
103 /* printf("tapdev6: read %d bytes\n", ret);*/
106 perror("tapdev_poll: read");
110 /*---------------------------------------------------------------------------*/
116 fd
= open(DEVTAP
, O_RDWR
);
118 perror("tapdev: tapdev_init: open");
125 memset(&ifr
, 0, sizeof(ifr
));
126 ifr
.ifr_flags
= IFF_TAP
|IFF_NO_PI
;
127 if (ioctl(fd
, TUNSETIFF
, (void *) &ifr
) < 0) {
134 snprintf(buf
, sizeof(buf
), "ifconfig tap0 inet6 fc00::123");
137 snprintf(buf
, sizeof(buf
), "route add -inet6 fc00::0/64 -interface tap0");
143 /* gdk_input_add(fd, GDK_INPUT_READ,
144 read_callback, NULL);*/
147 /*---------------------------------------------------------------------------*/
158 /* printf("tapdev_send: sending %d bytes\n", size);*/
159 /* check_checksum(uip_buf, size);*/
163 printf("Dropped an output packet!\n");
168 ret
= write(fd
, uip_buf
, uip_len
);
171 perror("tap_dev: tapdev_send: writev");
175 /*---------------------------------------------------------------------------*/
176 #define DEBUG_PRINTF(...) printf(__VA_ARGS__)
177 #define DEBUG_PRINT6ADDR(addr) DEBUG_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])
181 struct uip_neighbor_addr
*addr
;
184 addr
= uip_neighbor_lookup(&IPBUF
->destipaddr
);
186 printf("tapdev6: tapdev_send: no matching neighbor found\n");
187 DEBUG_PRINT6ADDR(&IPBUF
->destipaddr
);
190 memcpy(&BUF
->dest
, addr
, 6);
191 memcpy(&BUF
->src
, &uip_ethaddr
, 6);
192 uip_len
+= sizeof(struct uip_eth_hdr
);
197 /*---------------------------------------------------------------------------*/
203 /*---------------------------------------------------------------------------*/