Socket.Host (sockets v2.1.7)

Copy Markdown

Looks up information about a host by name or IP address.

Given a hostname like "google.com" or an IP address, it returns a struct with the canonical name, any known aliases, and the list of IP addresses associated with that host. Also exposes helpers for getting the local machine's hostname and network interfaces.

Summary

Functions

Get the hostent by address.

Get the hostent by address, raising if an error occurs.

Get the hostent by name.

Get the hostent by name and family.

Get the hostent by name, raising if an error occurs.

Get the hostent by name and family, raising if an error occurs.

Get the interfaces of the machine.

Get the interfaces of the machine, raising if an error occurs.

Get the hostname of the machine.

Types

t()

@type t() :: %Socket.Host{
  aliases: [String.t()],
  length: integer(),
  list: [tuple()],
  name: String.t(),
  type: :inet | :inet6
}

Functions

by_address(address)

@spec by_address(Socket.Address.t()) :: {:ok, t()} | {:error, :inet.posix()}

Get the hostent by address.

by_address!(address)

@spec by_address!(Socket.Address.t()) :: t()

Get the hostent by address, raising if an error occurs.

by_name(name)

@spec by_name(binary()) :: {:ok, t()} | {:error, :inet.posix()}

Get the hostent by name.

by_name(name, family)

@spec by_name(binary(), :inet.address_family()) ::
  {:ok, t()} | {:error, :inet.posix()}

Get the hostent by name and family.

by_name!(name)

@spec by_name!(binary()) :: t()

Get the hostent by name, raising if an error occurs.

by_name!(name, family)

@spec by_name!(binary(), :inet.address_family()) :: t()

Get the hostent by name and family, raising if an error occurs.

interfaces()

@spec interfaces() :: {:ok, [tuple()]} | {:error, :inet.posix()}

Get the interfaces of the machine.

interfaces!()

@spec interfaces!() :: [tuple()]

Get the interfaces of the machine, raising if an error occurs.

name()

@spec name() :: String.t()

Get the hostname of the machine.