Is your feature request related to a problem? Please describe.
Yes, with tokio sockets I can't bind two independent sockets both on 0.0.0.0 and :: using the same port, like this:
use std::net::*;
use tokio::net::UdpSocket;
#[tokio::main]
async fn main() {
let socket4 = UdpSocket::bind(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 10000)).await.unwrap();
let socket6 = UdpSocket::bind(SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, 10000, 0, 0)).await.unwrap();
}
I want to use two sockets, one for each IP version, because not all platforms support using one socket for both versions.
On Linux, IPV6_V6ONLY is turned off by default, and it maps IPv4 packets to the v6 socket as well (and maybe also on others platform too, idk), and because of it, I can't bind socket6 in this example. I get an address already in use error, because I'm on Linux. Which makes sense, but I'd like to enable the IPV6_V6ONLY option when it's disabled by default.
Describe alternatives you've considered
I could obtain the file descriptor and use C functions to set it maybe, haven't looked into it. I'd rather add the only_v6 myself if I have some time again.
Is your feature request related to a problem? Please describe. Yes, with tokio sockets I can't bind two independent sockets both on
0.0.0.0
and::
using the same port, like this:I want to use two sockets, one for each IP version, because not all platforms support using one socket for both versions. On Linux,
IPV6_V6ONLY
is turned off by default, and it maps IPv4 packets to the v6 socket as well (and maybe also on others platform too, idk), and because of it, I can't bindsocket6
in this example. I get an address already in use error, because I'm on Linux. Which makes sense, but I'd like to enable theIPV6_V6ONLY
option when it's disabled by default.Describe the solution you'd like I see
mio
is used internally by tokio.mio
has a function for setting that option: https://docs.rs/mio/latest/mio/net/struct.UdpSocket.html#method.only_v6 So I'd like theTcpSocket
andUdpSocket
to wrap that function as well.Describe alternatives you've considered I could obtain the file descriptor and use C functions to set it maybe, haven't looked into it. I'd rather add the
only_v6
myself if I have some time again.