mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 02:46:47 +00:00
49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
use alloc::sync::Arc;
|
|
use smoltcp;
|
|
use system_error::SystemError::{self, *};
|
|
|
|
use inet::{TcpSocket, UdpSocket};
|
|
|
|
// use crate::net::syscall_util::SysArgSocketType;
|
|
use crate::net::socket::*;
|
|
|
|
fn create_inet_socket(
|
|
socket_type: PSOCK,
|
|
protocol: smoltcp::wire::IpProtocol,
|
|
) -> Result<Arc<dyn Socket>, SystemError> {
|
|
// log::debug!("type: {:?}, protocol: {:?}", socket_type, protocol);
|
|
use smoltcp::wire::IpProtocol::*;
|
|
match socket_type {
|
|
PSOCK::Datagram => match protocol {
|
|
HopByHop | Udp => {
|
|
return Ok(UdpSocket::new(false));
|
|
}
|
|
_ => {
|
|
return Err(EPROTONOSUPPORT);
|
|
}
|
|
},
|
|
PSOCK::Stream => match protocol {
|
|
HopByHop | Tcp => {
|
|
return Ok(TcpSocket::new(false));
|
|
}
|
|
_ => {
|
|
return Err(EPROTONOSUPPORT);
|
|
}
|
|
},
|
|
PSOCK::Raw => {
|
|
todo!("raw")
|
|
}
|
|
_ => {
|
|
return Err(EPROTONOSUPPORT);
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct Inet;
|
|
impl family::Family for Inet {
|
|
fn socket(stype: PSOCK, protocol: u32) -> Result<Arc<Inode>, SystemError> {
|
|
let socket = create_inet_socket(stype, smoltcp::wire::IpProtocol::from(protocol as u8))?;
|
|
Ok(Inode::new(socket))
|
|
}
|
|
}
|