bind_before_connect

Crates.iobind_before_connect
lib.rsbind_before_connect
version0.1.1
sourcesrc
created_at2017-02-05 23:48:35.137796
updated_at2017-02-05 23:48:35.137796
descriptionProduces a std::net::TCPStream bound to a specified local address (Unix only).
homepagehttps://github.com/46bit/bind_before_connect
repositoryhttps://github.com/46bit/bind_before_connect.git
max_upload_size
id8405
size23,009
Michael Mokrysz (46bit)

documentation

README

bind_before_connect

In older network protocols or when using multiple IP Addresses, one wants to open a connection to a remote host using a specific local port and/or a specific local IP address. In other words you want to specify the local source address.

This can be done using the bind syscall (commonly used to specify the binding address for servers) followed by the connect syscall (commonly used to connect to a remote server). This sequence of syscalls is termed Bind Before Connect.

The constructor of Rust's std::net::TcpStream does not allow specifying a particular local address. It picks a random high port to use. This crate constructs a bound socket then converts it to a std::net::TcpStream for you to use as normal.

At present only Unix-based systems are supported. An implementation for Windows/etc would be very much welcomed.

Usage examples

See examples/simple.rs and run cargo run --example simple.

Commit count: 1

cargo fmt