diff -aur bind-to-tinydns-0.4.3/bind-to-tinydns.c bind-to-tinydns-0.4.3-v6/bind-to-tinydns.c --- bind-to-tinydns-0.4.3/bind-to-tinydns.c 2005-08-17 17:49:47.000000000 +0200 +++ bind-to-tinydns-0.4.3-v6/bind-to-tinydns.c 2010-01-09 17:58:02.000000000 +0100 @@ -10,6 +10,9 @@ #include #include #include +#include +#include +#include #define LINE_LEN 8192 #define DOMAIN_LEN 255 @@ -350,6 +353,22 @@ return 0; } + +/* sanitize_ip6: takes a formatted ipv6 address in src and turns it + * into a ipv6 address formattet correctly for djbcns. dest must be 33 + * characters (or more). */ +int sanitize_ip6 (char *dest, const char *src) { + + uint8_t tmp[sizeof(struct in6_addr)]; + + if (!src) return 1; + if (!inet_pton(AF_INET6, src, &tmp)) return 1; + sprintf(dest, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7], + tmp[8], tmp[9], tmp[10], tmp[11], tmp[12], tmp[13], tmp[14], tmp[15]); + return 0; +} + /* tokenize: tokenizes a line from stdin. puts the tokens into the token * array and returns the number of tokens found, or -1 if the end of the * file was reached. */ @@ -853,6 +872,17 @@ start_line_num); fprintf (file, "+%s:%s:%d\n", owner.text, ip, local_ttl); + /* AAAA */ + } else if (!strcasecmp (token[next], "AAAA")) { + char ip[33]; + if (num_tokens - next - 1 != 1) + fatal ("wrong number of tokens in AAAA RDATA", + start_line_num); + if (sanitize_ip6 (ip, token[next+1])) + fatal ("invalid IP address in AAAA RDATA", + start_line_num); + fprintf (file, "3%s:%s:%d\n", owner.text, + ip, local_ttl); /* CNAME */ } else if (!strcasecmp (token[next], "CNAME")) { if (num_tokens - next - 1 != 1)