DHCPv4.Client (DHCP v0.5.0)

View Source

DHCP client utilities for testing and simulation.

Provides functions to simulate DHCP client behavior for testing DHCP server implementations.

Summary

Functions

Create a DHCPDECLINE message for testing.

Create a DHCPDISCOVER message for testing.

Create a DHCPRELEASE message for testing.

Create a DHCPREQUEST message for testing.

Send a DHCP message to a server for testing.

Run a complete DHCP lease test cycle.

Functions

decline(opts)

@spec decline(keyword()) :: DHCPv4.Message.t()

Create a DHCPDECLINE message for testing.

Options

  • :mac - Client MAC address (required)
  • :server_ip - Server IP to decline from (required)
  • :declined_ip - IP to decline (required)
  • :xid - Transaction ID (auto-generated if not provided)

discover(opts)

@spec discover(keyword()) :: DHCPv4.Message.t()

Create a DHCPDISCOVER message for testing.

Options

  • :mac - Client MAC address (required)
  • :hostname - Hostname to include (optional)
  • :requested_ip - IP to request (optional)
  • :xid - Transaction ID (auto-generated if not provided)

release(opts)

@spec release(keyword()) :: DHCPv4.Message.t()

Create a DHCPRELEASE message for testing.

Options

  • :mac - Client MAC address (required)
  • :server_ip - Server IP to release to (required)
  • :leased_ip - IP to release (required)
  • :xid - Transaction ID (auto-generated if not provided)

request(opts)

@spec request(keyword()) :: DHCPv4.Message.t()

Create a DHCPREQUEST message for testing.

Options

  • :mac - Client MAC address (required)
  • :server_ip - Server IP to request from (required)
  • :requested_ip - IP to request (required)
  • :xid - Transaction ID (auto-generated if not provided)

send_message(opts)

@spec send_message(keyword()) :: {:ok, DHCPv4.Message.t()} | {:error, term()}

Send a DHCP message to a server for testing.

Options

  • :message - Message to send (required)
  • :server_ip - Server IP to send to (default: {255, 255, 255, 255})
  • :timeout - Timeout in milliseconds (default: 5000)

test_lease_cycle(opts)

@spec test_lease_cycle(keyword()) ::
  {:ok,
   %{
     discover: DHCPv4.Message.t(),
     offer: DHCPv4.Message.t(),
     request: DHCPv4.Message.t(),
     ack: DHCPv4.Message.t()
   }}
  | {:error, term()}

Run a complete DHCP lease test cycle.

Returns the full DHCP handshake process for testing.