SnmpKit.SnmpMgr.Target (snmpkit v1.3.20)
Target parsing and validation for SNMP requests.
Handles parsing of various target formats and resolves hostnames to IP addresses.
Summary
Functions
Parses a target string into a structured format.
Resolves a target to a parsed struct, with fallback for unparseable targets.
Resolves a hostname to an IP address if needed.
Validates that a target is reachable (basic connectivity check).
Functions
Parses a target string into a structured format.
Examples
iex> SnmpKit.SnmpMgr.Target.parse("192.168.1.1:161")
{:ok, %{host: {192, 168, 1, 1}, port: 161}}
iex> SnmpKit.SnmpMgr.Target.parse("device.local")
{:ok, %{host: "device.local", port: 161}}
iex> SnmpKit.SnmpMgr.Target.parse("192.168.1.1")
{:ok, %{host: {192, 168, 1, 1}, port: 161}}
Resolves a target to a parsed struct, with fallback for unparseable targets.
Unlike parse/1 which returns {:ok, target} or {:error, reason},
this function always returns a target struct, using the raw input as
the host with default port 161 if parsing fails.
This is the canonical function for target resolution across all modules.
Examples
iex> SnmpKit.SnmpMgr.Target.resolve("192.168.1.1:161")
%{host: {192, 168, 1, 1}, port: 161}
iex> SnmpKit.SnmpMgr.Target.resolve("device.local")
%{host: "device.local", port: 161}
iex> SnmpKit.SnmpMgr.Target.resolve(%{host: {127, 0, 0, 1}, port: 162})
%{host: {127, 0, 0, 1}, port: 162}
Resolves a hostname to an IP address if needed.
If the host is already an IP tuple, returns it unchanged.
Validates that a target is reachable (basic connectivity check).