1
0

returns error on dual-stack IPv4 socket

This commit is contained in:
EAimTY 2023-05-25 21:51:10 +09:00
parent f6602beaf8
commit f0e931d7bd
2 changed files with 15 additions and 0 deletions

View File

@ -43,6 +43,13 @@ impl Server {
let socket = Socket::from(TcpListener::bind(&cfg.server).await?.into_std()?); let socket = Socket::from(TcpListener::bind(&cfg.server).await?.into_std()?);
if let Some(dual_stack) = cfg.dual_stack { if let Some(dual_stack) = cfg.dual_stack {
if cfg.server.is_ipv4() && dual_stack {
return Err(Error::from(IoError::new(
ErrorKind::Unsupported,
"IPv4 socket cannot be dual stack",
)));
}
socket.set_only_v6(!dual_stack)?; socket.set_only_v6(!dual_stack)?;
} }
@ -119,6 +126,7 @@ impl Server {
); );
if let Some(dual_stack) = SERVER.get().unwrap().dual_stack { if let Some(dual_stack) = SERVER.get().unwrap().dual_stack {
// We already checked that the server address is IPv6
socket.set_only_v6(!dual_stack)?; socket.set_only_v6(!dual_stack)?;
} }

View File

@ -98,6 +98,13 @@ impl Server {
let socket = Socket::from(StdUdpSocket::bind(cfg.server)?); let socket = Socket::from(StdUdpSocket::bind(cfg.server)?);
if let Some(dual_stack) = cfg.dual_stack { if let Some(dual_stack) = cfg.dual_stack {
if cfg.server.is_ipv4() && dual_stack {
return Err(Error::from(IoError::new(
ErrorKind::Unsupported,
"IPv4 socket cannot be dual stack",
)));
}
socket.set_only_v6(!dual_stack)?; socket.set_only_v6(!dual_stack)?;
} }