# `Linx.IP.Subnet`
[🔗](https://github.com/oshlabs/linx/blob/v0.2.0/lib/linx/ip/subnet.ex#L1)

An IPv4 or IPv6 subnet — a network address and a prefix length, parsed
from CIDR notation.

    iex> Linx.IP.Subnet.parse("10.0.0.0/24")
    {:ok, ~IP"10.0.0.0/24"}

    iex> import Linx.IP
    iex> ~IP"fc00::/16"
    ~IP"fc00::/16"

## Subnet operations

    iex> import Linx.IP
    iex> Linx.IP.Subnet.contains?(~IP"10.0.0.0/8", ~IP"10.99.0.5")
    true
    iex> Linx.IP.Subnet.network(~IP"10.0.42.5/24")
    ~IP"10.0.42.0"
    iex> Linx.IP.Subnet.broadcast(~IP"10.0.42.5/24")
    ~IP"10.0.42.255"

# `t`

```elixir
@type t() :: %Linx.IP.Subnet{address: Linx.IP.t(), prefix: 0..128}
```

# `broadcast`

```elixir
@spec broadcast(t()) :: Linx.IP.t() | nil
```

Returns the IPv4 broadcast address of `subnet`, or `nil` for IPv6 (which
has no broadcast).

# `contains?`

```elixir
@spec contains?(t(), Linx.IP.t()) :: boolean()
```

Returns whether `subnet` contains `ip`.

False when the address families differ.

# `network`

```elixir
@spec network(t()) :: Linx.IP.t()
```

Returns `subnet`'s network address — the input address with host bits
zeroed.

# `parse`

```elixir
@spec parse(binary()) :: {:ok, t()} | {:error, term()}
```

Parses a CIDR string (`"10.0.0.0/24"`, `"fc00::/16"`) into a subnet.

---

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