DNS.Message.Record.Data.A (DNS v0.5.0)

View Source

DNS A (Address) record implementation.

A records are used to map domain names to IPv4 addresses. This module provides functionality for creating, parsing, and serializing A records according to RFC 1035.

Fields

  • type - Resource record type (always 1 for A records)
  • rdlength - Length of the RDATA field (always 4 bytes for IPv4 addresses)
  • raw - Raw binary data for the record
  • data - IPv4 address as a 4-tuple {a, b, c, d}

Examples

iex> record = DNS.Message.Record.Data.A.new({192, 168, 1, 1})
iex> record.data
{192, 168, 1, 1}

iex> raw = <<192, 168, 1, 1>>
iex> record = DNS.Message.Record.Data.A.from_iodata(raw)
iex> to_string(record)
"192.168.1.1"

Summary

Functions

Parse A record data from binary iodata.

Create a new A record from an IPv4 address tuple.

Types

t()

@type t() :: %DNS.Message.Record.Data.A{
  data: :inet.ip4_address(),
  raw: bitstring(),
  rdlength: 4,
  type: DNS.ResourceRecordType.t()
}

Functions

from_iodata(raw, message \\ nil)

@spec from_iodata(iodata(), binary()) :: t()

Parse A record data from binary iodata.

Parameters

  • raw - Binary data containing the IPv4 address (4 bytes)
  • message - Full DNS message (unused for A records, kept for interface consistency)

Returns

  • t() - A record struct with parsed IPv4 address

Examples

iex> record = DNS.Message.Record.Data.A.from_iodata(<<192, 168, 1, 1>>)
iex> record.data
{192, 168, 1, 1}

new(ip)

@spec new(:inet.ip4_address()) :: t()

Create a new A record from an IPv4 address tuple.

Parameters

  • ip - IPv4 address as a 4-tuple {a, b, c, d} where each element is 0-255

Returns

  • t() - A record struct with the IP address data

Examples

iex> record = DNS.Message.Record.Data.A.new({192, 168, 1, 1})
iex> record.data
{192, 168, 1, 1}