# `Linx.Netlink.Rtnl.Address`
[🔗](https://github.com/oshlabs/linx/blob/v0.2.0/lib/linx/netlink/rtnl/address.ex#L1)

rtnetlink interface addresses — the `RTM_*ADDR` messages.

`list/1` and `list/2` read addresses; `add/4` and `delete/4` assign and
remove them. IPv4 and IPv6 are both supported — the address family is
detected from the IP value.

Address fields (`:address`, `:local`) on a decoded `%Address{}` are
`Linx.IP` structs, not raw bytes; they accept either an `Linx.IP` or a
string at the verb's input.

## Example

    {:ok, sock} = Rtnl.open()

    :ok = Address.add(sock, "eth0", "10.0.0.5", 24)
    :ok = Address.add(sock, "eth0", "fd00::5", 64)

    {:ok, addrs} = Address.list(sock, "eth0")
    # => [#Linx.Netlink.Rtnl.Address<10.0.0.5/24 ifindex=2>,
    #     #Linx.Netlink.Rtnl.Address<fd00::5/64 ifindex=2>]

    :ok = Address.delete(sock, "eth0", "10.0.0.5", 24)

The wire format — `struct ifaddrmsg` and the `IFA_*` attributes
(`include/uapi/linux/if_addr.h`) — is declared with the
`Linx.Netlink.Codec` DSL.

# `t`

```elixir
@type t() :: %Linx.Netlink.Rtnl.Address{
  address: term(),
  family: term(),
  flags: term(),
  index: term(),
  local: term(),
  prefixlen: term(),
  scope: term()
}
```

# `add`

```elixir
@spec add(
  Linx.Netlink.Socket.t(),
  binary(),
  binary() | Linx.IP.t(),
  non_neg_integer()
) ::
  :ok | {:error, term()}
```

Adds address `ip` with prefix length `prefix` to link `link_name`.

`ip` may be a string (`"10.0.0.5"`, `"fc00::1"`) or a `Linx.IP`. The
address family is taken from the IP.

# `decode`

```elixir
@spec decode(binary()) :: t()
```

Decodes a netlink message body into a `t:t/0`.

# `delete`

```elixir
@spec delete(
  Linx.Netlink.Socket.t(),
  binary(),
  binary() | Linx.IP.t(),
  non_neg_integer()
) ::
  :ok | {:error, term()}
```

Removes address `ip`/`prefix` from link `link_name`.

# `encode`

```elixir
@spec encode(t()) :: binary()
```

Encodes a `t:t/0` into its netlink message body.

# `list`

```elixir
@spec list(Linx.Netlink.Socket.t()) :: {:ok, [t()]} | {:error, term()}
```

Lists every address in the socket's network namespace.

# `list`

```elixir
@spec list(Linx.Netlink.Socket.t(), binary()) :: {:ok, [t()]} | {:error, term()}
```

Lists the addresses on the link named `link_name`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
