diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/vpn/Makefile.am | 6 | ||||
-rw-r--r-- | src/vpn/gnunet-dns-parser.c | 25 | ||||
-rw-r--r-- | src/vpn/gnunet-dns-parser.h | 10 | ||||
-rw-r--r-- | src/vpn/gnunet-vpn-pretty-print.c | 25 |
4 files changed, 41 insertions, 25 deletions
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am index ca8f6c1af..5bfa29600 100644 --- a/src/vpn/Makefile.am +++ b/src/vpn/Makefile.am | |||
@@ -35,7 +35,8 @@ gnunet_helper_hijack_dns_SOURCES = \ | |||
35 | 35 | ||
36 | gnunet_daemon_vpn_SOURCES = \ | 36 | gnunet_daemon_vpn_SOURCES = \ |
37 | gnunet-daemon-vpn.c \ | 37 | gnunet-daemon-vpn.c \ |
38 | gnunet-vpn-pretty-print.c | 38 | gnunet-vpn-pretty-print.c \ |
39 | gnunet-dns-parser.c | ||
39 | gnunet_daemon_vpn_LDADD = \ | 40 | gnunet_daemon_vpn_LDADD = \ |
40 | $(top_builddir)/src/core/libgnunetcore.la \ | 41 | $(top_builddir)/src/core/libgnunetcore.la \ |
41 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 42 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
@@ -44,7 +45,8 @@ gnunet_daemon_vpn_LDADD = \ | |||
44 | 45 | ||
45 | gnunet_service_dns_SOURCES = \ | 46 | gnunet_service_dns_SOURCES = \ |
46 | gnunet-service-dns.c \ | 47 | gnunet-service-dns.c \ |
47 | gnunet-vpn-pretty-print.c | 48 | gnunet-vpn-pretty-print.c \ |
49 | gnunet-dns-parser.c | ||
48 | gnunet_service_dns_LDADD = \ | 50 | gnunet_service_dns_LDADD = \ |
49 | $(top_builddir)/src/core/libgnunetcore.la \ | 51 | $(top_builddir)/src/core/libgnunetcore.la \ |
50 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 52 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
diff --git a/src/vpn/gnunet-dns-parser.c b/src/vpn/gnunet-dns-parser.c new file mode 100644 index 000000000..3425e78f6 --- /dev/null +++ b/src/vpn/gnunet-dns-parser.c | |||
@@ -0,0 +1,25 @@ | |||
1 | #include "platform.h" | ||
2 | #include "gnunet-dns-parser.h" | ||
3 | |||
4 | unsigned int parse_dns_name(unsigned char* d, const unsigned char* src, unsigned short idx) {/*{{{*/ | ||
5 | unsigned char* dest = d; | ||
6 | |||
7 | int len = src[idx++]; | ||
8 | while (len != 0) { | ||
9 | if (len & 0xC0) { /* Compressed name, offset in this and the next octet */ | ||
10 | unsigned short offset = ((len & 0x3F) << 8) | src[idx++]; | ||
11 | parse_dns_name(dest, src, offset - 12); /* 12 for the Header of the DNS-Packet, idx starts at 0 which is 12 bytes from the start of the packet */ | ||
12 | return idx; | ||
13 | } | ||
14 | memcpy(dest, src+idx, len); | ||
15 | idx += len; | ||
16 | dest += len; | ||
17 | *dest = '.'; | ||
18 | dest++; | ||
19 | len = src[idx++]; | ||
20 | }; | ||
21 | *dest = 0; | ||
22 | |||
23 | return idx; | ||
24 | } | ||
25 | /*}}}*/ | ||
diff --git a/src/vpn/gnunet-dns-parser.h b/src/vpn/gnunet-dns-parser.h new file mode 100644 index 000000000..77dcd6d4e --- /dev/null +++ b/src/vpn/gnunet-dns-parser.h | |||
@@ -0,0 +1,10 @@ | |||
1 | #ifndef _GNVPN_DNSP_H_ | ||
2 | #define _GNVPN_DNSP_H_ | ||
3 | |||
4 | /** | ||
5 | * Parses the dns-name pointed to by src+idx returning idx so, that src+idx points | ||
6 | * to the first unused char. | ||
7 | */ | ||
8 | unsigned int parse_dns_name(unsigned char* dest, const unsigned char* src, unsigned short idx); | ||
9 | |||
10 | #endif | ||
diff --git a/src/vpn/gnunet-vpn-pretty-print.c b/src/vpn/gnunet-vpn-pretty-print.c index 01427fe95..f620e84fa 100644 --- a/src/vpn/gnunet-vpn-pretty-print.c +++ b/src/vpn/gnunet-vpn-pretty-print.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #endif | 9 | #endif |
10 | 10 | ||
11 | #include "gnunet-vpn-packet.h" | 11 | #include "gnunet-vpn-packet.h" |
12 | #include "gnunet-dns-parser.h" | ||
12 | 13 | ||
13 | static char* pretty = /*{{{*/ | 14 | static char* pretty = /*{{{*/ |
14 | /* 0 1 2 3 4 5 6 | 15 | /* 0 1 2 3 4 5 6 |
@@ -245,7 +246,7 @@ static char* dns_types(unsigned short type) {{{ | |||
245 | 246 | ||
246 | }}} | 247 | }}} |
247 | 248 | ||
248 | static char* dns_classes(short class) {{{ | 249 | static char* dns_classes(short class) { /* {{{ */ |
249 | static char* classes[] = { /*{{{*/ | 250 | static char* classes[] = { /*{{{*/ |
250 | "", | 251 | "", |
251 | "IN", // 1 the Internet | 252 | "IN", // 1 the Internet |
@@ -256,28 +257,6 @@ static char* dns_classes(short class) {{{ | |||
256 | 257 | ||
257 | if (class <= 4) return classes[class]; | 258 | if (class <= 4) return classes[class]; |
258 | return 0; | 259 | return 0; |
259 | }}} | ||
260 | |||
261 | unsigned int parse_dns_name(unsigned char* d, const unsigned char* src, unsigned short idx) {/*{{{*/ | ||
262 | unsigned char* dest = d; | ||
263 | |||
264 | int len = src[idx++]; | ||
265 | while (len != 0) { | ||
266 | if (len & 0xC0) { /* Compressed name, offset in this and the next octet */ | ||
267 | unsigned short offset = ((len & 0x3F) << 8) | src[idx++]; | ||
268 | parse_dns_name(dest, src, offset - 12); /* 12 for the Header of the DNS-Packet, idx starts at 0 which is 12 bytes from the start of the packet */ | ||
269 | return idx; | ||
270 | } | ||
271 | memcpy(dest, src+idx, len); | ||
272 | idx += len; | ||
273 | dest += len; | ||
274 | *dest = '.'; | ||
275 | dest++; | ||
276 | len = src[idx++]; | ||
277 | }; | ||
278 | *dest = 0; | ||
279 | |||
280 | return idx; | ||
281 | } | 260 | } |
282 | /*}}}*/ | 261 | /*}}}*/ |
283 | 262 | ||