# Hostname, localhost, IpAddress.bind

**URL:** <https://ziggit.dev/t/hostname-localhost-ipaddress-bind/18451>\
**Category:** Help\
**Tags:** standard-library\
**Created:** [November 13, 2026, 12:40pm UTC](https://ziggit.dev/t/hostname-localhost-ipaddress-bind/18451 "2026-11-13T12:40:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![flow](https://ziggit.dev/letter_avatar_proxy/v4/letter/f/8edcca/32.png) [@flow](https://ziggit.dev/u/flow)\
**Post date:** [November 13, 2026, 12:40pm UTC](https://ziggit.dev/t/hostname-localhost-ipaddress-bind/18451/1 "2026-11-13T12:40:34Z")

</div>

I’ve the following ‘string’ as url: `localhost:9000`

I need `std.Io.net.IpAddress.parseLiteral` to get a `IpAddress`, but it can’t handle the url: `error.InvalidAddress`.

How to handle such a url?

---

<div class="post-metadata">

**Author:** ![prokoprandacek](https://ziggit.dev/user_avatar/ziggit.dev/prokoprandacek/32/2863_2.png) [@prokoprandacek](https://ziggit.dev/u/prokoprandacek)\
**Post date:** [November 13, 2026, 1:01pm UTC](https://ziggit.dev/t/hostname-localhost-ipaddress-bind/18451/2 "2026-11-13T13:01:47Z")

</div>

localhost is not an IP address but a hostname. to handle this correctly you need to go through `std.Io.net.Hostname.fromUri`, giving it a `std.Uri` and then `.lookup` on the `std.Io.net.Hostname`

PS: if you know that it is always localhost, i would use ::1 or 127.0.0.1, since those don’t need the lookup step that involves io.

---

<div class="post-metadata">

**Author:** ![Wunka](https://ziggit.dev/user_avatar/ziggit.dev/wunka/32/7510_2.png) [@Wunka](https://ziggit.dev/u/Wunka)\
**Post date:** [November 13, 2026, 1:30pm UTC](https://ziggit.dev/t/hostname-localhost-ipaddress-bind/18451/3 "2026-11-13T13:30:57Z")

</div>

For localhost there is also: `std.Io.net.Ip4Adress.loopback(port)` / `std.Io.net.Ip6Adress.loopback(port)` which directly maps to 127.0.0.1 / ::1 without parsing. (and with that also no possible ParseErrors on return)

So I would use something like:

```zig
const ipv4: IpAddress = .{.ip4 = .loopback(9000)};
const ipv6: IpAddress = .{.ip6 = .loopback(9000)};

```

---

<div class="post-metadata">

**Author:** ![flow](https://ziggit.dev/letter_avatar_proxy/v4/letter/f/8edcca/32.png) [@flow](https://ziggit.dev/u/flow)\
**Post date:** [November 13, 2026, 1:40pm UTC](https://ziggit.dev/t/hostname-localhost-ipaddress-bind/18451/4 "2026-11-13T13:40:29Z")

</div>

> [@prokoprandacek](#):
>
> localhost is not an IP address but a hostname. to handle this correctly you need to go through `std.Io.net.Hostname.fromUri`, giving it a `std.Uri` and then `.lookup` on the `std.Io.net.Hostname`

Wow, that’s not really straightforward, given all the different types needed to get something out of the chain.

> [@Wunka](#):
>
> For localhost there is also: `std.Io.net.Ip4Adress.loopback(port)` / `std.Io.net.Ip6Adress.loopback(port)` which directly maps to 127.0.0.1 / ::1 without parsing. (and with that also no possible ParseErrors on return)

So then I just need to get the port from a url, which can be localhost:port or 127.0.0.1:port. ( tokenizeScalar?)

But I’m not sure if it will be localhost, it can be any url actually.

edit:

std.Uri.Parse can’t handle ‘localhost:9000’, then `uri.host` is null.

In Go you can do:  
`conn, err := d.DialContext(ctx, "tcp", "localhost:12345")`
