diff --git a/library/std/src/net/ip_addr.rs b/library/std/src/net/ip_addr.rs index e167fbd1b9c..2c436078754 100644 --- a/library/std/src/net/ip_addr.rs +++ b/library/std/src/net/ip_addr.rs @@ -2,7 +2,9 @@ #[cfg(all(test, not(target_os = "emscripten")))] mod tests; +#[cfg(not(target_os = "yggdrasil"))] use crate::sys::net::netc as c; +#[cfg(not(target_os = "yggdrasil"))] use crate::sys_common::{FromInner, IntoInner}; #[stable(feature = "ip_addr", since = "1.7.0")] @@ -14,6 +16,7 @@ pub use core::net::{Ipv4Addr, Ipv6Addr}; #[unstable(feature = "ip", issue = "27709")] pub use core::net::Ipv6MulticastScope; +#[cfg(not(target_os = "yggdrasil"))] impl IntoInner for Ipv4Addr { #[inline] fn into_inner(self) -> c::in_addr { @@ -22,17 +25,20 @@ impl IntoInner for Ipv4Addr { c::in_addr { s_addr: u32::from_ne_bytes(self.octets()) } } } +#[cfg(not(target_os = "yggdrasil"))] impl FromInner for Ipv4Addr { fn from_inner(addr: c::in_addr) -> Ipv4Addr { Ipv4Addr::from(addr.s_addr.to_ne_bytes()) } } +#[cfg(not(target_os = "yggdrasil"))] impl IntoInner for Ipv6Addr { fn into_inner(self) -> c::in6_addr { c::in6_addr { s6_addr: self.octets() } } } +#[cfg(not(target_os = "yggdrasil"))] impl FromInner for Ipv6Addr { #[inline] fn from_inner(addr: c::in6_addr) -> Ipv6Addr { diff --git a/library/std/src/net/socket_addr.rs b/library/std/src/net/socket_addr.rs index 421fed9077c..a834804dfb8 100644 --- a/library/std/src/net/socket_addr.rs +++ b/library/std/src/net/socket_addr.rs @@ -4,24 +4,29 @@ mod tests; use crate::io; use crate::iter; +#[cfg(not(target_os = "yggdrasil"))] use crate::mem; use crate::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use crate::option; use crate::slice; +#[cfg(not(target_os = "yggdrasil"))] use crate::sys::net::netc as c; use crate::sys_common::net::LookupHost; +#[cfg(not(target_os = "yggdrasil"))] use crate::sys_common::{FromInner, IntoInner}; use crate::vec; #[stable(feature = "rust1", since = "1.0.0")] pub use core::net::{SocketAddr, SocketAddrV4, SocketAddrV6}; +#[cfg(not(target_os = "yggdrasil"))] impl FromInner for SocketAddrV4 { fn from_inner(addr: c::sockaddr_in) -> SocketAddrV4 { SocketAddrV4::new(Ipv4Addr::from_inner(addr.sin_addr), u16::from_be(addr.sin_port)) } } +#[cfg(not(target_os = "yggdrasil"))] impl FromInner for SocketAddrV6 { fn from_inner(addr: c::sockaddr_in6) -> SocketAddrV6 { SocketAddrV6::new( @@ -33,6 +38,7 @@ impl FromInner for SocketAddrV6 { } } +#[cfg(not(target_os = "yggdrasil"))] impl IntoInner for SocketAddrV4 { fn into_inner(self) -> c::sockaddr_in { c::sockaddr_in { @@ -44,6 +50,7 @@ impl IntoInner for SocketAddrV4 { } } +#[cfg(not(target_os = "yggdrasil"))] impl IntoInner for SocketAddrV6 { fn into_inner(self) -> c::sockaddr_in6 { c::sockaddr_in6 { diff --git a/library/std/src/os/yggdrasil/io/mod.rs b/library/std/src/os/yggdrasil/io/mod.rs index 0194c95c04d..a736ec823a4 100644 --- a/library/std/src/os/yggdrasil/io/mod.rs +++ b/library/std/src/os/yggdrasil/io/mod.rs @@ -15,6 +15,9 @@ pub mod terminal; // Public exports +#[unstable(feature = "yggdrasil_os", issue = "none")] +pub use net::raw_socket; + #[stable(feature = "io_safety", since = "1.63.0")] pub use owned::*; #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/std/src/os/yggdrasil/io/net.rs b/library/std/src/os/yggdrasil/io/net.rs deleted file mode 100644 index 49daf43cb3a..00000000000 --- a/library/std/src/os/yggdrasil/io/net.rs +++ /dev/null @@ -1,45 +0,0 @@ -use crate::os::yggdrasil::io::OwnedFd; -use crate::os::yggdrasil::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; -use crate::sys_common::{self, AsInner, FromInner, IntoInner}; -use crate::{net, sys}; - -macro_rules! impl_as_raw_fd { - ($($t:ident)*) => {$( - #[stable(feature = "rust1", since = "1.0.0")] - impl AsRawFd for net::$t { - #[inline] - fn as_raw_fd(&self) -> RawFd { - self.as_inner().socket().as_raw_fd() - } - } - )*}; -} - -macro_rules! impl_from_raw_fd { - ($($t:ident)*) => {$( - #[stable(feature = "rust1", since = "1.0.0")] - impl FromRawFd for net::$t { - #[inline] - unsafe fn from_raw_fd(fd: RawFd) -> net::$t { - let socket = sys::net::Socket::from_inner(FromInner::from_inner(OwnedFd::from_raw_fd(fd))); - net::$t::from_inner(sys_common::net::$t::from_inner(socket)) - } - } - )*}; -} - -macro_rules! impl_into_raw_fd { - ($($t:ident)*) => {$( - #[stable(feature = "rust1", since = "1.0.0")] - impl IntoRawFd for net::$t { - #[inline] - fn into_raw_fd(self) -> RawFd { - self.into_inner().into_socket().into_inner().into_raw_fd() - } - } - )*}; -} - -impl_as_raw_fd! { TcpStream TcpListener UdpSocket } -impl_from_raw_fd! { TcpStream TcpListener UdpSocket } -impl_into_raw_fd! { TcpStream TcpListener UdpSocket } diff --git a/library/std/src/os/yggdrasil/io/net/mod.rs b/library/std/src/os/yggdrasil/io/net/mod.rs new file mode 100644 index 00000000000..8569154e11c --- /dev/null +++ b/library/std/src/os/yggdrasil/io/net/mod.rs @@ -0,0 +1 @@ +pub mod raw_socket; diff --git a/library/std/src/os/yggdrasil/io/net/raw_socket.rs b/library/std/src/os/yggdrasil/io/net/raw_socket.rs new file mode 100644 index 00000000000..92c67ae5181 --- /dev/null +++ b/library/std/src/os/yggdrasil/io/net/raw_socket.rs @@ -0,0 +1,49 @@ +#![unstable(feature = "yggdrasil_os", issue = "none")] + +use yggdrasil_rt::{ + net::{MacAddress, SocketInterfaceQuery, SocketOption, SocketType}, + sys as syscall, +}; + +use crate::io; +use crate::mem::MaybeUninit; +use crate::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; +use crate::os::fd::{AsRawFd, FromRawFd}; +use crate::sys::cvt_io; +use crate::sys::io::FileDesc; + +#[unstable(feature = "yggdrasil_os", issue = "none")] +pub struct RawSocket(FileDesc); + +impl RawSocket { + #[unstable(feature = "yggdrasil_os", issue = "none")] + pub fn bind<'a, Q: Into>>(interface: Q) -> io::Result { + // TODO this is atrocious + let query = interface.into(); + let bind_address = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0)); + let raw = cvt_io(unsafe { syscall::bind_socket(&bind_address, SocketType::RawPacket) })?; + let inner = unsafe { FileDesc::from_raw_fd(raw) }; + cvt_io(unsafe { + syscall::set_socket_option(inner.as_raw_fd(), &SocketOption::BindInterface(query)) + })?; + Ok(Self(inner)) + } + + pub fn send(&self, data: &[u8]) -> io::Result { + cvt_io(unsafe { syscall::send_to(self.0.as_raw_fd(), data, &None) }) + } + + pub fn recv(&self, data: &mut [u8]) -> io::Result { + let mut discard = MaybeUninit::uninit(); + cvt_io(unsafe { syscall::receive_from(self.0.as_raw_fd(), data, &mut discard) }) + } + + pub fn hardware_address(&self) -> io::Result<[u8; 6]> { + let mut value = SocketOption::BoundHardwareAddress(MacAddress::BROADCAST); + cvt_io(unsafe { syscall::get_socket_option(self.0.as_raw_fd(), &mut value) })?; + let SocketOption::BoundHardwareAddress(value) = value else { + unreachable!(); + }; + Ok(value.into()) + } +} diff --git a/library/std/src/sys/yggdrasil/mod.rs b/library/std/src/sys/yggdrasil/mod.rs index 43df338e960..30272f074ee 100644 --- a/library/std/src/sys/yggdrasil/mod.rs +++ b/library/std/src/sys/yggdrasil/mod.rs @@ -166,6 +166,9 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { | Ok(OsError::InvalidOperation) => ErrorKind::InvalidInput, Ok(OsError::NotImplemented) => ErrorKind::Unsupported, + // Network + Ok(OsError::HostUnreachable) => ErrorKind::HostUnreachable, + // Uncategorized Ok(OsError::InvalidFile) => ErrorKind::Uncategorized, Err(_) => ErrorKind::Uncategorized, diff --git a/library/std/src/sys/yggdrasil/net/mod.rs b/library/std/src/sys/yggdrasil/net/mod.rs new file mode 100644 index 00000000000..3e54cf2aa71 --- /dev/null +++ b/library/std/src/sys/yggdrasil/net/mod.rs @@ -0,0 +1,198 @@ +#![allow(dead_code)] + +// use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; +// use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr}; +// use crate::os::yggdrasil::io::{AsFd, AsRawFd, BorrowedFd, RawFd}; +// use crate::sys::io::FileDesc; +// use crate::sys_common::{AsInner, FromInner, IntoInner}; +// use crate::time::Duration; +// +// pub use crate::sys::{cvt, cvt_r}; + +// pub use super::yggdrasil_rt::netc; + +mod tcp_listener; +mod tcp_stream; +mod udp; + +pub use tcp_listener::TcpListener; +pub use tcp_stream::TcpStream; +pub use udp::UdpSocket; + +use crate::net::SocketAddr; + +pub struct LookupHost(!); + +impl LookupHost { + pub fn port(&self) -> u16 { + todo!() + } +} + +impl Iterator for LookupHost { + type Item = SocketAddr; + + fn next(&mut self) -> Option { + todo!() + } +} + +impl TryFrom<&str> for LookupHost { + type Error = crate::io::Error; + + fn try_from(_s: &str) -> crate::io::Result { + todo!() + } +} + +impl<'a> TryFrom<(&'a str, u16)> for LookupHost { + type Error = crate::io::Error; + + fn try_from(_s: (&'a str, u16)) -> crate::io::Result { + todo!() + } +} + +// pub type wrlen_t = usize; + +// #[derive(Debug)] +// pub struct Socket(FileDesc); +// +// impl Socket { +// pub fn new(_addr: &SocketAddr, _ty: i32) -> io::Result { +// todo!() +// } +// +// pub fn connect_timeout(&self, _addr: &SocketAddr, _timeout: Duration) -> io::Result<()> { +// todo!() +// } +// +// pub fn set_linger(&self, _linger: Option) -> io::Result<()> { +// todo!() +// } +// +// pub fn read_buf(&self, _buf: BorrowedCursor<'_>) -> io::Result<()> { +// todo!() +// } +// +// pub fn linger(&self) -> io::Result> { +// todo!() +// } +// +// pub fn shutdown(&self, _how: Shutdown) -> io::Result<()> { +// todo!() +// } +// +// pub fn read(&self, _buf: &mut [u8]) -> io::Result { +// todo!() +// } +// +// pub fn accept( +// &self, +// _storage: *mut netc::sockaddr, +// _len: *mut netc::socklen_t, +// ) -> io::Result { +// todo!() +// } +// +// pub fn duplicate(&self) -> io::Result { +// todo!() +// } +// +// #[inline] +// pub fn is_read_vectored(&self) -> bool { +// todo!() +// } +// +// pub fn recv_from(&self, _buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { +// todo!() +// } +// +// pub fn write(&self, _buf: &[u8]) -> io::Result { +// todo!() +// } +// +// pub fn write_vectored(&self, _bufs: &[IoSlice<'_>]) -> io::Result { +// todo!() +// } +// +// pub fn is_write_vectored(&self) -> bool { +// todo!() +// } +// +// pub fn set_timeout(&self, _dur: Option, _kind: i32) -> io::Result<()> { +// todo!() +// } +// +// pub fn timeout(&self, _kind: i32) -> io::Result> { +// todo!() +// } +// +// pub fn set_nodelay(&self, _nodelay: bool) -> io::Result<()> { +// todo!() +// } +// +// pub fn nodelay(&self) -> io::Result { +// todo!() +// } +// +// pub fn take_error(&self) -> io::Result> { +// todo!() +// } +// +// pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> { +// todo!() +// } +// +// pub fn peek_from(&self, _buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { +// todo!() +// } +// +// pub fn peek(&self, _buf: &mut [u8]) -> io::Result { +// todo!() +// } +// +// pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { +// todo!() +// } +// +// pub fn as_raw(&self) -> RawFd { +// self.0.as_raw_fd() +// } +// } +// +// impl AsInner for Socket { +// fn as_inner(&self) -> &FileDesc { +// &self.0 +// } +// } +// +// impl IntoInner for Socket { +// fn into_inner(self) -> FileDesc { +// self.0 +// } +// } +// +// impl FromInner for Socket { +// fn from_inner(fd: FileDesc) -> Self { +// Self(fd) +// } +// } +// +// impl AsFd for Socket { +// fn as_fd(&self) -> BorrowedFd<'_> { +// self.0.as_fd() +// } +// } +// +// impl AsRawFd for Socket { +// fn as_raw_fd(&self) -> RawFd { +// self.0.as_raw_fd() +// } +// } +// +pub fn init() {} +// +// pub fn cvt_gai(_err: i32) -> io::Result<()> { +// unimplemented!("No networking support"); +// } diff --git a/library/std/src/sys/yggdrasil/net/tcp_listener.rs b/library/std/src/sys/yggdrasil/net/tcp_listener.rs new file mode 100644 index 00000000000..bdf4c1f3c4c --- /dev/null +++ b/library/std/src/sys/yggdrasil/net/tcp_listener.rs @@ -0,0 +1,49 @@ +use crate::io; +use crate::net::SocketAddr; + +use super::TcpStream; + +#[derive(Debug)] +pub struct TcpListener(!); + +impl TcpListener { + pub fn bind(_addr: io::Result<&SocketAddr>) -> io::Result { + todo!() + } + + pub fn socket_addr(&self) -> io::Result { + todo!() + } + + pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> { + todo!() + } + + pub fn duplicate(&self) -> io::Result { + todo!() + } + + pub fn set_ttl(&self, _ttl: u32) -> io::Result<()> { + todo!() + } + + pub fn ttl(&self) -> io::Result { + todo!() + } + + pub fn set_only_v6(&self, _only_v6: bool) -> io::Result<()> { + todo!() + } + + pub fn only_v6(&self) -> io::Result { + todo!() + } + + pub fn take_error(&self) -> io::Result> { + todo!() + } + + pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> { + todo!() + } +} diff --git a/library/std/src/sys/yggdrasil/net.rs b/library/std/src/sys/yggdrasil/net/tcp_stream.rs similarity index 50% rename from library/std/src/sys/yggdrasil/net.rs rename to library/std/src/sys/yggdrasil/net/tcp_stream.rs index 8b092556550..add6a14e6c1 100644 --- a/library/std/src/sys/yggdrasil/net.rs +++ b/library/std/src/sys/yggdrasil/net/tcp_stream.rs @@ -1,43 +1,36 @@ -#![allow(dead_code)] - use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; use crate::net::{Shutdown, SocketAddr}; -use crate::os::yggdrasil::io::{AsFd, AsRawFd, BorrowedFd, RawFd}; -use crate::sys::io::FileDesc; -use crate::sys_common::{AsInner, FromInner, IntoInner}; use crate::time::Duration; -pub use crate::sys::{cvt, cvt_r}; - -pub use super::yggdrasil_rt::netc; - -pub type wrlen_t = usize; - #[derive(Debug)] -pub struct Socket(FileDesc); +pub struct TcpStream(!); -impl Socket { - pub fn new(_addr: &SocketAddr, _ty: i32) -> io::Result { +impl TcpStream { + pub fn connect(_addr: io::Result<&SocketAddr>) -> io::Result { todo!() } - pub fn connect_timeout(&self, _addr: &SocketAddr, _timeout: Duration) -> io::Result<()> { + pub fn connect_timeout(_addr: &SocketAddr, _timeout: Duration) -> io::Result { todo!() } - pub fn set_linger(&self, _linger: Option) -> io::Result<()> { + pub fn set_read_timeout(&self, _dur: Option) -> io::Result<()> { todo!() } - pub fn read_buf(&self, _buf: BorrowedCursor<'_>) -> io::Result<()> { + pub fn set_write_timeout(&self, _dur: Option) -> io::Result<()> { todo!() } - pub fn linger(&self) -> io::Result> { + pub fn read_timeout(&self) -> io::Result> { todo!() } - pub fn shutdown(&self, _how: Shutdown) -> io::Result<()> { + pub fn write_timeout(&self) -> io::Result> { + todo!() + } + + pub fn peek(&self, _buf: &mut [u8]) -> io::Result { todo!() } @@ -45,15 +38,11 @@ impl Socket { todo!() } - pub fn accept( - &self, - _storage: *mut netc::sockaddr, - _len: *mut netc::socklen_t, - ) -> io::Result { + pub fn read_buf(&self, _buf: BorrowedCursor<'_>) -> io::Result<()> { todo!() } - pub fn duplicate(&self) -> io::Result { + pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { todo!() } @@ -62,10 +51,6 @@ impl Socket { todo!() } - pub fn recv_from(&self, _buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { - todo!() - } - pub fn write(&self, _buf: &[u8]) -> io::Result { todo!() } @@ -74,15 +59,32 @@ impl Socket { todo!() } + #[inline] pub fn is_write_vectored(&self) -> bool { todo!() } - pub fn set_timeout(&self, _dur: Option, _kind: i32) -> io::Result<()> { + pub fn peer_addr(&self) -> io::Result { todo!() } - pub fn timeout(&self, _kind: i32) -> io::Result> { + pub fn socket_addr(&self) -> io::Result { + todo!() + } + + pub fn shutdown(&self, _how: Shutdown) -> io::Result<()> { + todo!() + } + + pub fn duplicate(&self) -> io::Result { + todo!() + } + + pub fn set_linger(&self, _linger: Option) -> io::Result<()> { + todo!() + } + + pub fn linger(&self) -> io::Result> { todo!() } @@ -94,6 +96,14 @@ impl Socket { todo!() } + pub fn set_ttl(&self, _ttl: u32) -> io::Result<()> { + todo!() + } + + pub fn ttl(&self) -> io::Result { + todo!() + } + pub fn take_error(&self) -> io::Result> { todo!() } @@ -101,58 +111,4 @@ impl Socket { pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> { todo!() } - - pub fn peek_from(&self, _buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { - todo!() - } - - pub fn peek(&self, _buf: &mut [u8]) -> io::Result { - todo!() - } - - pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { - todo!() - } - - pub fn as_raw(&self) -> RawFd { - self.0.as_raw_fd() - } -} - -impl AsInner for Socket { - fn as_inner(&self) -> &FileDesc { - &self.0 - } -} - -impl IntoInner for Socket { - fn into_inner(self) -> FileDesc { - self.0 - } -} - -impl FromInner for Socket { - fn from_inner(fd: FileDesc) -> Self { - Self(fd) - } -} - -impl AsFd for Socket { - fn as_fd(&self) -> BorrowedFd<'_> { - self.0.as_fd() - } -} - -impl AsRawFd for Socket { - fn as_raw_fd(&self) -> RawFd { - self.0.as_raw_fd() - } -} - -pub fn init() { - todo!(); -} - -pub fn cvt_gai(_err: i32) -> io::Result<()> { - unimplemented!("No networking support"); } diff --git a/library/std/src/sys/yggdrasil/net/udp.rs b/library/std/src/sys/yggdrasil/net/udp.rs new file mode 100644 index 00000000000..b7b6435732b --- /dev/null +++ b/library/std/src/sys/yggdrasil/net/udp.rs @@ -0,0 +1,192 @@ +use crate::io; +use crate::mem::MaybeUninit; +use crate::net::{Ipv4Addr, Ipv6Addr, SocketAddr}; +use crate::os::fd::{AsRawFd, FromRawFd, RawFd}; +use crate::sys::{cvt_io, io::FileDesc}; +use crate::sys_common::{AsInner, IntoInner}; +use crate::time::Duration; + +use yggdrasil_rt::{ + net::{SocketOption, SocketType}, + sys as syscall, +}; + +#[derive(Debug)] +pub struct UdpSocket { + fd: FileDesc, + local: SocketAddr, + remote: Option, +} + +impl UdpSocket { + pub fn bind(listen: io::Result<&SocketAddr>) -> io::Result { + let listen = listen?; + let raw = cvt_io(unsafe { syscall::bind_socket(listen, SocketType::UdpPacket) })?; + let inner = unsafe { FileDesc::from_raw_fd(raw) }; + Ok(Self { fd: inner, local: *listen, remote: None }) + } + + pub fn connect(&self, _remote: io::Result<&SocketAddr>) -> io::Result<()> { + todo!() + } + + pub fn peer_addr(&self) -> io::Result { + todo!() + } + + pub fn socket_addr(&self) -> io::Result { + todo!() + } + + pub fn recv(&self, _buffer: &mut [u8]) -> io::Result { + todo!() + } + + pub fn recv_from(&self, buffer: &mut [u8]) -> io::Result<(usize, SocketAddr)> { + let mut remote = MaybeUninit::uninit(); + let len = + cvt_io(unsafe { syscall::receive_from(self.fd.as_raw_fd(), buffer, &mut remote) })?; + Ok((len, unsafe { remote.assume_init() })) + } + + pub fn send(&self, _buffer: &[u8]) -> io::Result { + todo!() + } + + pub fn send_to(&self, buffer: &[u8], dst: &SocketAddr) -> io::Result { + let dst = Some(*dst); + cvt_io(unsafe { syscall::send_to(self.fd.as_raw_fd(), buffer, &dst) }) + } + + pub fn peek(&self, _buf: &mut [u8]) -> io::Result { + todo!() + } + + pub fn peek_from(&self, _buffer: &mut [u8]) -> io::Result<(usize, SocketAddr)> { + todo!() + } + + pub fn duplicate(&self) -> io::Result { + todo!() + } + + pub fn set_read_timeout(&self, _dur: Option) -> io::Result<()> { + todo!() + } + + pub fn read_timeout(&self) -> io::Result> { + todo!() + } + + pub fn set_write_timeout(&self, _dur: Option) -> io::Result<()> { + todo!() + } + + pub fn write_timeout(&self) -> io::Result> { + todo!() + } + + pub fn set_ttl(&self, _ttl: u32) -> io::Result<()> { + todo!() + } + + pub fn ttl(&self) -> io::Result { + todo!() + } + + pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> { + todo!() + } + + pub fn set_broadcast(&self, broadcast: bool) -> io::Result<()> { + cvt_io(unsafe { + syscall::set_socket_option(self.fd.as_raw_fd(), &SocketOption::Broadcast(broadcast)) + }) + } + + pub fn broadcast(&self) -> io::Result { + let mut value = SocketOption::Broadcast(false); + cvt_io(unsafe { syscall::get_socket_option(self.fd.as_raw_fd(), &mut value) })?; + let SocketOption::Broadcast(value) = value else { + unreachable!(); + }; + Ok(value) + } + + pub fn set_multicast_loop_v4(&self, _loop_v4: bool) -> io::Result<()> { + todo!() + } + + pub fn multicast_loop_v4(&self) -> io::Result { + todo!() + } + + pub fn set_multicast_ttl_v4(&self, _ttl: u32) -> io::Result<()> { + todo!() + } + + pub fn multicast_ttl_v4(&self) -> io::Result { + todo!() + } + + pub fn set_multicast_loop_v6(&self, _loop_v6: bool) -> io::Result<()> { + todo!() + } + + pub fn multicast_loop_v6(&self) -> io::Result { + todo!() + } + + pub fn join_multicast_v6(&self, _multiaddr: &Ipv6Addr, _interface: u32) -> io::Result<()> { + todo!() + } + + pub fn join_multicast_v4( + &self, + _multiaddr: &Ipv4Addr, + _interface: &Ipv4Addr, + ) -> io::Result<()> { + todo!() + } + + pub fn leave_multicast_v6(&self, _multiaddr: &Ipv6Addr, _interface: u32) -> io::Result<()> { + todo!() + } + + pub fn leave_multicast_v4( + &self, + _multiaddr: &Ipv4Addr, + _interface: &Ipv4Addr, + ) -> io::Result<()> { + todo!() + } + + pub fn take_error(&self) -> io::Result> { + todo!() + } +} + +impl IntoInner for UdpSocket { + fn into_inner(self) -> FileDesc { + self.fd + } +} + +impl AsInner for UdpSocket { + fn as_inner(&self) -> &FileDesc { + &self.fd + } +} + +impl AsRawFd for UdpSocket { + fn as_raw_fd(&self) -> RawFd { + self.fd.as_raw_fd() + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRawFd for crate::net::UdpSocket { + fn as_raw_fd(&self) -> RawFd { + self.as_inner().as_raw_fd() + } +} diff --git a/library/std/src/sys_common/mod.rs b/library/std/src/sys_common/mod.rs index e9c727cbbd1..446542db1c3 100644 --- a/library/std/src/sys_common/mod.rs +++ b/library/std/src/sys_common/mod.rs @@ -45,6 +45,7 @@ cfg_if::cfg_if! { cfg_if::cfg_if! { if #[cfg(any(target_os = "l4re", feature = "restricted-std", + target_os = "yggdrasil", all(target_family = "wasm", not(target_os = "emscripten")), all(target_vendor = "fortanix", target_env = "sgx")))] { pub use crate::sys::net;