pull a function I will need for service-dns out of pretty-print
authorPhilipp Tölke <toelke@in.tum.de>
Tue, 5 Oct 2010 18:20:17 +0000 (18:20 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Tue, 5 Oct 2010 18:20:17 +0000 (18:20 +0000)
src/vpn/Makefile.am
src/vpn/gnunet-dns-parser.c [new file with mode: 0644]
src/vpn/gnunet-dns-parser.h [new file with mode: 0644]
src/vpn/gnunet-vpn-pretty-print.c

index ca8f6c1af765822b5a0125a03feecd5192ab61d6..5bfa296008ad78afc60bba0cc6843fee6114d131 100644 (file)
@@ -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 (file)
index 0000000..3425e78
--- /dev/null
@@ -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 (file)
index 0000000..77dcd6d
--- /dev/null
@@ -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
index 01427fe95138b8371182565db7ff845036fd7470..f620e84fa82771ee3c22b3d6b1f14b568fcb9d2b 100644 (file)
@@ -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;
 }
 /*}}}*/