libresolv TXT RR Strangeness

Kevin Darcy kcd at daimlerchrysler.com
Mon Jul 15 19:20:31 UTC 2002


matthew at blackholes.us wrote:

> Hello,
>
> I'm writing a simple application part of which needs to retrieve TXT
> records. Documentation for libresolv is lacking, at best.
>
> RFC 1035 3.3.14 says the TXT RR doesn't have a first byte length, but
> it appears that my libresolv (built into libc on FreeBSD 4.4-REL)
> returns one.
>
> My question is: is this behavior consistent on other platforms?
>
> #include <stdlib.h>
> #include <sys/types.h>
> #include <netinet/in.h>
> #include <arpa/nameser.h>
> #include <resolv.h>
>
> int main(int argc, char *argv[])
> {
>   int result;
>   ns_rr rr;
>   u_char packet[NS_PACKETSZ];
>   ns_msg handle;
>   u_char txt[1024];
>
>   res_init();
>
>   result = res_query("2.0.0.127.china.blackholes.us.",
>                      ns_c_in,ns_t_txt,
>                      packet,sizeof(packet));
>   if (result == -1) {
>     return 1;
>   }
>
>   result = ns_initparse(packet,result,&handle);
>   result = ns_parserr(&handle,ns_s_an,0,&rr);
>   /*
>    * the first byte of ns_rr_rdata(rr) appears to be a
>    * length byte, but RFC 1035 3.3.14 doesn't specify that.
>    */
>   strlcpy(txt,ns_rr_rdata(rr)+1,ns_rr_rdlen(rr));
>   printf("ns_rr_rdata(rr)[0] = %d(%c)\n%s (%d)\n",
>           ns_rr_rdata(rr)[0],ns_rr_rdata(rr)[0],
>           txt,strlen(txt));
>   return 0;
> }

RFC 1035 3.3.14 says that the TXT RR RDATA consists of "One or more
<character-string>s". Back in 3.3 ("Standard RRs"), you'll see that
"<character-string>" is described as "single length octet followed by
that number of characters". Note that a TXT RR can consist of multiple
<character-string>s. For robustness, your code should accommodate that
possibility.

                                                                    -
Kevin




More information about the bind-users mailing list