fn decode_packet(
        mut packet_bytes: &[u8],
    ) -> Result<(Ipv6Proto, Ipv6Addr, Ipv6Addr, Option<NonZeroU16>, Option<NonZeroU16>), Error>
    {
        let packet =
            Ipv6Packet::parse(&mut packet_bytes, ()).context("failed to parse IPv6 packet")?;

        let proto = packet.proto();
        let src_ip = packet.src_ip().ipv6_bytes().into();
        let dst_ip = packet.dst_ip().ipv6_bytes().into();

        let (src_port, dst_port) = match packet.proto() {
            Ipv6Proto::Proto(IpProto::Tcp) => {
                let args = TcpParseArgs::new(packet.src_ip(), packet.dst_ip());
                let tcp = TcpSegment::parse(&mut packet_bytes, args)
                    .context("failed to parse TCP segment")?;
                (Some(tcp.src_port()), Some(tcp.dst_port()))
            }
            Ipv6Proto::Proto(IpProto::Udp) => {
                let args = UdpParseArgs::new(packet.src_ip(), packet.dst_ip());
                let udp = UdpPacket::parse(&mut packet_bytes, args)
                    .context("failed to parse UDP packet")?;
                (udp.src_port(), Some(udp.dst_port()))
            }
            _ => (None, None),
        };

        Ok((proto, src_ip, dst_ip, src_port, dst_port))
    }
/// Decodes the protocol, source address, destination address, source port,
/// destination port
Decodes the protocol, source address, destination address, source port,
destination port
Decodes the protocol source address destination address source port destination port
fn decode_packet(
        mut packet_bytes: &[u8],
    ) -> Result<(Ipv6Proto, Ipv6Addr, Ipv6Addr, Option<NonZeroU16>, Option<NonZeroU16>), Error>
    {
        let packet =
            Ipv6Packet::parse(&mut packet_bytes, ()).context("failed to parse IPv6 packet")?;
        let proto = packet.proto();
        let src_ip = packet.src_ip().ipv6_bytes().into();
        let dst_ip = packet.dst_ip().ipv6_bytes().into();
        let (src_port, dst_port) = match packet.proto() {
            Ipv6Proto::Proto(IpProto::Tcp) => {
                let args = TcpParseArgs::new(packet.src_ip(), packet.dst_ip());
                let tcp = TcpSegment::parse(&mut packet_bytes, args)
                    .context("failed to parse TCP segment")?;
                (Some(tcp.src_port()), Some(tcp.dst_port()))
            }
            Ipv6Proto::Proto(IpProto::Udp) => {
                let args = UdpParseArgs::new(packet.src_ip(), packet.dst_ip());
                let udp = UdpPacket::parse(&mut packet_bytes, args)
                    .context("failed to parse UDP packet")?;
                (udp.src_port(), Some(udp.dst_port()))
            }
            _ => (None, None),
        };
        Ok((proto, src_ip, dst_ip, src_port, dst_port))
    }
fn decode_packet ( mut packet_bytes : & [ u8 ] , ) -> Result < ( Ipv6Proto , Ipv6Addr , Ipv6Addr , Option < NonZeroU16 > , Option < NonZeroU16 > ) , Error > { let packet = Ipv6Packet :: parse ( & mut packet_bytes , ( ) ) . context ( " " ) ? ; let proto = packet . proto ( ) ; let src_ip = packet . src_ip ( ) . ipv6_bytes ( ) . into ( ) ; let dst_ip = packet . dst_ip ( ) . ipv6_bytes ( ) . into ( ) ; let ( src_port , dst_port ) = match packet . proto ( ) { Ipv6Proto :: Proto ( IpProto :: Tcp ) => { let args = TcpParseArgs :: new ( packet . src_ip ( ) , packet . dst_ip ( ) ) ; let tcp = TcpSegment :: parse ( & mut packet_bytes , args ) . context ( " " ) ? ; ( Some ( tcp . src_port ( ) ) , Some ( tcp . dst_port ( ) ) ) } Ipv6Proto :: Proto ( IpProto :: Udp ) => { let args = UdpParseArgs :: new ( packet . src_ip ( ) , packet . dst_ip ( ) ) ; let udp = UdpPacket :: parse ( & mut packet_bytes , args ) . context ( " " ) ? ; ( udp . src_port ( ) , Some ( udp . dst_port ( ) ) ) } _ => ( None , None ) , } ; Ok ( ( proto , src_ip , dst_ip , src_port , dst_port ) ) }
Decodes the protocol, source address, destination address, source port,
destination port
Decodes the protocol source address destination address source port destination port
packet_bytes
&[u8]
packet_bytes
&[u8]