nessie

A collection of functions for resolving DNS names in Gleam programs targeting Erlang.

The functions in this module are implemented using Erlang’s built-in inet_res and inet modules. Most of the functions and types are simply Gleam representations of their Erlang counterparts.

Types

A DNS class type.

pub type DnsClass {
  In
  Chaos
  Hs
  Any
}

Constructors

  • In
  • Chaos
  • Hs
  • Any

A DNS error.

pub type ErrorReason {
  Formerr
  Qfmterr
  Servfail
  Nxdomain
  Notimp
  Refused
  Badvers
  TimeoutErr
  Other(error: String)
}

Constructors

  • Formerr
  • Qfmterr
  • Servfail
  • Nxdomain
  • Notimp
  • Refused
  • Badvers
  • TimeoutErr
  • Other(error: String)

    Encapuslates any other error, such as Posix errors.

A host entry.

For more information, see the inet_res:hostent Erlang type.

pub type Hostent(addr) {
  Hostent(
    name: String,
    aliases: List(String),
    addrtype: String,
    length: Int,
    addr_list: List(addr),
  )
}

Constructors

  • Hostent(
      name: String,
      aliases: List(String),
      addrtype: String,
      length: Int,
      addr_list: List(addr),
    )

A union type for IPv4 and IPv6 addresses.

pub type IPAddress {
  IPV4(IPV4)
  IPV6(IPV6)
}

Constructors

  • IPV4(IPV4)
  • IPV6(IPV6)

Erlang representation of an IPv4 address.

pub type IPV4 =
  #(Int, Int, Int, Int)

Erlang representation of an IPv6 address.

pub type IPV6 =
  #(Int, Int, Int, Int, Int, Int, Int, Int)

A DNS MX record.

pub type MXRecord {
  MXRecord(priority: Int, exchange: String)
}

Constructors

  • MXRecord(priority: Int, exchange: String)

Nameserver address and port.

pub type Nameserver =
  #(IPAddress, Int)

Options for resolving a DNS name.

pub type ResolverOption {
  Nameservers(opt: List(Nameserver))
  INet6(opt: Bool)
  Recurse(opt: Bool)
  Retry(opt: Int)
  TimeoutMillis(opt: Int)
  NxdomainReply(opt: Bool)
}

Constructors

  • Nameservers(opt: List(Nameserver))
  • INet6(opt: Bool)
  • Recurse(opt: Bool)
  • Retry(opt: Int)
  • TimeoutMillis(opt: Int)
  • NxdomainReply(opt: Bool)

A DNS SOA record.

pub type SOARecord {
  SOARecord(
    mname: String,
    rname: String,
    serial: Int,
    refresh: Int,
    retry: Int,
    expire: Int,
    minimum: Int,
  )
}

Constructors

  • SOARecord(
      mname: String,
      rname: String,
      serial: Int,
      refresh: Int,
      retry: Int,
      expire: Int,
      minimum: Int,
    )

DNS record types returning plain string data.

pub type StringRecordType {
  CNAME
  TXT
  NS
}

Constructors

  • CNAME
  • TXT
  • NS

A timeout for DNS lookups.

pub type Timeout {
  Timeout(value: Int)
  Infinity
}

Constructors

  • Timeout(value: Int)
  • Infinity

Functions

pub fn getbyname(
  name: String,
  srt: StringRecordType,
  timeout: Timeout,
) -> Result(Hostent(String), ErrorReason)

Looks up a DNS record of the given type for the given name.

pub fn getbyname_ipv4(
  name: String,
  timeout: Timeout,
) -> Result(Hostent(#(Int, Int, Int, Int)), ErrorReason)

Looks up an A record for the given name.

pub fn getbyname_ipv6(
  name: String,
  timeout: Timeout,
) -> Result(
  Hostent(#(Int, Int, Int, Int, Int, Int, Int, Int)),
  ErrorReason,
)

Looks up an AAAA record for the given name.

pub fn getbyname_mx(
  name: String,
  timeout: Timeout,
) -> Result(Hostent(MXRecord), ErrorReason)

Looks up a DNS MX record for the given name.

pub fn getbyname_soa(
  name: String,
  timeout: Timeout,
) -> Result(Hostent(SOARecord), ErrorReason)

Looks up a SOA record for the given name.

pub fn gethostbyaddr(
  address: IPAddress,
  timeout: Timeout,
) -> Result(Hostent(String), ErrorReason)

Looks up a host by IP address.

pub fn ip_decoder() -> fn(Dynamic) ->
  Result(IPAddress, List(DecodeError))

Returns a gleam/dynamic.Decoder for decoding an IP address tuple.

pub fn ip_to_string(ip_addr: IPAddress) -> Result(String, String)

Converts an IP address to a string.

For more detail, see the inet module’s ntoa/1 function docs

pub fn lookup(
  name: String,
  class: DnsClass,
  srt: StringRecordType,
  options: List(ResolverOption),
) -> List(String)

Looks up a record of the specified type for the given name.

pub fn lookup_ipv4(
  name: String,
  class: DnsClass,
  options: List(ResolverOption),
) -> List(#(Int, Int, Int, Int))

Looks up an A record for the given name.

pub fn lookup_ipv6(
  name: String,
  class: DnsClass,
  options: List(ResolverOption),
) -> List(#(Int, Int, Int, Int, Int, Int, Int, Int))

Looks up an AAAA record for the given name.

pub fn lookup_mx(
  name: String,
  class: DnsClass,
  options: List(ResolverOption),
) -> List(MXRecord)
pub fn lookup_soa(
  name: String,
  class: DnsClass,
  options: List(ResolverOption),
) -> List(SOARecord)

Looks up a SOA record for the given name.

pub fn string_to_ip(ip_addr: String) -> Result(IPAddress, String)

Converts a string to an IP address.

If the given string is not a valid IP address, this function returns an error.

For more detail, see the inet module’s parse_address/1 function docs.

Search Document