UdpLayer

Struct UdpLayer 

Source
pub struct UdpLayer {
    port_map: RwLock<BTreeMap<u16, Weak<UdpSocket>>>,
    next_ephemeral_port: Mutex<u16>,
    stats: RwLock<NetworkLayerStats>,
    self_weak: Weak<UdpLayer>,
}
Expand description

UDP layer

Manages UDP port bindings and handles UDP datagrams.

Fields§

§port_map: RwLock<BTreeMap<u16, Weak<UdpSocket>>>

Port-to-socket mapping for receiving datagrams

§next_ephemeral_port: Mutex<u16>

Port allocation (ephemeral ports start from 49152)

§stats: RwLock<NetworkLayerStats>

Statistics

§self_weak: Weak<UdpLayer>

Implementations§

Source§

impl UdpLayer

Source

pub fn new() -> Arc<Self>

Create a new UDP layer

Source

pub fn init(network_manager: &NetworkManager)

Initialize and register the UDP layer with NetworkManager

Registers with NetworkManager and registers itself with Ipv4Layer for protocol number 17 (UDP).

§Panics

Panics if Ipv4Layer is not registered (must be initialized first).

Source

pub fn create_socket(&self) -> Arc<UdpSocket>

Create a new UDP socket

Source

pub fn allocate_port(&self) -> u16

Allocate an ephemeral port

Source

pub fn register_port(&self, port: u16, socket: Weak<UdpSocket>)

Register a socket for a specific port

Source

pub fn unregister_socket(&self, port: u16, socket: &Weak<UdpSocket>)

Unregister a specific socket from a port

Only removes the port entry if the registered socket matches.

Source

pub fn find_socket(&self, port: u16) -> Option<Arc<UdpSocket>>

Find socket for a destination port

Source

pub fn configure_socket( &self, socket: Weak<UdpSocket>, config: &SocketConfig, ) -> Result<(), SocketError>

Configure a UDP socket (bind)

Source

pub fn send_datagram( &self, socket: &UdpSocket, dest_ip: [u8; 4], dest_port: u16, data: Vec<u8>, ) -> Result<(), SocketError>

Send a UDP datagram

Source

pub fn receive_datagram( &self, src_ip: Ipv4Address, src_port: u16, dst_port: u16, data: Vec<u8>, )

Receive a UDP datagram

Source§

impl UdpLayer

Source

pub fn receive_packet( &self, src_ip: Ipv4Address, _dst_ip: Ipv4Address, packet: &[u8], ) -> Result<(), SocketError>

Receive a UDP datagram

Trait Implementations§

Source§

impl NetworkLayer for UdpLayer

Source§

fn register_protocol(&self, _proto_num: u16, _handler: Arc<dyn NetworkLayer>)

Register a protocol handler for this layer Read more
Source§

fn send( &self, _packet: &[u8], _context: &LayerContext, _next_layers: &[Arc<dyn NetworkLayer>], ) -> Result<(), SocketError>

Send a packet through this layer Read more
Source§

fn receive( &self, packet: &[u8], context: Option<&LayerContext>, ) -> Result<(), SocketError>

Receive and process a packet at this layer Read more
Source§

fn name(&self) -> &'static str

Get layer name for debugging
Source§

fn stats(&self) -> NetworkLayerStats

Get layer statistics
Source§

fn as_any(&self) -> &dyn Any

Cast to Any for safe downcasting
Source§

fn configure( &self, config: &SocketConfig, next_layers: &[Arc<dyn NetworkLayer>], ) -> Result<(), SocketError>

Configure this layer with socket-specific parameters Read more

Auto Trait Implementations§

§

impl !Freeze for UdpLayer

§

impl !RefUnwindSafe for UdpLayer

§

impl Send for UdpLayer

§

impl Sync for UdpLayer

§

impl Unpin for UdpLayer

§

impl !UnwindSafe for UdpLayer

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.