DnsParseResponse
Description
Parse a wire-format response into out. The caller is responsible for DnsResponseDeinit(out) afterwards.
Parameters
| Name | Direction | Description |
|---|---|---|
out |
out | Receives parsed structure. Strings + Vecs use alloc. |
buf |
in | Wire bytes received from the nameserver. |
len |
in | Number of bytes in buf. |
alloc |
in | Allocator used for all strings + record Vecs. |
Success
Returns true. out is populated, including a possibly empty answer list (NXDOMAIN with no records is valid).
Failure
Returns false on header truncation, name-compression cycles, oversized labels, or out-of-bounds reads. out is left partially filled but is safe to DnsResponseDeinit.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Dns.c:152:
DnsResponse resp = {0};
bool ok = DnsParseResponse(&resp, wire, sizeof(wire), a);
bool match = ok && resp.id == 0x1234 && resp.is_response && resp.recursion_desired && resp.recursion_avail &&- In
Dns.c:219:
DnsResponse resp = {0};
bool ok = DnsParseResponse(&resp, wire, sizeof(wire), a);
bool match = ok && resp.rcode == DNS_RCODE_NXDOMAIN && resp.answers.length == 0;- In
Dns.c:290:
DnsResponse resp = {0};
bool ok = DnsParseResponse(&resp, wire, sizeof(wire), a);
bool match = ok && resp.answers.length == 1;
if (match) {- In
Dns.c:537:
DnsResponse resp = {0};
bool ok = DnsParseResponse(&resp, resp_buf, (u64)got, sa);
if (!ok || resp.id != id || resp.rcode != DNS_RCODE_NOERROR) {
DnsResponseDeinit(&resp);- In
Dns.c:284:
}
bool DnsParseResponse(DnsResponse *out, const u8 *buf, u64 len, Allocator *alloc) {
if (!out || !buf || !alloc) {
return false;
Last updated on