Traceroute.Utils (traceroute v0.2.5)

View Source

Implements various helper functions.

Summary

Functions

Returns the any address for a given socket domain.

Returns the domain for a given IP.

Returns the domain or a string representation of an IP address

Returns the host OS (linux or macOS)

Returns an ICMP packet's protocol + identifier combination.

Returns the IPv4 or IPv6 address as Tuple for a given IP Protocol and Domain.

Returns {:ok, ip_protocol} with ip_protocol = :ipv4|:ipv6 for an IP tuple or {:error, :invalid_ip_address} if the IP tuple is invalid.

Returns the IPv4 as Tuple for a given Domain.

Returns the IPv6 as Tuple for a given Domain.

Returns the socket domain, protocol, and ttl option for an IP protocol.

Returns the correct socket type (raw, dgram, stream) for a given protocol depending on the current host OS

Converts an integer to an IPv4 tuple

Converts an integer to an IPv6 tuple

Calls a GenServer with a timeout and handles the timeout error gracefully.

Splits an ICMP reply packet into IP header and payload.

Functions

any_addr(atom)

Returns the any address for a given socket domain.

get_domain(ip)

Returns the domain for a given IP.

get_domain_or_address(ip)

Returns the domain or a string representation of an IP address

get_host_os()

Returns the host OS (linux or macOS)

get_icmp_identifier(ip_protocol, reply_packet)

Returns an ICMP packet's protocol + identifier combination.

This is used to send ICMP responses to the correct process when multiple sockets run in parallel, ensuring each socket only processes responses intended for its own request.

Parameters

  • ip_protocol - Whether the packet was sent through :ipv4 or :ipv6
  • reply_packet - The raw ICMP response packet

get_ip(arg1, ip)

Returns the IPv4 or IPv6 address as Tuple for a given IP Protocol and Domain.

get_ip_protocol(ip)

Returns {:ok, ip_protocol} with ip_protocol = :ipv4|:ipv6 for an IP tuple or {:error, :invalid_ip_address} if the IP tuple is invalid.

get_ipv4(domain)

Returns the IPv4 as Tuple for a given Domain.

get_ipv6(domain)

Returns the IPv6 as Tuple for a given Domain.

get_protocol_options(atom, protocol)

Returns the socket domain, protocol, and ttl option for an IP protocol.

get_socket_type(protocol)

Returns the correct socket type (raw, dgram, stream) for a given protocol depending on the current host OS

ipv4_tuple(ip)

Converts an integer to an IPv4 tuple

ipv6_tuple(ip)

Converts an integer to an IPv6 tuple

safe_genserver_call(pid, args, timeout)

Calls a GenServer with a timeout and handles the timeout error gracefully.

split_reply_packet(ip_protocol, reply_packet, source \\ nil)

Splits an ICMP reply packet into IP header and payload.

For IPv6, an optional source address can be provided (from the socket's recvfrom result) since ICMPv6 DGRAM sockets strip the IPv6 header.