bind_before_connect 0.1.1

Produces a std::net::TCPStream bound to a specified local address (Unix only).
Documentation
  • Coverage
  • 0%
    0 out of 13 items documented0 out of 1 items with examples
  • Size
  • Source code size: 23.39 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.31 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • 46bit/bind_before_connect
    4 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • 46bit

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.