# `IpAddress`

An IPv4 or IPv6 address: `192.0.2.1`, `2001:db8::1`.

Use it for an address you allow or block. For a range of addresses, use [`Cidr`](/docs/types/type-cidr.md). For a name, use [`Hostname`](/docs/types/type-hostname.md).

## Shape

One value, with no fields to fill in. As text it reads `2001:db8::1`.

## Example

```jadpo
IpAddress("192.0.2.1")
```

`text.parse(raw, as: IpAddress)` reads one from text that comes from outside. Text that isn't one at all fails `malformed`, such as `192.0.2` or `example.com`.

## Good to know

- When it identifies a person, mark the field that holds it `personal: PersonalData.online`.
- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it.

## In JSON

A string, in a request, a response or `json.write`:

```json
"192.0.2.1"
"2001:db8::1"
```

## Details

<details>
<summary>Text form, storage, how it is shown, and operations</summary>

`IpAddress` is in the group Web and network, and has been in Jadpo since 0.1.0.

### Text form

`text.from` writes one standard text form, the same form `text.parse` reads back: `192.0.2.1` and `2001:db8::1`.

### How it is stored

It is stored in one column named for the field, of type `text`. `2001:db8::1` is stored as `'2001:db8::1'`.

### How it is shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `192.0.2.1` | `192.0.2.1` |
| `2001:db8::1` | `2001:db8::1` |

### Operations

- `web.cidr_contains(range: Cidr, address: IpAddress) -> Bool`: Whether `address` is inside `range`. An IPv4 address is never inside an IPv6 range, nor the other way round.

It also takes `text.parse`, `text.from`, `text.format`, `json.read`, `json.write` and `==`. [How every standard type behaves](/docs/every-standard-type-meets-one-contract.md) says how they work.

</details>
