gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r12271 - gnunet/src/vpn


From: gnunet
Subject: [GNUnet-SVN] r12271 - gnunet/src/vpn
Date: Tue, 20 Jul 2010 11:41:26 +0200

Author: toelke
Date: 2010-07-20 11:41:26 +0200 (Tue, 20 Jul 2010)
New Revision: 12271

Modified:
   gnunet/src/vpn/gnunet-daemon-vpn.c
   gnunet/src/vpn/gnunet-vpn-packet.h
   gnunet/src/vpn/gnunet-vpn-pretty-print.c
Log:
Pretty-Print Packets from the helper

Modified: gnunet/src/vpn/gnunet-daemon-vpn.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn.c  2010-07-20 09:33:32 UTC (rev 12270)
+++ gnunet/src/vpn/gnunet-daemon-vpn.c  2010-07-20 09:41:26 UTC (rev 12271)
@@ -28,6 +28,8 @@
 #include "gnunet_program_lib.h"
 #include "gnunet_os_lib.h"
 #include "gnunet-vpn-helper-p.h"
+#include "gnunet-vpn-packet.h"
+#include "gnunet-vpn-pretty-print.h"
 /* #include "gnunet_template_service.h" */
 
 /**
@@ -71,8 +73,6 @@
                r += t;
        }
 
-       fprintf(stderr, "Read %d bytes for the header. The 'size' is %x, that 
is %d\n", r, hdr.size, ntohl(hdr.size));
-
        struct suid_packet *pkt = (struct suid_packet*) 
GNUNET_malloc(ntohl(hdr.size));
 
        if (memcpy(pkt, &hdr, sizeof(struct suid_packet_header)) < 0) {
@@ -89,11 +89,24 @@
                r += t;
        }
 
-       printf("read %d bytes. The first 87 are:\n\t", r);
+       struct ip6_pkt *pkt6 = (struct ip6_pkt*) pkt;
+       struct ip6_tcp *pkt6_tcp;
+       struct ip6_udp *pkt6_udp;
 
-       for (r = 0; r < 87; r++)
-               printf("%02x ", pkt->data[r]);
-       printf("\n");
+       pkt_printf(pkt6);
+       switch(pkt6->ip6_hdr.nxthdr) {
+               case 0x06:
+                       pkt6_tcp = (struct ip6_tcp*)pkt6;
+                       pkt_printf_ip6tcp(pkt6_tcp);
+                       break;
+               case 0x11:
+                       pkt6_udp = (struct ip6_udp*)pkt6;
+                       pkt_printf_ip6udp(pkt6_udp);
+                       if (ntohs(pkt6_udp->udp_hdr.dpt) == 53) {
+                               pkt_printf_ip6dns((struct 
ip6_udp_dns*)pkt6_udp);
+                       }
+                       break;
+       }
 
        GNUNET_free(pkt);
 

Modified: gnunet/src/vpn/gnunet-vpn-packet.h
===================================================================
--- gnunet/src/vpn/gnunet-vpn-packet.h  2010-07-20 09:33:32 UTC (rev 12270)
+++ gnunet/src/vpn/gnunet-vpn-packet.h  2010-07-20 09:41:26 UTC (rev 12271)
@@ -1,6 +1,9 @@
 #ifndef _GNTUN_PACKET_H_
 #define _GNTUN_PACKET_H_
 
+#include "gnunet-vpn-helper-p.h"
+
+// Headers
 struct pkt_tun {
        unsigned flags:16;
        unsigned type:16;
@@ -28,7 +31,6 @@
        unsigned wsz:16;
        unsigned crc:16;
        unsigned urg:16;
-       unsigned char data[1];
 };
 
 struct udp_pkt {
@@ -38,6 +40,7 @@
        unsigned crc:16;
 };
 
+// DNS-Stuff
 struct dns_pkt {
        unsigned short id;
 
@@ -78,37 +81,36 @@
        unsigned char* data;
 };
 
+// Complete Packets
 struct ip6_pkt {
+       struct suid_packet_header shdr;
        struct pkt_tun tun;
-       struct ip6_hdr hdr;
+       struct ip6_hdr ip6_hdr;
        unsigned char data[1];
 };
 
 struct ip6_tcp {
+       struct suid_packet_header shdr;
        struct pkt_tun tun;
-       struct ip6_hdr hdr;
-       struct tcp_pkt data;
+       struct ip6_hdr ip6_hdr;
+       struct tcp_pkt tcp_hdr;
+       unsigned char data[1];
 };
 
 struct ip6_udp {
+       struct suid_packet_header shdr;
        struct pkt_tun tun;
-       struct ip6_hdr hdr;
-       struct udp_pkt data;
+       struct ip6_hdr ip6_hdr;
+       struct udp_pkt udp_hdr;
+       unsigned char data[1];
 };
 
-void send_pkt(int fd, struct ip6_pkt* pkt);
-int recv_ipv6pkt(int fd, struct pkt_tun** pkt);
-int recv_pkt(int fd, struct pkt_tun** pkt);
-struct ip6_pkt* parse_ip6(struct pkt_tun* pkt);
-
 struct ip6_udp_dns {
-       struct ip6_udp hdr;
+       struct suid_packet_header shdr;
+       struct pkt_tun tun;
+       struct ip6_hdr ip6_hdr;
+       struct udp_pkt udp_hdr;
        struct dns_pkt data;
 };
 
-struct ip6_tcp* parse_ip6_tcp(struct ip6_pkt*);
-struct ip6_udp* parse_ip6_udp(struct ip6_pkt*);
-
-short payload(struct ip6_hdr* pkt);
-
 #endif

Modified: gnunet/src/vpn/gnunet-vpn-pretty-print.c
===================================================================
--- gnunet/src/vpn/gnunet-vpn-pretty-print.c    2010-07-20 09:33:32 UTC (rev 
12270)
+++ gnunet/src/vpn/gnunet-vpn-pretty-print.c    2010-07-20 09:41:26 UTC (rev 
12271)
@@ -4,7 +4,7 @@
 #include <ctype.h>
 #include <arpa/inet.h>
 
-#include "packet.h"
+#include "gnunet-vpn-packet.h"
 
 static char* pretty = /*{{{*/
 /*     0       1         2         3         4        5          6
@@ -92,7 +92,7 @@
 }}}
 
 void pp_write_header(char* dest, struct ip6_pkt* pkt) {{{
-       switch (pkt->hdr.nxthdr) {
+       switch (pkt->ip6_hdr.nxthdr) {
                case 0x3a:
                        memcpy(dest, "ICMPv6)", 7);
                        break;
@@ -114,32 +114,32 @@
 
        memcpy(buf, pretty, strlen(pretty)+1);
 
-       pp_ip6adr(pkt->hdr.sadr, buf+16);
-       pp_ip6adr(pkt->hdr.dadr, buf+76);
+       pp_ip6adr(pkt->ip6_hdr.sadr, buf+16);
+       pp_ip6adr(pkt->ip6_hdr.dadr, buf+76);
 
-       int flow = (ntohl(pkt->hdr.flowlbl));
+       int flow = (ntohl(pkt->ip6_hdr.flowlbl));
        sprintf(tmp, "%03x", flow);
        memcpy(buf+138, tmp, 3);
        sprintf(tmp, "%-8d", flow);
        memcpy(buf+143, tmp, 8);
 
-       int length = ntohs(pkt->hdr.paylgth);
+       int length = ntohs(pkt->ip6_hdr.paylgth);
        sprintf(tmp, "%02x", length);
        memcpy(buf+198, tmp, 2);
        sprintf(tmp, "%-3d", length);
        memcpy(buf+203, tmp, 3);
 
-       sprintf(tmp, "%02x", pkt->hdr.nxthdr);
+       sprintf(tmp, "%02x", pkt->ip6_hdr.nxthdr);
        memcpy(buf+258, tmp, 2);
        pp_write_header(buf+263, pkt);
 
-       sprintf(tmp, "%02x", pkt->hdr.hoplmt);
+       sprintf(tmp, "%02x", pkt->ip6_hdr.hoplmt);
        memcpy(buf+318, tmp, 2);
-       sprintf(tmp, "%-3d", pkt->hdr.hoplmt);
+       sprintf(tmp, "%-3d", pkt->ip6_hdr.hoplmt);
        memcpy(buf+323, tmp, 3);
 
-       int size = payload(&pkt->hdr);
-        int i;
+       int size = ntohs(pkt->ip6_hdr.paylgth);
+       int i;
        for(i = 0; i < 8; i++) {
                if (16*i > size) break;
                pp_hexdump(pkt->data + (16*i), buf + 420 + (i*70), size - 16*i);
@@ -150,31 +150,31 @@
 }}}
 
 void pkt_printf_ip6tcp(struct ip6_tcp* pkt) {{{
-       printf("spt: %u\n", ntohs(pkt->data.spt));
-       printf("dpt: %u\n", ntohs(pkt->data.dpt));
-       printf("seq: %u\n", ntohs(pkt->data.seq));
-       printf("ack: %u\n", ntohs(pkt->data.ack));
-       printf("off: %u\n", ntohs(pkt->data.off));
-       printf("wsz: %u\n", ntohs(pkt->data.wsz));
-       printf("crc: 0x%x\n", ntohs(pkt->data.crc));
-       printf("urg: %u\n", ntohs(pkt->data.urg));
+       printf("spt: %u\n", ntohs(pkt->tcp_hdr.spt));
+       printf("dpt: %u\n", ntohs(pkt->tcp_hdr.dpt));
+       printf("seq: %u\n", ntohs(pkt->tcp_hdr.seq));
+       printf("ack: %u\n", ntohs(pkt->tcp_hdr.ack));
+       printf("off: %u\n", ntohs(pkt->tcp_hdr.off));
+       printf("wsz: %u\n", ntohs(pkt->tcp_hdr.wsz));
+       printf("crc: 0x%x\n", ntohs(pkt->tcp_hdr.crc));
+       printf("urg: %u\n", ntohs(pkt->tcp_hdr.urg));
        printf("flags: %c%c%c%c%c%c%c%c\n",
-                       pkt->data.flg & 0x80 ? 'C' : '.',
-                       pkt->data.flg & 0x40 ? 'E' : '.',
-                       pkt->data.flg & 0x20 ? 'U' : '.',
-                       pkt->data.flg & 0x10 ? 'A' : '.',
-                       pkt->data.flg & 0x08 ? 'P' : '.',
-                       pkt->data.flg & 0x04 ? 'R' : '.',
-                       pkt->data.flg & 0x02 ? 'S' : '.',
-                       pkt->data.flg & 0x01 ? 'F' : '.'
+                       pkt->tcp_hdr.flg & 0x80 ? 'C' : '.',
+                       pkt->tcp_hdr.flg & 0x40 ? 'E' : '.',
+                       pkt->tcp_hdr.flg & 0x20 ? 'U' : '.',
+                       pkt->tcp_hdr.flg & 0x10 ? 'A' : '.',
+                       pkt->tcp_hdr.flg & 0x08 ? 'P' : '.',
+                       pkt->tcp_hdr.flg & 0x04 ? 'R' : '.',
+                       pkt->tcp_hdr.flg & 0x02 ? 'S' : '.',
+                       pkt->tcp_hdr.flg & 0x01 ? 'F' : '.'
                        );
 }}}
 
 void pkt_printf_ip6udp(struct ip6_udp* pkt) {{{
-       printf("spt: %u\n", ntohs(pkt->data.spt));
-       printf("dpt: %u\n", ntohs(pkt->data.dpt));
-       printf("len: %u\n", ntohs(pkt->data.len));
-       printf("crc: 0x%x\n", ntohs(pkt->data.crc));
+       printf("spt: %u\n", ntohs(pkt->udp_hdr.spt));
+       printf("dpt: %u\n", ntohs(pkt->udp_hdr.dpt));
+       printf("len: %u\n", ntohs(pkt->udp_hdr.len));
+       printf("crc: 0x%x\n", ntohs(pkt->udp_hdr.crc));
 }}}
 
 static char* dns_types(unsigned short type) {{{




reply via email to

[Prev in Thread] Current Thread [Next in Thread]