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: AtomicU16Identifier allocator
self_weak: Weak<IcmpLayer>Implementations§
Source§impl IcmpLayer
impl IcmpLayer
fn compute_checksum(packet: &[u8]) -> u16
fn verify_checksum(packet: &[u8]) -> bool
Sourcepub fn init(network_manager: &NetworkManager)
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).
pub fn create_socket(&self) -> Arc<IcmpSocket>
Sourcepub fn send_ping_request(
&self,
dest_ip: Ipv4Address,
identifier: u16,
sequence: u16,
data: &[u8],
next_layers: &[Arc<dyn NetworkLayer>],
) -> Result<(), SocketError>
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)
Sourcepub fn send_ping_reply(
&self,
dest_ip: Ipv4Address,
identifier: u16,
sequence: u16,
data: &[u8],
next_layers: &[Arc<dyn NetworkLayer>],
) -> Result<(), SocketError>
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
Sourcepub fn receive_packet(
&self,
packet: &[u8],
src_ip: Ipv4Address,
dst_ip: Ipv4Address,
) -> Result<(), SocketError>
pub fn receive_packet( &self, packet: &[u8], src_ip: Ipv4Address, dst_ip: Ipv4Address, ) -> Result<(), SocketError>
Process received ICMP packet
fn deliver_echo_reply( &self, identifier: u16, payload: Vec<u8>, src_ip: Ipv4Address, sequence: u16, )
Trait Implementations§
Source§impl NetworkLayer for IcmpLayer
impl NetworkLayer for IcmpLayer
Source§fn register_protocol(&self, _proto_num: u16, _handler: Arc<dyn NetworkLayer>)
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>
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>
fn receive( &self, _packet: &[u8], _context: Option<&LayerContext>, ) -> Result<(), SocketError>
Receive and process a packet at this layer Read more
Source§fn stats(&self) -> NetworkLayerStats
fn stats(&self) -> NetworkLayerStats
Get layer statistics
Source§fn configure(
&self,
config: &SocketConfig,
next_layers: &[Arc<dyn NetworkLayer>],
) -> Result<(), SocketError>
fn configure( &self, config: &SocketConfig, next_layers: &[Arc<dyn NetworkLayer>], ) -> Result<(), SocketError>
Configure this layer with socket-specific parameters Read more