fn decode_icmpv4(addr: IpAddr, buf: &[u8]) -> Result<EchoReply> {
    let ipv4 = Ipv4Packet::new(buf)
        .ok_or_else(|| SurgeError::from(MalformedPacketError::NotIpv4Packet))?;
    let payload = ipv4.payload();
    let icmp_packet = IcmpPacket::new(payload)
        .ok_or_else(|| SurgeError::from(MalformedPacketError::NotIcmpPacket))?;
    let ty = icmp_packet.get_icmp_type();
    if ty != IcmpTypes::EchoReply {
        trace!(
            "type={:?},code={:?},src={},dst={}",
            ty,
            icmp_packet.get_icmp_code(),
            ipv4.get_source(),
            ipv4.get_destination()
        );
        return Err(SurgeError::NotEchoReply(ty));
    }

    let echo_reply_packet = EchoReplyPacket::new(payload).unwrap();
    Ok(EchoReply {
        ttl: Some(ipv4.get_ttl()),
        source: addr,
        sequence: echo_reply_packet.get_sequence_number(),
        identifier: echo_reply_packet.get_identifier(),
        // TODO: When `EchoReplyPacket::packet_size()` can directly use.
        size: echo_reply_packet.packet().len(),
    })
}
/// Decodes an ICMPv4 packet received from an IPv4 raw socket
Decodes an ICMPv4 packet received from an IPv4 raw socket
Decodes an ICMPv4 packet received from an IPv4 raw socket
fn decode_icmpv4(addr: IpAddr, buf: &[u8]) -> Result<EchoReply> {
    let ipv4 = Ipv4Packet::new(buf)
        .ok_or_else(|| SurgeError::from(MalformedPacketError::NotIpv4Packet))?;
    let payload = ipv4.payload();
    let icmp_packet = IcmpPacket::new(payload)
        .ok_or_else(|| SurgeError::from(MalformedPacketError::NotIcmpPacket))?;
    let ty = icmp_packet.get_icmp_type();
    if ty != IcmpTypes::EchoReply {
        trace!(
            "type={:?},code={:?},src={},dst={}",
            ty,
            icmp_packet.get_icmp_code(),
            ipv4.get_source(),
            ipv4.get_destination()
        );
        return Err(SurgeError::NotEchoReply(ty));
    }
    let echo_reply_packet = EchoReplyPacket::new(payload).unwrap();
    Ok(EchoReply {
        ttl: Some(ipv4.get_ttl()),
        source: addr,
        sequence: echo_reply_packet.get_sequence_number(),
        identifier: echo_reply_packet.get_identifier(),
        // TODO: When `EchoReplyPacket::packet_size()` can directly use.
        size: echo_reply_packet.packet().len(),
    })
}
fn decode_icmpv4 ( addr : IpAddr , buf : & [ u8 ] ) -> Result < EchoReply > { let ipv4 = Ipv4Packet :: new ( buf ) . ok_or_else ( | | SurgeError :: from ( MalformedPacketError :: NotIpv4Packet ) ) ? ; let payload = ipv4 . payload ( ) ; let icmp_packet = IcmpPacket :: new ( payload ) . ok_or_else ( | | SurgeError :: from ( MalformedPacketError :: NotIcmpPacket ) ) ? ; let ty = icmp_packet . get_icmp_type ( ) ; if ty != IcmpTypes :: EchoReply { trace ! ( " " ty icmp_packet get_icmp_code ( ) ipv4 get_source ( ) ipv4 get_destination ( ) ) ; return Err ( SurgeError :: NotEchoReply ( ty ) ) ; } let echo_reply_packet = EchoReplyPacket :: new ( payload ) . unwrap ( ) ; Ok ( EchoReply { ttl : Some ( ipv4 . get_ttl ( ) ) , source : addr , sequence : echo_reply_packet . get_sequence_number ( ) , identifier : echo_reply_packet . get_identifier ( ) , // TODO: When `EchoReplyPacket::packet_size()` can directly use. size : echo_reply_packet . packet ( ) . len ( ) , } ) }
Decodes an ICMPv4 packet received from an IPv4 raw socket
Decodes an ICMPv4 packet received from an IPv4 raw socket
addr
IpAddr
buf
&[u8]
addr
IpAddr
buf
&[u8]