80 lines
2.3 KiB
Rust
80 lines
2.3 KiB
Rust
//! Defines data types for network operations
|
|
|
|
#[cfg(any(feature = "alloc", feature = "rustc_std_alloc"))]
|
|
pub mod dns;
|
|
#[cfg(feature = "alloc")]
|
|
pub mod netconfig;
|
|
|
|
pub mod protocols;
|
|
pub mod types;
|
|
|
|
use core::time::Duration;
|
|
|
|
pub use crate::generated::SocketType;
|
|
|
|
pub use types::{
|
|
ip_addr::{IpAddr, Ipv4Addr, Ipv6Addr},
|
|
socket_addr::{SocketAddr, SocketAddrV4, SocketAddrV6},
|
|
subnet_addr::{SubnetAddr, SubnetV4Addr},
|
|
MacAddress,
|
|
};
|
|
|
|
// primitive_enum! {
|
|
// #[doc = "Defines a type of a socket"]
|
|
// pub enum SocketType: u32 {
|
|
// }
|
|
// }
|
|
|
|
/// Describes a method to query an interface
|
|
#[derive(Clone, Debug)]
|
|
pub enum SocketInterfaceQuery<'a> {
|
|
/// Query by name
|
|
ByName(&'a str),
|
|
/// Query by id
|
|
ById(u32),
|
|
}
|
|
|
|
/// Describes a socket operation parameter
|
|
#[derive(Clone, Debug)]
|
|
pub enum SocketOption<'a> {
|
|
/// Whether the socket is broadcast
|
|
Broadcast(bool),
|
|
/// Time-to-Live parameter
|
|
Ttl(u32),
|
|
/// Bind the socket to a specific interface
|
|
BindInterface(SocketInterfaceQuery<'a>),
|
|
/// Unbind the socket from an interface
|
|
UnbindInterface,
|
|
/// (Read-only) Hardware address of the bound interface
|
|
BoundHardwareAddress(MacAddress),
|
|
/// If set, reception will return [crate::error::Error::WouldBlock] if the socket has
|
|
/// no data in its queue/buffer.
|
|
NonBlocking(bool),
|
|
/// If set, the socket will be restricted to IPv6 only.
|
|
Ipv6Only(bool),
|
|
/// If not [None], receive operations will have a time limit set before returning an error.
|
|
RecvTimeout(Option<Duration>),
|
|
/// If not [None], send operations will have a time limit set before returning an error.
|
|
SendTimeout(Option<Duration>),
|
|
/// (UDP) If set, allows multicast packets to be looped back to local host.
|
|
MulticastLoopV4(bool),
|
|
/// (UDP) If set, allows multicast packets to be looped back to local host.
|
|
MulticastLoopV6(bool),
|
|
/// (UDP) Time-to-Live for IPv4 multicast packets.
|
|
MulticastTtlV4(u32),
|
|
/// (TCP) If set, disables any internal buffering for the socket.
|
|
NoDelay(bool),
|
|
}
|
|
|
|
impl<'a> From<&'a str> for SocketInterfaceQuery<'a> {
|
|
fn from(value: &'a str) -> Self {
|
|
Self::ByName(value)
|
|
}
|
|
}
|
|
|
|
impl From<u32> for SocketInterfaceQuery<'_> {
|
|
fn from(value: u32) -> Self {
|
|
Self::ById(value)
|
|
}
|
|
}
|