7 #include <linux/if_tun.h>
11 #include "arpa/inet.h"
13 short payload(struct ip6_hdr* hdr) {{{
14 return ntohs(hdr->paylgth);
17 void send_pkt(int fd, struct ip6_pkt* pkt) {{{
18 int sz = payload(&(pkt->hdr));
20 char* buf = (char*)pkt;
24 int t = write(fd, buf+w, (sz + 40) - w);
26 debug(1, 0, "packet: write : %s\n", strerror(errno));
34 int recv_pkt(int fd, struct pkt_tun** pkt) {{{
36 unsigned char data[size];
38 debug(1, 0, "beginning to read...\n");
40 int r = read(fd, data, size);
41 debug(1, 0, "read %d bytes\n", r);
43 *pkt = (struct pkt_tun*)malloc(r);
45 memcpy(*pkt, data, r);
46 struct pkt_tun *_pkt = *pkt;
48 debug(1, 0, "read the flags: %04x\n", ntohs(_pkt->flags));
49 debug(1, 0, "read the type: %04x\n", ntohs(_pkt->type));
51 switch(ntohs(_pkt->type)) {
53 debug(1, 0, "reading an ipv6-packet\n");
54 struct ip6_pkt * pkt6 = (struct ip6_pkt*) *pkt;
55 size = payload(&(pkt6->hdr));
56 debug(1, 0, "read the size: %d\n", size);
60 debug(1, 0, "unknown pkt-type: IPv4\n");
64 debug(1, 0, "unknown pkt-type: 0x%02x\n", 0x800);
71 struct ip6_pkt* parse_ip6(struct pkt_tun* pkt) {{{
72 struct ip6_pkt* pkt6 = (struct ip6_pkt*)pkt;
77 struct ip6_tcp* parse_ip6_tcp(struct ip6_pkt* pkt) {{{
78 struct ip6_tcp* res = (struct ip6_tcp*) pkt;