Modern alternatives to net2?

net2 by alex crichton allows us to customize TCP sockets or UDP sockets as such:

TcpStream::from(TcpBuilder::new_v4()?.bind(metadata.local_socket)?.reuse_port(true)?.connect(metadata.remote_socket?)?)

However, it does not compile and uses rust from the bronze ages. Is there a postmodern alternative to net2?

(async?)

@alexcrichton, I just managed to get it to compile in linux. I am now working on the windows version. I had to update the version to 2018, and am updating the code. My oh my, you've come a long ways since the days of net2!

@alexcrichton https://github.com/tbraun96/net2-rs

I fixed compile errors on both windows and linux, but the others are unchecked

https://docs.rs/socket2/0.3.11/socket2/

2 Likes

under https://docs.rs/socket2/0.1.0/socket2/struct.Protocol.html , it's asking for an i32 input to form the protocol. IS there a table that shows what value maps to which protocol?

Those would be in the libc headers, but there are constructors for the common protocols.

ths IANA list for internet protocols is here , though, it's rare to pass a non-zero protocol to the socket contructor, as for most socket domain/type combos there's only one common choice (SOCK_RAW is a notable exeption).