6 int dns_ip4_packet(stralloc
*out
,const char *buf
,unsigned int len
)
13 if (!stralloc_copys(out
,"")) return -1;
15 pos
= dns_packet_copy(buf
,len
,0,header
,12); if (!pos
) return -1;
16 uint16_unpack_big(header
+ 6,&numanswers
);
17 pos
= dns_packet_skipname(buf
,len
,pos
); if (!pos
) return -1;
20 while (numanswers
--) {
21 pos
= dns_packet_skipname(buf
,len
,pos
); if (!pos
) return -1;
22 pos
= dns_packet_copy(buf
,len
,pos
,header
,10); if (!pos
) return -1;
23 uint16_unpack_big(header
+ 8,&datalen
);
24 if (byte_equal(header
,2,DNS_T_A
))
25 if (byte_equal(header
+ 2,2,DNS_C_IN
))
27 if (!dns_packet_copy(buf
,len
,pos
,header
,4)) return -1;
28 if (!stralloc_catb(out
,header
,4)) return -1;
33 dns_sortip(out
->s
,out
->len
);
39 int dns_ip4(stralloc
*out
,const stralloc
*fqdn
)
45 if (!stralloc_copys(out
,"")) return -1;
47 for (i
= 0;i
<= fqdn
->len
;++i
) {
53 if ((ch
== '[') || (ch
== ']')) continue;
55 if (!stralloc_append(out
,&code
)) return -1;
59 if ((ch
>= '0') && (ch
<= '9')) {
65 if (!dns_domain_fromdot(&q
,fqdn
->s
,fqdn
->len
)) return -1;
66 if (dns_resolve(q
,DNS_T_A
) == -1) return -1;
67 if (dns_ip4_packet(out
,dns_resolve_tx
.packet
,dns_resolve_tx
.packetlen
) == -1) return -1;
68 dns_transmit_free(&dns_resolve_tx
);