IcmpLayer

Struct IcmpLayer 

Source
pub struct IcmpLayer {
    stats: RwLock<NetworkLayerStats>,
    sockets: RwLock<BTreeMap<u16, Weak<IcmpSocket>>>,
    next_identifier: AtomicU16,
    self_weak: Weak<IcmpLayer>,
}
Expand description

ICMP layer

Handles ICMP messages for network diagnostics.

Fields§

§stats: RwLock<NetworkLayerStats>

Statistics

§sockets: RwLock<BTreeMap<u16, Weak<IcmpSocket>>>

ICMP sockets by identifier

§next_identifier: AtomicU16

Identifier allocator

§self_weak: Weak<IcmpLayer>

Implementations§

Source§

impl IcmpLayer

Source

fn compute_checksum(packet: &[u8]) -> u16

Source

fn verify_checksum(packet: &[u8]) -> bool

Source

pub fn new() -> Arc<Self>

Create a new ICMP layer

Source

pub fn init(network_manager: &NetworkManager)

Initialize and register the ICMP layer with NetworkManager

Registers with NetworkManager and registers itself with Ipv4Layer for protocol number 1 (ICMP).

§Panics

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

Source

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

Source

pub fn send_ping_request( &self, dest_ip: Ipv4Address, identifier: u16, sequence: u16, data: &[u8], next_layers: &[Arc<dyn NetworkLayer>], ) -> Result<(), SocketError>

Send an ICMP Echo Request (ping)

Source

pub fn send_ping_reply( &self, dest_ip: Ipv4Address, identifier: u16, sequence: u16, data: &[u8], next_layers: &[Arc<dyn NetworkLayer>], ) -> Result<(), SocketError>

Send an ICMP Echo Reply

Source

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

Process received ICMP packet

Source

fn deliver_echo_reply( &self, identifier: u16, payload: Vec<u8>, src_ip: Ipv4Address, sequence: u16, )

Trait Implementations§

Source§

impl NetworkLayer for IcmpLayer

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 IcmpLayer

§

impl !RefUnwindSafe for IcmpLayer

§

impl Send for IcmpLayer

§

impl Sync for IcmpLayer

§

impl Unpin for IcmpLayer

§

impl !UnwindSafe for IcmpLayer

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.