Library dns

To use this library in your code:

import net.modules.dns

Interfaces

A DnsClient contains a list of DNS servers in the form of IP addresses in string form.

Functions

create-dns-packet queries/List records/List --id/int --is-response/bool --is-authoritative/bool=false --authorities/List=[] --additionals/List=[] -> ByteArray
Create a DNS packet for lookups or reponses.

decode-name packet/ByteArray position/int [position-block] -> string
Decodes a name from a DNS (RFC 1035) packet.
The block is invoked with the index of the next data in the packet.
Deprecated. Use decode-name reader packet instead.

Decodes a name from a DNS (RFC 1035) packet.
Takes both the reader and the packet, as the parts can contain pointers that are absolute in the packet.

decode-packet packet/ByteArray --error-name/string=null --mdns/bool=false -> DecodedPacket
Decodes a DNS packet.
The error-name is only used for error messages.

On Unix systems the default client is one that keeps an eye on changes in /etc/resolv.conf.
On FreeRTOS systems the default client is set by DHCP.
On Windows defaults to using Google and Cloudflare DNS servers.
On all platforms you can set a custom default client with the default-client= client setter.

default-client= client/DnsClient -> none

The default mDNS client.
By default this is an instance of MdnsDnsClient, but it can be overwritten with default-mdns-client= client.

dns-lookup host/string --network/Interface --server/string=null --client/DnsClient=null --timeout/Duration=DNS-DEFAULT-TIMEOUT --accept-ipv4/bool=true --accept-ipv6/bool=false -> IpAddress
Look up a domain name and return a single net.IpAddress.

dns-lookup-multi host/string --network/Interface --server/string=null --client/DnsClient=null --timeout/Duration=DNS-DEFAULT-TIMEOUT --accept-ipv4/bool=true --accept-ipv6/bool=false -> List
Look up a domain name and return a list of net.IpAddress records.
If given a numeric address like 127.0.0.1 it merely parses the numbers without a network round trip.
By default the server is determined by the network interface. The fallback servers if none are configured are the Google and Cloudflare DNS services.
If there are multiple servers then they are tried in rotation until one responds. If one responds with an error (eg. no such domain) we do not try the next one. This is in line with the way that Linux handles multiple servers on the same lookup request. If we are looking up a name ending in ".local" and no specific client is provided, we use the default mDNS client default-mdns-client.

find-in-cache top-cache/Map name/any type/int -> List
Returns a list of results for the given name and type, or null if the cache does not contain a valid entry (or it has expired).

trim-cache top-cache/Map type/int --max-cache-size/int=MAX-CACHE-SIZE_ -> none
Limits the size of the cache to avoid using too much memory.