Module eco.dns

DNS resolver utilities.

This module implements a simple DNS client over UDP.

It resolves names using:

  • /etc/hosts first
  • then DNS servers from opts.nameservers or /etc/resolv.conf

Functions

query (qname[, opts]) Resolve a DNS name.
type_name (n) Convert RR type number to its mnemonic.

Fields

TYPE_A Resource record type: A.
TYPE_NS Resource record type: NS.
TYPE_CNAME Resource record type: CNAME.
TYPE_SOA Resource record type: SOA.
TYPE_PTR Resource record type: PTR.
TYPE_MX Resource record type: MX.
TYPE_TXT Resource record type: TXT.
TYPE_AAAA Resource record type: AAAA.
TYPE_SRV Resource record type: SRV.
TYPE_SPF Resource record type: SPF.
CLASS_IN DNS class: IN (Internet).
SECTION_AN DNS answer section: Answer.
SECTION_NS DNS answer section: Authority.
SECTION_AR DNS answer section: Additional.


Functions

query (qname[, opts])

Resolve a DNS name.

The return value is an array of answer records. Record table fields depend on the record type. Common fields:

  • name, type, class, ttl, section

Type-specific fields include:

  • A/AAAA: address
  • CNAME: cname
  • MX: preference, exchange
  • SRV: priority, weight, port, target
  • NS: nsdname
  • TXT: txt (string or array of strings)
  • SPF: spf (string or array of strings)
  • PTR: ptrdname
  • SOA: mname, rname, serial, refresh, retry, expire, minimum

Parameters:

  • qname string Domain name or IP address.
  • opts table

    Options:

    • type (int) RR type (default TYPE_A).
    • no_recurse (boolean) Disable recursion desired (RD) flag.
    • nameservers (table) Nameserver list. Each entry can be:
    • "ip" string
    • { ip, port } table
    • mark (number) SO_MARK for the UDP socket.
    • device (string) SO_BINDTODEVICE for the UDP socket.
    (optional)

Returns:

    table answers

Or

  1. nil On failure.
  2. string Error message.
type_name (n)
Convert RR type number to its mnemonic.

Parameters:

  • n int RR type number.

Returns:

    string

Fields

TYPE_A
Resource record type: A.
TYPE_NS
Resource record type: NS.
TYPE_CNAME
Resource record type: CNAME.
TYPE_SOA
Resource record type: SOA.
TYPE_PTR
Resource record type: PTR.
TYPE_MX
Resource record type: MX.
TYPE_TXT
Resource record type: TXT.
TYPE_AAAA
Resource record type: AAAA.
TYPE_SRV
Resource record type: SRV.
TYPE_SPF
Resource record type: SPF.
CLASS_IN
DNS class: IN (Internet).
SECTION_AN
DNS answer section: Answer.
SECTION_NS
DNS answer section: Authority.
SECTION_AR
DNS answer section: Additional.
generated by LDoc 1.5.0 Last updated 2026-04-09 14:48:22