Skip to content

Make --host take an optional IP address to bind to#265

Merged
dubadub merged 1 commit intocooklang:mainfrom
pvsr:push-lpxyplrnqxxn
Feb 18, 2026
Merged

Make --host take an optional IP address to bind to#265
dubadub merged 1 commit intocooklang:mainfrom
pvsr:push-lpxyplrnqxxn

Conversation

@pvsr
Copy link
Copy Markdown
Contributor

@pvsr pvsr commented Feb 18, 2026

This allows the server to accept connections on just a specific IP address. I also changed the default address when the argument isn't provided from 0.0.0.0 to the IPv6 equivalent of ::, which means the server will accept connections on both IPv4 and IPv6 addresses instead of just IPv4. The default when --host is not provided remains 127.0.0.1, as the IPv6 equivalent of ::1 doesn't cover both.

For each configuration I tested connectivity on five addresses: 127.0.0.1, ::1, localhost, and my IPv4 and IPv6 LAN addresses, and that --open brought me to a working page.

Before

cook server: only requests to 127.0.0.1 and localhost succeed
cook server --host: ::1 and IPv6 LAN address fail, the rest succeed

After

cook server: only requests to 127.0.0.1 and localhost succeed
cook server --host: all succeed
cook server --host ::1: only ::1 and localhost succeed
cook server --host <IPv4 LAN address>: only IPv4 LAN address succeeds
cook server --host <IPv6 LAN address>: only IPv6 LAN address succeeds

Also support IPv6 with no arg by binding :: instead of 0.0.0.0
@pvsr pvsr force-pushed the push-lpxyplrnqxxn branch from 7e9b99c to a496cf1 Compare February 18, 2026 03:38
SocketAddr::from(([127, 0, 0, 1], args.port))
let addr = match args.host {
Some(Some(addr)) => addr,
Some(None) => "::".parse()?,
Copy link
Copy Markdown
Contributor Author

@pvsr pvsr Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative option that's verbose but more consistent:

Suggested change
Some(None) => "::".parse()?,
Some(None) => [0, 0, 0, 0, 0, 0, 0, 0].into(),

@dubadub dubadub merged commit 38edb60 into cooklang:main Feb 18, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants