20 uint16_unpack_big(header + 6,&numanswers);
24 while (numanswers--) {
27 uint16_unpack_big(header + 8,&datalen);
28 if (byte_equal(header,2,
DNS_T_A))
29 if (byte_equal(header + 2,2,
DNS_C_IN))
32 if (!stralloc_catb(
out,header,4))
return DNS_MEM;
52 if (!stralloc_readyplus(fqdn,1))
return DNS_MEM;
54 fqdn->s[fqdn->len] = 0;
55 if (ip4_scan(fqdn->s,
ip)) {
61 for (i = 0; i <= fqdn->len; ++i) {
67 if ((ch ==
'[') || (ch ==
']'))
continue;
69 if (!stralloc_append(
out,&code))
return DNS_MEM;
73 if ((ch >=
'0') && (ch <=
'9')) {
104 uint16_unpack_big(header + 6,&numanswers);
108 while (numanswers--) {
111 uint16_unpack_big(header + 8,&datalen);
113 if (byte_equal(header + 2,2,
DNS_C_IN))
116 if (!stralloc_catb(
out,header,16))
return DNS_MEM;
118 }
else if (byte_equal(header,2,
DNS_T_A))
119 if (byte_equal(header + 2,2,
DNS_C_IN))
121 byte_copy(header,12,V4mappedprefix);
123 if (!stralloc_catb(
out,header,16))
return DNS_MEM;
143 if (!stralloc_readyplus(fqdn,1))
return DNS_MEM;
145 fqdn->s[fqdn->len] = 0;
146 if (ip6_scan(fqdn->s,
ip)) {
152 for (i = 0; i <= fqdn->len; ++i) {
158 if ((ch ==
'[') || (ch ==
']'))
continue;
160 if (!stralloc_append(
out,&code))
return DNS_MEM;
164 if ((ch >=
'0') && (ch <=
'9')) {
int dns_domain_fromdot(char **out, const char *buf, unsigned int n)
void dns_domain_free(char **out)
int dns_ip4_packet(stralloc *out, const char *buf, unsigned int len)
int dns_ip6_packet(stralloc *out, const char *buf, unsigned int len)
int dns_ip4(stralloc *out, stralloc *fqdn)
int dns_ip6(stralloc *out, stralloc *fqdn)
unsigned int dns_packet_copy(const char *buf, unsigned int len, unsigned int pos, char *out, unsigned int outlen)
unsigned int dns_packet_skipname(const char *buf, unsigned int len, unsigned int pos)
int dns_resolve(const char *q, const char qtype[2])
struct dns_transmit dns_resolve_tx
void dns_sortip4(char *s, unsigned int n)
void dns_sortip6(char *s, unsigned int n)
void dns_transmit_free(struct dns_transmit *d)
void out(const char *s, unsigned int len)