/// <summary>
        /// Look for the innermost payload. This method is useful because
        /// while some packets are LinuxSSL->IpPacket or
        /// EthernetPacket->IpPacket, there are some packets that are
        /// EthernetPacket->PPPoEPacket->PPPPacket->IpPacket, and for these cases
        /// we really want to get to the IpPacket
        /// </summary>
        /// <returns>
        /// A <see cref="Packet"/>
        /// </returns>
        public static Packet GetInnerPayload(InternetLinkLayerPacket packet)
        {
            // is this an ethernet packet?
            if (packet is EthernetPacket)
            {
                log.Debug("packet is EthernetPacket");

                var thePayload = packet.PayloadPacket;

                // is this packets payload a PPPoEPacket? If so,
                // the PPPoEPacket payload should be a PPPPacket and we want
                // the payload of the PPPPpacket
                if (thePayload is PPPoEPacket)
                {
                    log.Debug("thePayload is PPPoEPacket");
                    return(thePayload.PayloadPacket.PayloadPacket);
                }

                return(thePayload);
            }
            else
            {
                log.Debug("else");
                return(packet.PayloadPacket);
            }
        }
Exemple #2
0
        /// <summary>
        /// Returns the encapsulated ARPPacket of the Packet p or null if
        /// there is no encapsulated packet
        /// </summary>
        /// <param name="p">
        /// A <see cref="Packet"/>
        /// </param>
        /// <returns>
        /// A <see cref="ARPPacket"/>
        /// </returns>
        public static ARPPacket GetEncapsulated(Packet p)
        {
            if (p is InternetLinkLayerPacket)
            {
                var payload = InternetLinkLayerPacket.GetInnerPayload((InternetLinkLayerPacket)p);
                if (payload is ARPPacket)
                {
                    return((ARPPacket)payload);
                }
            }

            return(null);
        }
Exemple #3
0
        /// <summary>
        /// Returns the IpPacket inside of the Packet p or null if
        /// there is no encapsulated packet
        /// </summary>
        /// <param name="p">
        /// A <see cref="Packet"/>
        /// </param>
        /// <returns>
        /// A <see cref="IpPacket"/>
        /// </returns>
        public static IpPacket GetEncapsulated(Packet p)
        {
            log.Debug("");

            if (p is InternetLinkLayerPacket)
            {
                var payload = InternetLinkLayerPacket.GetInnerPayload((InternetLinkLayerPacket)p);
                if (payload is IpPacket)
                {
                    return((IpPacket)payload);
                }
            }

            return(null);
        }
Exemple #4
0
        /// <summary>
        /// Returns the UdpPacket inside of the Packet p or null if
        /// there is no encapsulated packet
        /// </summary>
        /// <param name="p">
        /// A <see cref="Packet"/>
        /// </param>
        /// <returns>
        /// A <see cref="UdpPacket"/>
        /// </returns>
        public static UdpPacket GetEncapsulated(Packet p)
        {
            if (p is InternetLinkLayerPacket)
            {
                var payload = InternetLinkLayerPacket.GetInnerPayload((InternetLinkLayerPacket)p);
                if (payload is IpPacket)
                {
                    var innerPayload = payload.PayloadPacket;
                    if (innerPayload is UdpPacket)
                    {
                        return((UdpPacket)innerPayload);
                    }
                }
            }

            return(null);
        }