DnsBuildQuery
Description
Build a single-question DNS query (recursion desired) into out.
Parameters
| Name | Direction | Description |
|---|---|---|
out |
out | Caller-managed Vec(u8). Buffer is cleared and repopulated. |
id |
in | Caller-supplied transaction id, echoed back by the nameserver. Pick randomly for cache-poisoning resistance. |
name |
in | Null-terminated hostname, e.g. “example.com”. Trailing dot is optional. Each label must be 1..63 bytes; total wire length must be < 255. |
type |
in | Question type (typically DNS_TYPE_A or DNS_TYPE_AAAA). |
Success
Returns true. out contains a valid wire query.
Failure
Returns false on invalid arguments, label-length violations, or Vec growth failure. out is left with whatever was written.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Dns.c:15:
DnsWireBuf buf = VecInitT(buf, a);
bool ok = DnsBuildQuery(&buf, 0x1234, "example.com", DNS_TYPE_A);
// Expected wire bytes (29 bytes total):
- In
Dns.c:43:
DnsWireBuf no_dot = VecInitT(no_dot, a);
DnsWireBuf w_dot = VecInitT(w_dot, a);
bool ok = DnsBuildQuery(&no_dot, 1, "a.b.c", DNS_TYPE_AAAA) && DnsBuildQuery(&w_dot, 1, "a.b.c.", DNS_TYPE_AAAA);
bool match = ok && no_dot.length == w_dot.length;- In
Dns.c:522:
DnsWireBuf query = VecInitT(query, sa);
u16 id = random_query_id();
if (!DnsBuildQuery(&query, id, hostname, qtype)) {
VecDeinit(&query);
DefaultAllocatorDeinit(&scratch);- In
Dns.c:72:
}
bool DnsBuildQuery(DnsWireBuf *out, u16 id, const char *name, DnsType type) {
if (!out || !name) {
return false;
Last updated on