Date: Mon, 16 Jul 2007 01:28:20 GMT From: Fredrik Lindberg <fli@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 123572 for review Message-ID: <200707160128.l6G1SKkA091411@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123572 Change 123572 by fli@fli_nexus on 2007/07/16 01:27:33 - Fix encoding of IPv6 addresses - Style fixes (long lines). Affected files ... .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_util.c#3 edit Differences ... ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_util.c#3 (text+ko) ==== @@ -30,6 +30,7 @@ #include <netinet/in.h> #include <arpa/inet.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -127,6 +128,7 @@ else { if (flags & MDNS_ENC_WCHAR) { wcstombs(addr, data, INET6_ADDRSTRLEN+1); + p = addr; } r = malloc(16); /* ipv6 address */ inet_pton(AF_INET6, p, r); @@ -150,6 +152,49 @@ return (found); } +/* Create a ip6.arpa ptr record */ +static char * +ip6ptr(char *p) +{ + char *q, *s, *r; + int cnt, cols; + + cols = stroc(p, ':'); + if (cols < 2) + return (NULL); + + /* + * 74 bytes is enough to hold a ip6.arpa domain pointer + * including terminating '\0'. + */ + r = s = malloc(74); + q = p + strlen(p) - 1; + cnt = 0; + while (q >= p) { + if (s - r == 64) + break; + *s++ = *q--; + *s++ = '.'; + cnt++; + if (*q == ':') { + for (; cnt < 4; cnt++) { + *s++ = '0'; *s++ = '.'; + } + if (q != p && *(q - 1) == ':') { + while (cols++ <= 7) { + for (cnt = 0; cnt < 4; cnt++) { + *s++ = '0'; *s++ = '.'; + } + } + q--; + } + cnt = 0; + q--; + } + } + strcpy(s, "ip6.arpa."); + return (r); +} /* * (IN, PTR) resource data encoder @@ -194,48 +239,13 @@ q = strdup(p); for (i = 0; i < 4; i++) parts[i] = strsep(&p, "."); - asprintf(&r, "%s.%s.%s.%s.in-addr.arpa.", parts[3], parts[2], - parts[1], parts[0]); + asprintf(&r, "%s.%s.%s.%s.in-addr.arpa.", + parts[3], parts[2], parts[1], parts[0]); free(q); } #ifdef INET6 else if (flags & MDNS_ENC_INET6) { - char *q, *s; - int cnt, cols; - - cols = stroc(p, ':'); - if (cols < 2) - return (NULL); - /* - * 74 bytes is enough to hold a ip6.arpa domain pointer - * including terminating '\0'. - */ - r = s = malloc(74); - q = p + strlen(p) - 1; - cnt = 0; - while (q >= p) { - if (s - r == 64) - break; - *s++ = *q--; - *s++ = '.'; - cnt++; - if (*q == ':') { - for (; cnt < 4; cnt++) { - *s++ = '0'; *s++ = '.'; - } - if (q != p && *(q - 1) == ':') { - while (cols++ <= 7) { - for (cnt = 0; cnt < 4; cnt++) { - *s++ = '0'; *s++ = '.'; - } - } - q--; - } - cnt = 0; - q--; - } - } - strcpy(s, "ip6.arpa."); + r = ip6ptr(p); } #endif } @@ -310,7 +320,8 @@ for (i = 0; i < res_enc_table_size; i++) { if (res_enc_table[i].em_type == type) { - res = res_enc_table[i].em_encoder(data, flags, dlen, rlen); + res = res_enc_table[i].em_encoder(data, flags, dlen, + rlen); break; } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707160128.l6G1SKkA091411>