# network/v1 — IPv4/IPv6 CIDR

CIDR block info, containment, and overlap checks, using Go's standard
library `net/netip`.

### `POST /v1/network/cidr/info`

**Request**

```json
{ "cidr": "10.14.32.17/21" }
```

**Response**

```json
{
  "cidr": "10.14.32.17/21",
  "network": "10.14.32.0/21",
  "firstAddress": "10.14.32.0",
  "lastAddress": "10.14.39.255",
  "prefixLength": 21,
  "version": 4,
  "addresses": "2048"
}
```

If the given address has host bits set (as above), `network`,
`firstAddress`, and `lastAddress` are normalized to the block's network
address — `cidr` echoes the input unchanged. `addresses` is the total
address count (including network/broadcast for IPv4) as a decimal string,
since it can exceed 64 bits for large IPv6 blocks.

### `POST /v1/network/cidr/contains`

**Request**

```json
{ "cidr": "10.1.2.0/24", "address": "10.1.2.200" }
```

**Response**

```json
{ "contains": true }
```

An address in a different family than the CIDR (IPv4 vs IPv6) always
returns `false` rather than an error.

### `POST /v1/network/cidr/overlaps`

**Request**

```json
{ "cidrA": "10.0.0.0/22", "cidrB": "10.0.2.0/24" }
```

**Response**

```json
{ "overlaps": true }
```

**Error response**

```json
{ "error": "invalid CIDR \"not-a-cidr\": netip.ParsePrefix(\"not-a-cidr\"): no '/'" }
```

## Notes

- IPv4 host/broadcast conventions (e.g. usable hosts = total − 2) are not
  applied — `addresses` is always the raw count for the prefix length,
  including the network and broadcast addresses for IPv4. Subtract 2
  yourself for `/0`–`/30` IPv4 blocks if you need the usable-host count;
  `/31` and `/32` have no such reservation (RFC 3021).
- IPv6 has no broadcast address; `lastAddress` is simply the highest
  address in the block.

## Out of scope

Subnetting/splitting a block into smaller prefixes, address-range (non-CIDR)
input, and IANA special-purpose registries (private/reserved ranges) — ask
if you need one added.

## Files

- `network.go` — module wiring (routes, HTTP handlers)
- `cidr.go` — pure CIDR logic
- `cidr_test.go` — known-vector and error tests
