pull a function I will need for service-dns out of pretty-print
[oweals/gnunet.git] / src / vpn / gnunet-dns-parser.c
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 /*}}}*/