hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 31a916a6dd69bd47821a2f05a2aa52e7eb2cdf51
parent f6d7bf79b46543c47c48a88457fd38e67bc3257c
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 21 Jun 2021 12:00:23 -0400

net::dns: use system nameservers in query

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mnet/dns/query.ha | 19+++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/net/dns/query.ha b/net/dns/query.ha @@ -1,16 +1,31 @@ use net::ip; use net::udp; +use unix::resolvconf; + +let defaults: []ip::addr = []; + +@fini fn fini() void = { + free(defaults); +}; // Performs a DNS query using the provided list of DNS servers. The caller must -// free the return value with [[message_free]]. +// free the return value with [[message_free]]. If no DNS servers are provided, +// the system defaults (if any) are used. export fn query(query: *message, addr: ip::addr...) (*message | error) = { - assert(len(addr) == 1, "TODO: Query multiple servers"); + if (len(addr) == 0) { + if (len(defaults) == 0) { + defaults = resolvconf::load(); + }; + addr = defaults; + }; + let socket = udp::listen(ip::ANY_V4, 0)?; defer udp::close(socket); // TODO: Use TCP for messages >512 bytes let sendbuf: [512]u8 = [0...]; let z = encode(sendbuf, query); + // TODO: Query multiple servers udp::sendto(socket, sendbuf[..z], addr[0], 53)?; let recvbuf: [512]u8 = [0...];