pub fn decode(buf: &[u8], destination: Ipv6Addr) -> Result<Self> {
        log::info!("{:?}", buf);
        // let ipv6_packet = ipv6::Ipv6Packet::new(buf)
        //     .ok_or_else(|| SurgeError::from(MalformedPacketError::NotIpv4Packet))?;
        // let payload = ipv6_packet.payload();
        let icmpv6_packet = icmpv6::Icmpv6Packet::new(buf)
            .ok_or_else(|| SurgeError::from(MalformedPacketError::NotIcmpv6Packet))?;
        log::info!("{:?}", &icmpv6_packet);
        log::info!("{:?}", &icmpv6_packet.get_icmpv6_type());
        log::info!("{:?}", icmpv6::Icmpv6Types::EchoReply);
        let icmpv6_payload = icmpv6_packet.payload();
        match icmpv6_packet.get_icmpv6_type() {
            icmpv6::Icmpv6Types::EchoRequest => Err(SurgeError::EchoRequestPacket),
            icmpv6::Icmpv6Types::EchoReply => {
                let identifier = u16::from_be_bytes(icmpv6_payload[0..2].try_into().unwrap());
                let sequence = u16::from_be_bytes(icmpv6_payload[2..4].try_into().unwrap());
                let mut packet = Icmpv6Packet::default();
                packet
                    .source(destination)
                    .destination(Ipv6Addr::LOCALHOST)
                    .max_hop_limit(0)
                    .icmpv6_type(icmpv6_packet.get_icmpv6_type())
                    .icmpv6_code(icmpv6_packet.get_icmpv6_code())
                    .size(icmpv6_packet.packet().len())
                    .real_dest(destination)
                    .identifier(identifier)
                    .sequence(sequence);
                Ok(packet)
            }
            _ => {
                // ipv6 header(40) + icmpv6 echo header(4)
                log::info!("{:?}", icmpv6_payload);
                let identifier = u16::from_be_bytes(icmpv6_payload[44..46].try_into().unwrap());
                let sequence = u16::from_be_bytes(icmpv6_payload[46..48].try_into().unwrap());
                let mut packet = Icmpv6Packet::default();
                packet
                    .source(destination)
                    .destination(destination)
                    .max_hop_limit(0)
                    .icmpv6_type(icmpv6_packet.get_icmpv6_type())
                    .icmpv6_code(icmpv6_packet.get_icmpv6_code())
                    .size(icmpv6_packet.packet_size())
                    .identifier(identifier)
                    .sequence(sequence);
                Ok(packet)
            }
        }
    }
/// Decode into icmpv6 packet from the socket message.
Decode into icmpv6 packet from the socket message.
Decode into icmpv6 packet from the socket message .
pub fn decode(buf: &[u8], destination: Ipv6Addr) -> Result<Self> {
        log::info!("{:?}", buf);
        // let ipv6_packet = ipv6::Ipv6Packet::new(buf)
        //     .ok_or_else(|| SurgeError::from(MalformedPacketError::NotIpv4Packet))?;
        // let payload = ipv6_packet.payload();
        let icmpv6_packet = icmpv6::Icmpv6Packet::new(buf)
            .ok_or_else(|| SurgeError::from(MalformedPacketError::NotIcmpv6Packet))?;
        log::info!("{:?}", &icmpv6_packet);
        log::info!("{:?}", &icmpv6_packet.get_icmpv6_type());
        log::info!("{:?}", icmpv6::Icmpv6Types::EchoReply);
        let icmpv6_payload = icmpv6_packet.payload();
        match icmpv6_packet.get_icmpv6_type() {
            icmpv6::Icmpv6Types::EchoRequest => Err(SurgeError::EchoRequestPacket),
            icmpv6::Icmpv6Types::EchoReply => {
                let identifier = u16::from_be_bytes(icmpv6_payload[0..2].try_into().unwrap());
                let sequence = u16::from_be_bytes(icmpv6_payload[2..4].try_into().unwrap());
                let mut packet = Icmpv6Packet::default();
                packet
                    .source(destination)
                    .destination(Ipv6Addr::LOCALHOST)
                    .max_hop_limit(0)
                    .icmpv6_type(icmpv6_packet.get_icmpv6_type())
                    .icmpv6_code(icmpv6_packet.get_icmpv6_code())
                    .size(icmpv6_packet.packet().len())
                    .real_dest(destination)
                    .identifier(identifier)
                    .sequence(sequence);
                Ok(packet)
            }
            _ => {
                // ipv6 header(40) + icmpv6 echo header(4)
                log::info!("{:?}", icmpv6_payload);
                let identifier = u16::from_be_bytes(icmpv6_payload[44..46].try_into().unwrap());
                let sequence = u16::from_be_bytes(icmpv6_payload[46..48].try_into().unwrap());
                let mut packet = Icmpv6Packet::default();
                packet
                    .source(destination)
                    .destination(destination)
                    .max_hop_limit(0)
                    .icmpv6_type(icmpv6_packet.get_icmpv6_type())
                    .icmpv6_code(icmpv6_packet.get_icmpv6_code())
                    .size(icmpv6_packet.packet_size())
                    .identifier(identifier)
                    .sequence(sequence);
                Ok(packet)
            }
        }
    }
