Skip to content

Add bind_address config option for local IP binding#279

Open
kofany wants to merge 1 commit intoaatxe:developfrom
kofany:feature/bind-address
Open

Add bind_address config option for local IP binding#279
kofany wants to merge 1 commit intoaatxe:developfrom
kofany:feature/bind-address

Conversation

@kofany
Copy link

@kofany kofany commented Mar 7, 2026

Summary

  • Adds a bind_address configuration option that allows clients to bind to a specific local IP address when establishing a connection to an IRC server
  • Useful for multi-homed machines, vhost setups, and running multiple bots from different IP addresses on the same host
  • Uses tokio::net::TcpSocket to bind before connecting, with proper IPv4/IPv6 address family matching during DNS resolution

Changes

  • src/client/data/config.rs: New bind_address: Option<String> field with serde support and bind_address() getter
  • src/client/conn.rs: New connect_with_bind() helper using TcpSocket::bind() + connect(), integrated into both proxy and non-proxy new_stream() variants
  • src/error.rs: New ConfigError::InvalidBindAddress variant for invalid IP address strings

Usage

TOML config

nickname = "mybot"
server = "irc.example.com"
bind_address = "192.168.1.100"

Programmatic

let config = Config {
    nickname: Some("mybot".to_owned()),
    server: Some("irc.example.com".to_owned()),
    bind_address: Some("192.168.1.100".to_owned()),
    ..Config::default()
};

Notes

  • When bind_address is None (default), behavior is unchanged — the OS selects the local address
  • IPv4/IPv6 family of the bind address is matched against resolved server addresses
  • SOCKS5 proxy: a warning is logged since the proxy library manages its own TCP connection
  • No new dependencies required (TcpSocket is already available via tokio's net feature)

Test plan

  • cargo check — compiles cleanly
  • cargo clippy --all-targets --all-features — no new warnings
  • cargo test — all 67 unit tests + 8 doc-tests pass
  • Manual testing with a multi-homed machine

🤖 Generated with Claude Code

Allow clients to bind to a specific local IP address when connecting
to an IRC server. This is useful for multi-homed machines, vhosts,
or running multiple bots from different IP addresses.

- Add `bind_address` field to Config (Option<String>)
- Add `bind_address()` getter method
- Add `InvalidBindAddress` error variant to ConfigError
- Use TcpSocket with bind() in connect_with_bind() helper
- Handle IPv4/IPv6 address family matching on DNS resolution
- Log warning when bind_address is used with SOCKS5 proxy

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant