From 024c0d7ddefc5458911242d61a89f44b5a3b5a38 Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Wed, 27 Apr 2022 18:27:03 -0700 Subject: Restore conversions from ip v4/6 Sockaddr types to std::net equivalents. Fixes #1710 --- src/sys/socket/addr.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/sys/socket/addr.rs') diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 52d60ac9..5cd4678c 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -1233,6 +1233,16 @@ impl From for SockaddrIn { } } +#[cfg(feature = "net")] +impl From for net::SocketAddrV4 { + fn from(addr: SockaddrIn) -> Self { + net::SocketAddrV4::new( + net::Ipv4Addr::from(addr.0.sin_addr.s_addr.to_ne_bytes()), + u16::from_be(addr.0.sin_port) + ) + } +} + #[cfg(feature = "net")] impl std::str::FromStr for SockaddrIn { type Err = net::AddrParseError; @@ -1329,6 +1339,18 @@ impl From for SockaddrIn6 { } } +#[cfg(feature = "net")] +impl From for net::SocketAddrV6 { + fn from(addr: SockaddrIn6) -> Self { + net::SocketAddrV6::new( + net::Ipv6Addr::from(addr.0.sin6_addr.s6_addr), + u16::from_be(addr.0.sin6_port), + u32::from_be(addr.0.sin6_flowinfo), + u32::from_be(addr.0.sin6_scope_id) + ) + } +} + #[cfg(feature = "net")] impl std::str::FromStr for SockaddrIn6 { type Err = net::AddrParseError; -- cgit v1.2.3