pub fn decode ( buf : & [ u8 ] , destination : Ipv6Addr ) -> Result < Self > { log :: info ! ( " " buf ) ; // let ipv6_packet = ipv6::Ipv6Packet::new(buf) //     .ok_or_else(|| SurgeError::from(MalformedPacketError::NotIpv4Packet))?; // let payload = ipv6_packet.payload(); let icmpv6_packet = icmpv6 :: Icmpv6Packet :: new ( buf ) . ok_or_else ( | | SurgeError :: from ( MalformedPacketError :: NotIcmpv6Packet ) ) ? ; log :: info ! ( " " icmpv6_packet ) ; log :: info ! ( " " icmpv6_packet get_icmpv6_type ( ) ) ; log :: info ! ( " " icmpv6 Icmpv6Types EchoReply ) ; let icmpv6_payload = icmpv6_packet . payload ( ) ; match icmpv6_packet . get_icmpv6_type ( ) { icmpv6 :: Icmpv6Types :: EchoRequest => Err ( SurgeError :: EchoRequestPacket ) , icmpv6 :: Icmpv6Types :: EchoReply => { let identifier = u16 :: from_be_bytes ( icmpv6_payload [ 0 .. 2 ] . try_into ( ) . unwrap ( ) ) ; let sequence = u16 :: from_be_bytes ( icmpv6_payload [ 2 .. 4 ] . try_into ( ) . unwrap ( ) ) ; let mut packet = Icmpv6Packet :: default ( ) ; packet . source ( destination ) . destination ( Ipv6Addr :: LOCALHOST ) . max_hop_limit ( 0 ) . icmpv6_type ( icmpv6_packet . get_icmpv6_type ( ) ) . icmpv6_code ( icmpv6_packet . get_icmpv6_code ( ) ) . size ( icmpv6_packet . packet ( ) . len ( ) ) . real_dest ( destination ) . identifier ( identifier ) . sequence ( sequence ) ; Ok ( packet ) } _ => { // ipv6 header(40) + icmpv6 echo header(4) log :: info ! ( " " icmpv6_payload ) ; let identifier = u16 :: from_be_bytes ( icmpv6_payload [ 44 .. 46 ] . try_into ( ) . unwrap ( ) ) ; let sequence = u16 :: from_be_bytes ( icmpv6_payload [ 46 .. 48 ] . try_into ( ) . unwrap ( ) ) ; let mut packet = Icmpv6Packet :: default ( ) ; packet . source ( destination ) . destination ( destination ) . max_hop_limit ( 0 ) . icmpv6_type ( icmpv6_packet . get_icmpv6_type ( ) ) . icmpv6_code ( icmpv6_packet . get_icmpv6_code ( ) ) . size ( icmpv6_packet . packet_size ( ) ) . identifier ( identifier ) . sequence ( sequence ) ; Ok ( packet ) } } }
Decode into icmpv6 packet from the socket message.
Decode into icmpv6 packet from the socket message .
buf
&[u8]
destination
Ipv6Addr