diff options
author | Philipp Tölke <toelke@in.tum.de> | 2010-07-20 09:41:26 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2010-07-20 09:41:26 +0000 |
commit | 67576021d826e729e3ddf247e1c596e29608f0c8 (patch) | |
tree | 4bd88d62f9bef50bc432ed1f9f7d1d644cf6ad88 /src/vpn | |
parent | cf2b5b068fe12986ebe4c21a2ce1fa04f5881c55 (diff) | |
download | gnunet-67576021d826e729e3ddf247e1c596e29608f0c8.tar.gz gnunet-67576021d826e729e3ddf247e1c596e29608f0c8.zip |
Pretty-Print Packets from the helper
Diffstat (limited to 'src/vpn')
-rw-r--r-- | src/vpn/gnunet-daemon-vpn.c | 27 | ||||
-rw-r--r-- | src/vpn/gnunet-vpn-packet.h | 36 | ||||
-rw-r--r-- | src/vpn/gnunet-vpn-pretty-print.c | 62 |
3 files changed, 70 insertions, 55 deletions
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 5cc832127..e9e944ca8 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c | |||
@@ -28,6 +28,8 @@ | |||
28 | #include "gnunet_program_lib.h" | 28 | #include "gnunet_program_lib.h" |
29 | #include "gnunet_os_lib.h" | 29 | #include "gnunet_os_lib.h" |
30 | #include "gnunet-vpn-helper-p.h" | 30 | #include "gnunet-vpn-helper-p.h" |
31 | #include "gnunet-vpn-packet.h" | ||
32 | #include "gnunet-vpn-pretty-print.h" | ||
31 | /* #include "gnunet_template_service.h" */ | 33 | /* #include "gnunet_template_service.h" */ |
32 | 34 | ||
33 | /** | 35 | /** |
@@ -71,8 +73,6 @@ static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* ts | |||
71 | r += t; | 73 | r += t; |
72 | } | 74 | } |
73 | 75 | ||
74 | fprintf(stderr, "Read %d bytes for the header. The 'size' is %x, that is %d\n", r, hdr.size, ntohl(hdr.size)); | ||
75 | |||
76 | struct suid_packet *pkt = (struct suid_packet*) GNUNET_malloc(ntohl(hdr.size)); | 76 | struct suid_packet *pkt = (struct suid_packet*) GNUNET_malloc(ntohl(hdr.size)); |
77 | 77 | ||
78 | if (memcpy(pkt, &hdr, sizeof(struct suid_packet_header)) < 0) { | 78 | if (memcpy(pkt, &hdr, sizeof(struct suid_packet_header)) < 0) { |
@@ -89,11 +89,24 @@ static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* ts | |||
89 | r += t; | 89 | r += t; |
90 | } | 90 | } |
91 | 91 | ||
92 | printf("read %d bytes. The first 87 are:\n\t", r); | 92 | struct ip6_pkt *pkt6 = (struct ip6_pkt*) pkt; |
93 | 93 | struct ip6_tcp *pkt6_tcp; | |
94 | for (r = 0; r < 87; r++) | 94 | struct ip6_udp *pkt6_udp; |
95 | printf("%02x ", pkt->data[r]); | 95 | |
96 | printf("\n"); | 96 | pkt_printf(pkt6); |
97 | switch(pkt6->ip6_hdr.nxthdr) { | ||
98 | case 0x06: | ||
99 | pkt6_tcp = (struct ip6_tcp*)pkt6; | ||
100 | pkt_printf_ip6tcp(pkt6_tcp); | ||
101 | break; | ||
102 | case 0x11: | ||
103 | pkt6_udp = (struct ip6_udp*)pkt6; | ||
104 | pkt_printf_ip6udp(pkt6_udp); | ||
105 | if (ntohs(pkt6_udp->udp_hdr.dpt) == 53) { | ||
106 | pkt_printf_ip6dns((struct ip6_udp_dns*)pkt6_udp); | ||
107 | } | ||
108 | break; | ||
109 | } | ||
97 | 110 | ||
98 | GNUNET_free(pkt); | 111 | GNUNET_free(pkt); |
99 | 112 | ||
diff --git a/src/vpn/gnunet-vpn-packet.h b/src/vpn/gnunet-vpn-packet.h index c19e7a101..89b75ba35 100644 --- a/src/vpn/gnunet-vpn-packet.h +++ b/src/vpn/gnunet-vpn-packet.h | |||
@@ -1,6 +1,9 @@ | |||
1 | #ifndef _GNTUN_PACKET_H_ | 1 | #ifndef _GNTUN_PACKET_H_ |
2 | #define _GNTUN_PACKET_H_ | 2 | #define _GNTUN_PACKET_H_ |
3 | 3 | ||
4 | #include "gnunet-vpn-helper-p.h" | ||
5 | |||
6 | // Headers | ||
4 | struct pkt_tun { | 7 | struct pkt_tun { |
5 | unsigned flags:16; | 8 | unsigned flags:16; |
6 | unsigned type:16; | 9 | unsigned type:16; |
@@ -28,7 +31,6 @@ struct tcp_pkt { | |||
28 | unsigned wsz:16; | 31 | unsigned wsz:16; |
29 | unsigned crc:16; | 32 | unsigned crc:16; |
30 | unsigned urg:16; | 33 | unsigned urg:16; |
31 | unsigned char data[1]; | ||
32 | }; | 34 | }; |
33 | 35 | ||
34 | struct udp_pkt { | 36 | struct udp_pkt { |
@@ -38,6 +40,7 @@ struct udp_pkt { | |||
38 | unsigned crc:16; | 40 | unsigned crc:16; |
39 | }; | 41 | }; |
40 | 42 | ||
43 | // DNS-Stuff | ||
41 | struct dns_pkt { | 44 | struct dns_pkt { |
42 | unsigned short id; | 45 | unsigned short id; |
43 | 46 | ||
@@ -78,37 +81,36 @@ struct dns_record { | |||
78 | unsigned char* data; | 81 | unsigned char* data; |
79 | }; | 82 | }; |
80 | 83 | ||
84 | // Complete Packets | ||
81 | struct ip6_pkt { | 85 | struct ip6_pkt { |
86 | struct suid_packet_header shdr; | ||
82 | struct pkt_tun tun; | 87 | struct pkt_tun tun; |
83 | struct ip6_hdr hdr; | 88 | struct ip6_hdr ip6_hdr; |
84 | unsigned char data[1]; | 89 | unsigned char data[1]; |
85 | }; | 90 | }; |
86 | 91 | ||
87 | struct ip6_tcp { | 92 | struct ip6_tcp { |
93 | struct suid_packet_header shdr; | ||
88 | struct pkt_tun tun; | 94 | struct pkt_tun tun; |
89 | struct ip6_hdr hdr; | 95 | struct ip6_hdr ip6_hdr; |
90 | struct tcp_pkt data; | 96 | struct tcp_pkt tcp_hdr; |
97 | unsigned char data[1]; | ||
91 | }; | 98 | }; |
92 | 99 | ||
93 | struct ip6_udp { | 100 | struct ip6_udp { |
101 | struct suid_packet_header shdr; | ||
94 | struct pkt_tun tun; | 102 | struct pkt_tun tun; |
95 | struct ip6_hdr hdr; | 103 | struct ip6_hdr ip6_hdr; |
96 | struct udp_pkt data; | 104 | struct udp_pkt udp_hdr; |
105 | unsigned char data[1]; | ||
97 | }; | 106 | }; |
98 | 107 | ||
99 | void send_pkt(int fd, struct ip6_pkt* pkt); | ||
100 | int recv_ipv6pkt(int fd, struct pkt_tun** pkt); | ||
101 | int recv_pkt(int fd, struct pkt_tun** pkt); | ||
102 | struct ip6_pkt* parse_ip6(struct pkt_tun* pkt); | ||
103 | |||
104 | struct ip6_udp_dns { | 108 | struct ip6_udp_dns { |
105 | struct ip6_udp hdr; | 109 | struct suid_packet_header shdr; |
110 | struct pkt_tun tun; | ||
111 | struct ip6_hdr ip6_hdr; | ||
112 | struct udp_pkt udp_hdr; | ||
106 | struct dns_pkt data; | 113 | struct dns_pkt data; |
107 | }; | 114 | }; |
108 | 115 | ||
109 | struct ip6_tcp* parse_ip6_tcp(struct ip6_pkt*); | ||
110 | struct ip6_udp* parse_ip6_udp(struct ip6_pkt*); | ||
111 | |||
112 | short payload(struct ip6_hdr* pkt); | ||
113 | |||
114 | #endif | 116 | #endif |
diff --git a/src/vpn/gnunet-vpn-pretty-print.c b/src/vpn/gnunet-vpn-pretty-print.c index 90bbe7bea..d7edf0a11 100644 --- a/src/vpn/gnunet-vpn-pretty-print.c +++ b/src/vpn/gnunet-vpn-pretty-print.c | |||
@@ -4,7 +4,7 @@ | |||
4 | #include <ctype.h> | 4 | #include <ctype.h> |
5 | #include <arpa/inet.h> | 5 | #include <arpa/inet.h> |
6 | 6 | ||
7 | #include "packet.h" | 7 | #include "gnunet-vpn-packet.h" |
8 | 8 | ||
9 | static char* pretty = /*{{{*/ | 9 | static char* pretty = /*{{{*/ |
10 | /* 0 1 2 3 4 5 6 | 10 | /* 0 1 2 3 4 5 6 |
@@ -92,7 +92,7 @@ void pp_hexdump(unsigned char* data, char* dest, int max) {{{ | |||
92 | }}} | 92 | }}} |
93 | 93 | ||
94 | void pp_write_header(char* dest, struct ip6_pkt* pkt) {{{ | 94 | void pp_write_header(char* dest, struct ip6_pkt* pkt) {{{ |
95 | switch (pkt->hdr.nxthdr) { | 95 | switch (pkt->ip6_hdr.nxthdr) { |
96 | case 0x3a: | 96 | case 0x3a: |
97 | memcpy(dest, "ICMPv6)", 7); | 97 | memcpy(dest, "ICMPv6)", 7); |
98 | break; | 98 | break; |
@@ -114,32 +114,32 @@ void pkt_printf(struct ip6_pkt* pkt) {{{ | |||
114 | 114 | ||
115 | memcpy(buf, pretty, strlen(pretty)+1); | 115 | memcpy(buf, pretty, strlen(pretty)+1); |
116 | 116 | ||
117 | pp_ip6adr(pkt->hdr.sadr, buf+16); | 117 | pp_ip6adr(pkt->ip6_hdr.sadr, buf+16); |
118 | pp_ip6adr(pkt->hdr.dadr, buf+76); | 118 | pp_ip6adr(pkt->ip6_hdr.dadr, buf+76); |
119 | 119 | ||
120 | int flow = (ntohl(pkt->hdr.flowlbl)); | 120 | int flow = (ntohl(pkt->ip6_hdr.flowlbl)); |
121 | sprintf(tmp, "%03x", flow); | 121 | sprintf(tmp, "%03x", flow); |
122 | memcpy(buf+138, tmp, 3); | 122 | memcpy(buf+138, tmp, 3); |
123 | sprintf(tmp, "%-8d", flow); | 123 | sprintf(tmp, "%-8d", flow); |
124 | memcpy(buf+143, tmp, 8); | 124 | memcpy(buf+143, tmp, 8); |
125 | 125 | ||
126 | int length = ntohs(pkt->hdr.paylgth); | 126 | int length = ntohs(pkt->ip6_hdr.paylgth); |
127 | sprintf(tmp, "%02x", length); | 127 | sprintf(tmp, "%02x", length); |
128 | memcpy(buf+198, tmp, 2); | 128 | memcpy(buf+198, tmp, 2); |
129 | sprintf(tmp, "%-3d", length); | 129 | sprintf(tmp, "%-3d", length); |
130 | memcpy(buf+203, tmp, 3); | 130 | memcpy(buf+203, tmp, 3); |
131 | 131 | ||
132 | sprintf(tmp, "%02x", pkt->hdr.nxthdr); | 132 | sprintf(tmp, "%02x", pkt->ip6_hdr.nxthdr); |
133 | memcpy(buf+258, tmp, 2); | 133 | memcpy(buf+258, tmp, 2); |
134 | pp_write_header(buf+263, pkt); | 134 | pp_write_header(buf+263, pkt); |
135 | 135 | ||
136 | sprintf(tmp, "%02x", pkt->hdr.hoplmt); | 136 | sprintf(tmp, "%02x", pkt->ip6_hdr.hoplmt); |
137 | memcpy(buf+318, tmp, 2); | 137 | memcpy(buf+318, tmp, 2); |
138 | sprintf(tmp, "%-3d", pkt->hdr.hoplmt); | 138 | sprintf(tmp, "%-3d", pkt->ip6_hdr.hoplmt); |
139 | memcpy(buf+323, tmp, 3); | 139 | memcpy(buf+323, tmp, 3); |
140 | 140 | ||
141 | int size = payload(&pkt->hdr); | 141 | int size = ntohs(pkt->ip6_hdr.paylgth); |
142 | int i; | 142 | int i; |
143 | for(i = 0; i < 8; i++) { | 143 | for(i = 0; i < 8; i++) { |
144 | if (16*i > size) break; | 144 | if (16*i > size) break; |
145 | pp_hexdump(pkt->data + (16*i), buf + 420 + (i*70), size - 16*i); | 145 | pp_hexdump(pkt->data + (16*i), buf + 420 + (i*70), size - 16*i); |
@@ -150,31 +150,31 @@ void pkt_printf(struct ip6_pkt* pkt) {{{ | |||
150 | }}} | 150 | }}} |
151 | 151 | ||
152 | void pkt_printf_ip6tcp(struct ip6_tcp* pkt) {{{ | 152 | void pkt_printf_ip6tcp(struct ip6_tcp* pkt) {{{ |
153 | printf("spt: %u\n", ntohs(pkt->data.spt)); | 153 | printf("spt: %u\n", ntohs(pkt->tcp_hdr.spt)); |
154 | printf("dpt: %u\n", ntohs(pkt->data.dpt)); | 154 | printf("dpt: %u\n", ntohs(pkt->tcp_hdr.dpt)); |
155 | printf("seq: %u\n", ntohs(pkt->data.seq)); | 155 | printf("seq: %u\n", ntohs(pkt->tcp_hdr.seq)); |
156 | printf("ack: %u\n", ntohs(pkt->data.ack)); | 156 | printf("ack: %u\n", ntohs(pkt->tcp_hdr.ack)); |
157 | printf("off: %u\n", ntohs(pkt->data.off)); | 157 | printf("off: %u\n", ntohs(pkt->tcp_hdr.off)); |
158 | printf("wsz: %u\n", ntohs(pkt->data.wsz)); | 158 | printf("wsz: %u\n", ntohs(pkt->tcp_hdr.wsz)); |
159 | printf("crc: 0x%x\n", ntohs(pkt->data.crc)); | 159 | printf("crc: 0x%x\n", ntohs(pkt->tcp_hdr.crc)); |
160 | printf("urg: %u\n", ntohs(pkt->data.urg)); | 160 | printf("urg: %u\n", ntohs(pkt->tcp_hdr.urg)); |
161 | printf("flags: %c%c%c%c%c%c%c%c\n", | 161 | printf("flags: %c%c%c%c%c%c%c%c\n", |
162 | pkt->data.flg & 0x80 ? 'C' : '.', | 162 | pkt->tcp_hdr.flg & 0x80 ? 'C' : '.', |
163 | pkt->data.flg & 0x40 ? 'E' : '.', | 163 | pkt->tcp_hdr.flg & 0x40 ? 'E' : '.', |
164 | pkt->data.flg & 0x20 ? 'U' : '.', | 164 | pkt->tcp_hdr.flg & 0x20 ? 'U' : '.', |
165 | pkt->data.flg & 0x10 ? 'A' : '.', | 165 | pkt->tcp_hdr.flg & 0x10 ? 'A' : '.', |
166 | pkt->data.flg & 0x08 ? 'P' : '.', | 166 | pkt->tcp_hdr.flg & 0x08 ? 'P' : '.', |
167 | pkt->data.flg & 0x04 ? 'R' : '.', | 167 | pkt->tcp_hdr.flg & 0x04 ? 'R' : '.', |
168 | pkt->data.flg & 0x02 ? 'S' : '.', | 168 | pkt->tcp_hdr.flg & 0x02 ? 'S' : '.', |
169 | pkt->data.flg & 0x01 ? 'F' : '.' | 169 | pkt->tcp_hdr.flg & 0x01 ? 'F' : '.' |
170 | ); | 170 | ); |
171 | }}} | 171 | }}} |
172 | 172 | ||
173 | void pkt_printf_ip6udp(struct ip6_udp* pkt) {{{ | 173 | void pkt_printf_ip6udp(struct ip6_udp* pkt) {{{ |
174 | printf("spt: %u\n", ntohs(pkt->data.spt)); | 174 | printf("spt: %u\n", ntohs(pkt->udp_hdr.spt)); |
175 | printf("dpt: %u\n", ntohs(pkt->data.dpt)); | 175 | printf("dpt: %u\n", ntohs(pkt->udp_hdr.dpt)); |
176 | printf("len: %u\n", ntohs(pkt->data.len)); | 176 | printf("len: %u\n", ntohs(pkt->udp_hdr.len)); |
177 | printf("crc: 0x%x\n", ntohs(pkt->data.crc)); | 177 | printf("crc: 0x%x\n", ntohs(pkt->udp_hdr.crc)); |
178 | }}} | 178 | }}} |
179 | 179 | ||
180 | static char* dns_types(unsigned short type) {{{ | 180 | static char* dns_types(unsigned short type) {{{ |