start the helper from the daemon, end it correctly
[oweals/gnunet.git] / src / vpn / test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/socket.h>
4 #include <string.h>
5
6 #include <linux/if.h>
7
8 #include "packet.h"
9 #include "tun.h"
10 #include "debug.h"
11 #include "pretty-print.h"
12 #include "tcp.h"
13 #include "udp.h"
14 #include <arpa/inet.h>
15
16
17 int main(int c, char** v) {
18         char dev[IFNAMSIZ];
19         memset(dev, 0, IFNAMSIZ);
20         int fd = init_tun(dev);
21
22         debug(1, 0, "Initialized the interface %s.\n", dev);
23
24         struct pkt_tun* pkt;
25
26         for(;;) {
27                 printf("read %d bytes from socket, ", recv_pkt(fd, &pkt));
28                 switch (ntohs(pkt->type)) {
29                         case 0x86dd:
30                                 printf("parsing ipv6:\n");
31                                 struct ip6_pkt* pkt6 = parse_ip6(pkt);
32                                 pkt_printf(pkt6);
33                                 struct ip6_tcp* pkt6_tcp;
34                                 struct ip6_udp* pkt6_udp;
35                                 switch(pkt6->hdr.nxthdr) {
36                                         case 0x06:
37                                                 pkt6_tcp = parse_ip6_tcp(pkt6);
38                                                 pkt_printf_ip6tcp(pkt6_tcp);
39                                                 handle_tcp(pkt6_tcp);
40                                                 break;
41                                         case 0x11:
42                                                 pkt6_udp = parse_ip6_udp(pkt6);
43                                                 pkt_printf_ip6udp(pkt6_udp);
44                                                 handle_udp(pkt6_udp);
45                                                 break;
46                                 }
47                                 break;
48                         default:
49                                 printf("unknown/unimplemented packet-type\n");
50                                 break;
51                 }
52         }
53 }