net::dns
net::dns implements low-level DNS message encoding and decoding, as well as a
porcelain DNS resolver.
TODO:
- DNS over TCP
- Porcelain resolver API (resolv.conf)
- Decoders for various record types
- Complete RFC 2535 support
- Look for other RFCs worth addressing
Index
Types
type a;
type aaaa;
type class;
type header;
type message;
type mx;
type op;
type opcode;
type qclass;
type qr;
type qtype;
type question;
type rcode;
type rdata;
type rrecord;
type rtype;
type txt;
type unknown_rdata;
Errors
type error;
type format;
type name_error;
type not_implemented;
type refused;
type server_failure;
type unknown_error;
Functions
fn decode([]u8) (*message | format);
fn encode([]u8, *message) (size | error);
fn message_free(*message) void;
fn parse_domain(str) []str;
fn query(*message, ip::addr...) (*message | error);
fn unparse_domain([]str) str;
fn strerror(error) const str;
Types
type a
type a = ip::addr4;
An A record.
type aaaa
type aaaa = ip::addr6;
An AAAA record.
type class
type class = enum u16 {
IN = 1,
CS = 2,
CH = 3,
HS = 4,
};
Class type (e.g. Internet).
type header = struct {
id: u16,
op: op,
qdcount: u16,
ancount: u16,
nscount: u16,
arcount: u16,
};
DNS message header.
type message
type message = struct {
header: header,
questions: []question,
answers: []rrecord,
authority: []rrecord,
additional: []rrecord,
};
A DNS message, Hare representation. See encode and decode for the DNS
representation.
type mx
type mx = struct {
priority: u16,
name: []str,
};
An MX record.
type op
type op = struct {
qr: qr,
opcode: opcode,
aa: bool,
tc: bool,
rd: bool,
ra: bool,
rcode: rcode,
};
Operational information for this message.
type opcode
type opcode = enum u8 {
QUERY = 0,
IQUERY = 1,
STATUS = 2,
};
Operation requested from resolver.
type qclass
type qclass = enum u16 {
IN = 1,
CS = 2,
CH = 3,
HS = 4,
ANY = 255,
};
Query class (superset of class).
type qr
type qr = enum u8 {
QUERY = 0,
RESPONSE = 1,
};
Bit indicating if a header precedes a query or response.
type qtype
type qtype = enum u16 {
A = 1,
NS = 2,
CNAME = 5,
SOA = 6,
PTR = 12,
MX = 15,
TXT = 16,
AAAA = 28,
SRV = 33,
DNSKEY = 48,
AXFR = 252,
ALL = 255,
};
Question type (superset of rtype).
type question
type question = struct {
qname: []str,
qtype: qtype,
qclass: qclass,
};
A question section item.
type rcode
type rcode = enum u8 {
NO_ERROR = 0,
FMT_ERROR = 1,
SERVER_FAILURE = 2,
NAME_ERROR = 3,
NOT_IMPLEMENTED = 4,
REFUSED = 5,
};
Response code from resolver.
type rdata
type rdata = (a | aaaa | mx | txt | unknown_rdata);
Tagged union of supported rdata types.
type rrecord
type rrecord = struct {
name: []str,
rtype: rtype,
class: class,
ttl: u32,
rdata: rdata,
};
A resource record item.
type rtype
type rtype = enum u16 {
A = 1,
NS = 2,
CNAME = 5,
SOA = 6,
PTR = 12,
MX = 15,
TXT = 16,
AAAA = 28,
SRV = 33,
DNSKEY = 48,
};
Record type.
type txt
type txt = [][]u8;
A TXT record.
type unknown_rdata
type unknown_rdata = []u8;
The raw rdata field for an rrecord with an unknown rtype.
Errors
type error
type error = !(format | server_failure | name_error | not_implemented | refused |
unknown_error | errors::overflow | errors::timeout | net::error);
All error types which might be returned from net::dns functions.
type format = !void;
The DNS message was poorly formatted.
type name_error
type name_error = !void;
The domain name referenced in the query does not exist. Meaningful only for
responses from an authoritative name server.
type not_implemented
type not_implemented = !void;
The name server does not support the requested kind of query.
type refused
type refused = !void;
The name server refuses to perform the specified operation for policy
reasons.
type server_failure
type server_failure = !void;
The name server was unable to process this query due to a problem with the
name server.
type unknown_error
type unknown_error = !u8;
Any other server-provided error condition not known to Hare.
Functions
fn decode
fn decode(buf: []u8) (*message | format);
Decodes a DNS message, heap allocating the resources necessary to represent
it in Hare's type system. The caller must use message_free to free the
return value. To decode without use of the heap, see decoder_init.
fn encode
fn encode(buf: []u8, msg: *message) (size | error);
Encodes a DNS message, returning its size, or an error.
fn message_free
fn message_free(msg: *message) void;
Frees a message and the resources associated with it.
fn parse_domain
fn parse_domain(in: str) []str;
Converts a human-readable domain name (e.g. "example.org") into a DNS-ready
name slice (e.g. ["example", "org"]). The slice returned must be freed by the
caller, but the members of the slice themselves are borrowed from the input.
fn query
fn query(query: *message, servers: ip::addr...) (*message | error);
Performs a DNS query using the provided list of DNS servers. The caller must
free the return value with message_free.
If no DNS servers are provided, the system default servers (if any) are used.
fn unparse_domain
fn unparse_domain(in: []str) str;
Converts a DNS name slice (e.g. ["example", "org"]) into a human-readable
domain name (e.g. "example.org"). The return value must be freed by the
caller.
fn strerror
Show undocumented member
fn strerror(err: error) const str;