DNS (DNS v0.5.0)

View Source

Pure Elixir DNS library for protocol message parsing and resource record handling.

This library provides comprehensive DNS protocol implementation including message parsing, resource record handling, zone management, and DNSSEC support.

Architecture

All DNS related modules are namespaced under this module. DNS resources implement two key protocols for consistent behavior:

Protocols

  • String.Chars - Provides human-readable string representations of DNS entities
  • DNS.Parameter - Handles binary serialization for DNS protocol data

Core Components

Usage Examples

Creating Resource Records

iex> a_record = DNS.Message.Record.Data.A.new({192, 168, 1, 1})
iex> to_string(a_record)
"192.168.1.1"

Zone Management

iex> zone = DNS.Zone.new("example.com", :authoritative)
iex> zone.name
#DNS.Zone.Name<example.com>

Security Features

The library includes comprehensive security protections:

  • DNS compression loop attack prevention
  • Input validation bounds checking
  • Path traversal protection
  • Centralized error handling
  • ETS table security

Performance

  • Optimized ETS queries for zone operations
  • Efficient binary pattern matching for DNS parsing
  • Concurrent access support with read_concurrency
  • Memory-efficient zone storage

Summary

Functions

Convert a DNS entity to binary iodata using the DNS.Parameter protocol.

Functions

to_iodata(value)

@spec to_iodata(term()) :: iodata()

Convert a DNS entity to binary iodata using the DNS.Parameter protocol.

This is a convenience function that delegates to DNS.Parameter.to_iodata/1.

Parameters

  • value - Any DNS entity that implements the DNS.Parameter protocol

Returns

  • iodata() - Binary representation suitable for network transmission

Examples

iex> DNS.to_iodata("example.com")
<<7, 101, 120, 97, 109, 112, 108, 101, 3, 99, 111, 109, 0>>

iex> record = DNS.Message.Record.Data.A.new({192, 168, 1, 1})
iex> DNS.to_iodata(record)
<<0, 4, 192, 168, 1, 1>>