#sockets #extension #networking #api-bindings #socket-ext

socket2-ext

An socket2 extension contains utilities for handling networking sockets with a maximal amount of configuration possible intended

2 releases

0.1.1 Apr 15, 2024
0.1.0 Apr 14, 2024

#1097 in Network programming

Download history 130/week @ 2024-04-08 186/week @ 2024-04-15

316 downloads per month
Used in netstack-smoltcp

MIT license

9KB
106 lines

socket2-ext-rs

An socket2 extension contains utilities for handling networking sockets with a maximal amount of configuration possible intended.

Crates.io MIT licensed Build Status

Example

Bind a socket to a specific device on Unix/Windows host platform.

use socket2_ext::binds::{AddressBinding, BindDeviceOption};

fn main() {
    let iface = "your/interface/name";
    match socket2::Socket::new(socket2::Domain::IPV4, socket2::Type::DGRAM, None) {
        Err(e) => println!("create socket error: {:?}", e),
        Ok(socket) => {
            if let Err(e) = socket.bind_to_device(BindDeviceOption::v4(iface)) {
                println!("bind device error: {:?}", e);
            }
        }
    }
}

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.5–10MB
~64K SLoC