From 1ec9a4ce4e00da8e877d6af343b7fed346765392 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Tue, 5 Oct 2010 18:20:17 +0000 Subject: [PATCH] pull a function I will need for service-dns out of pretty-print --- src/vpn/Makefile.am | 6 ++++-- src/vpn/gnunet-dns-parser.c | 25 +++++++++++++++++++++++++ src/vpn/gnunet-dns-parser.h | 10 ++++++++++ src/vpn/gnunet-vpn-pretty-print.c | 25 ++----------------------- 4 files changed, 41 insertions(+), 25 deletions(-) create mode 100644 src/vpn/gnunet-dns-parser.c create mode 100644 src/vpn/gnunet-dns-parser.h 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 = \ gnunet_daemon_vpn_SOURCES = \ gnunet-daemon-vpn.c \ - gnunet-vpn-pretty-print.c + gnunet-vpn-pretty-print.c \ + gnunet-dns-parser.c gnunet_daemon_vpn_LDADD = \ $(top_builddir)/src/core/libgnunetcore.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ @@ -44,7 +45,8 @@ gnunet_daemon_vpn_LDADD = \ gnunet_service_dns_SOURCES = \ gnunet-service-dns.c \ - gnunet-vpn-pretty-print.c + gnunet-vpn-pretty-print.c \ + gnunet-dns-parser.c gnunet_service_dns_LDADD = \ $(top_builddir)/src/core/libgnunetcore.la \ $(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 @@ +#include "platform.h" +#include "gnunet-dns-parser.h" + +unsigned int parse_dns_name(unsigned char* d, const unsigned char* src, unsigned short idx) {/*{{{*/ + unsigned char* dest = d; + + int len = src[idx++]; + while (len != 0) { + if (len & 0xC0) { /* Compressed name, offset in this and the next octet */ + unsigned short offset = ((len & 0x3F) << 8) | src[idx++]; + 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 */ + return idx; + } + memcpy(dest, src+idx, len); + idx += len; + dest += len; + *dest = '.'; + dest++; + len = src[idx++]; + }; + *dest = 0; + + return idx; +} +/*}}}*/ 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 @@ +#ifndef _GNVPN_DNSP_H_ +#define _GNVPN_DNSP_H_ + +/** + * Parses the dns-name pointed to by src+idx returning idx so, that src+idx points + * to the first unused char. + */ +unsigned int parse_dns_name(unsigned char* dest, const unsigned char* src, unsigned short idx); + +#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 @@ #endif #include "gnunet-vpn-packet.h" +#include "gnunet-dns-parser.h" static char* pretty = /*{{{*/ /* 0 1 2 3 4 5 6 @@ -245,7 +246,7 @@ static char* dns_types(unsigned short type) {{{ }}} -static char* dns_classes(short class) {{{ +static char* dns_classes(short class) { /* {{{ */ static char* classes[] = { /*{{{*/ "", "IN", // 1 the Internet @@ -256,28 +257,6 @@ static char* dns_classes(short class) {{{ if (class <= 4) return classes[class]; return 0; -}}} - -unsigned int parse_dns_name(unsigned char* d, const unsigned char* src, unsigned short idx) {/*{{{*/ - unsigned char* dest = d; - - int len = src[idx++]; - while (len != 0) { - if (len & 0xC0) { /* Compressed name, offset in this and the next octet */ - unsigned short offset = ((len & 0x3F) << 8) | src[idx++]; - 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 */ - return idx; - } - memcpy(dest, src+idx, len); - idx += len; - dest += len; - *dest = '.'; - dest++; - len = src[idx++]; - }; - *dest = 0; - - return idx; } /*}}}*/ -- 2.25.1