6 int dns_txt_packet(stralloc
*out
,const char *buf
,unsigned int len
)
16 if (!stralloc_copys(out
,"")) return -1;
18 pos
= dns_packet_copy(buf
,len
,0,header
,12); if (!pos
) return -1;
19 uint16_unpack_big(header
+ 6,&numanswers
);
20 pos
= dns_packet_skipname(buf
,len
,pos
); if (!pos
) return -1;
23 while (numanswers
--) {
24 pos
= dns_packet_skipname(buf
,len
,pos
); if (!pos
) return -1;
25 pos
= dns_packet_copy(buf
,len
,pos
,header
,10); if (!pos
) return -1;
26 uint16_unpack_big(header
+ 8,&datalen
);
27 if (byte_equal(header
,2,DNS_T_TXT
))
28 if (byte_equal(header
+ 2,2,DNS_C_IN
)) {
29 if (pos
+ datalen
> len
) return -1;
31 for (i
= 0;i
< datalen
;++i
) {
34 txtlen
= (unsigned char) ch
;
37 if (ch
< 32) ch
= '?';
38 if (ch
> 126) ch
= '?';
39 if (!stralloc_append(out
,&ch
)) return -1;
51 int dns_txt(stralloc
*out
,const stralloc
*fqdn
)
53 if (!dns_domain_fromdot(&q
,fqdn
->s
,fqdn
->len
)) return -1;
54 if (dns_resolve(q
,DNS_T_TXT
) == -1) return -1;
55 if (dns_txt_packet(out
,dns_resolve_tx
.packet
,dns_resolve_tx
.packetlen
) == -1) return -1;
56 dns_transmit_free(&dns_resolve_tx
);