Ejemplo n.º 1
0
        internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment Header,
                                                                        PPPProtocol Protocol)
        {
            // slice off the payload
            var payload = Header.EncapsulatedBytes();

            //log.DEBUGFormat("payload: {0}", payload);

            var payloadPacketOrData = new PacketOrByteArraySegment();

            switch (Protocol)
            {
            case PPPProtocol.IPv4:
                payloadPacketOrData.ThePacket = new IPv4Packet(payload);
                break;

            case PPPProtocol.IPv6:
                payloadPacketOrData.ThePacket = new IPv6Packet(payload);
                break;

            default:
                throw new System.NotImplementedException("Protocol of " + Protocol + " is not implemented");
            }

            return(payloadPacketOrData);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bas">
        /// A <see cref="ByteArraySegment"/>
        /// </param>
        public IGMPv2Packet(ByteArraySegment bas)
        {
            // set the header field, header field values are retrieved from this byte array
            header        = new ByteArraySegment(bas);
            header.Length = UdpFields.HeaderLength;

            // store the payload bytes
            payloadPacketOrData = new PacketOrByteArraySegment();
            payloadPacketOrData.TheByteArraySegment = header.EncapsulatedBytes();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bas">
        /// A <see cref="ByteArraySegment"/>
        /// </param>
        public ICMPv4Packet(ByteArraySegment bas)
        {
            //log.DEBUG("");

            header        = new ByteArraySegment(bas);
            header.Length = ICMPv4Fields.HeaderLength;

            // store the payload bytes
            payloadPacketOrData = new PacketOrByteArraySegment();
            payloadPacketOrData.TheByteArraySegment = header.EncapsulatedBytes();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bas">
        /// A <see cref="ByteArraySegment"/>
        /// </param>
        public UdpPacket(ByteArraySegment bas)
        {
            //log.DEBUGFormat("bas {0}", bas.ToString());

            // set the header field, header field values are retrieved from this byte array
            header        = new ByteArraySegment(bas);
            header.Length = UdpFields.HeaderLength;

            // store the payload bytes
            payloadPacketOrData = new PacketOrByteArraySegment();
            payloadPacketOrData.TheByteArraySegment = header.EncapsulatedBytes();
        }
Ejemplo n.º 5
0
        internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment Header)
        {
            // slice off the payload
            var payload = Header.EncapsulatedBytes();
            //log.DEBUGFormat("payload {0}", payload.ToString());

            var payloadPacketOrData = new PacketOrByteArraySegment();

            // we assume that we have a PPPPacket as the payload
            payloadPacketOrData.ThePacket = new PPPPacket(payload);

            return(payloadPacketOrData);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bas">
        /// A <see cref="ByteArraySegment"/>
        /// </param>
        public TcpPacket(ByteArraySegment bas)
        {
            //log.DEBUG("");

            // set the header field, header field values are retrieved from this byte array
            header = new ByteArraySegment(bas);

            // NOTE: we update the Length field AFTER the header field because
            // we need the header to be valid to retrieve the value of DataOffset
            header.Length = DataOffset * 4;

            // store the payload bytes
            payloadPacketOrData = new PacketOrByteArraySegment();
            payloadPacketOrData.TheByteArraySegment = header.EncapsulatedBytes();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Called by IPv4 and IPv6 packets to parse their packet payload
        /// </summary>
        /// <param name="payload">
        /// A <see cref="ByteArraySegment"/>
        /// </param>
        /// <param name="ProtocolType">
        /// A <see cref="IPProtocolType"/>
        /// </param>
        /// <param name="ParentPacket">
        /// A <see cref="Packet"/>
        /// </param>
        /// <returns>
        /// A <see cref="PacketOrByteArraySegment"/>
        /// </returns>
        internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment payload,
                                                                        IPProtocolType ProtocolType,
                                                                        Packet ParentPacket)
        {
            //log.DEBUGFormat("payload: {0}, ParentPacket.GetType() {1}",
            //payload,
            //ParentPacket.GetType());

            var payloadPacketOrData = new PacketOrByteArraySegment();

            switch (ProtocolType)
            {
            case IPProtocolType.TCP:
                payloadPacketOrData.ThePacket = new TcpPacket(payload,
                                                              ParentPacket);
                break;

            case IPProtocolType.UDP:
                payloadPacketOrData.ThePacket = new UdpPacket(payload,
                                                              ParentPacket);
                break;

            case IPProtocolType.ICMP:
                payloadPacketOrData.ThePacket = new ICMPv4Packet(payload,
                                                                 ParentPacket);
                break;

            case IPProtocolType.ICMPV6:
                payloadPacketOrData.ThePacket = new ICMPv6Packet(payload,
                                                                 ParentPacket);
                break;

            case IPProtocolType.IGMP:
                payloadPacketOrData.ThePacket = new IGMPv2Packet(payload,
                                                                 ParentPacket);
                break;

            // NOTE: new payload parsing entries go here
            default:
                payloadPacketOrData.TheByteArraySegment = payload;
                break;
            }

            return(payloadPacketOrData);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Used by the EthernetPacket constructor. Located here because the LinuxSLL constructor
        /// also needs to perform the same operations as it contains an ethernet type
        /// </summary>
        /// <param name="Header">
        /// A <see cref="ByteArraySegment"/>
        /// </param>
        /// <param name="Type">
        /// A <see cref="EthernetPacketType"/>
        /// </param>
        /// <returns>
        /// A <see cref="PacketOrByteArraySegment"/>
        /// </returns>
        internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment Header,
                                                                        EthernetPacketType Type)
        {
            // slice off the payload
            var payload = Header.EncapsulatedBytes();
            //log.DEBUGFormat("payload {0}", payload.ToString());

            var payloadPacketOrData = new PacketOrByteArraySegment();

            // parse the encapsulated bytes
            switch (Type)
            {
            case EthernetPacketType.IpV4:
                payloadPacketOrData.ThePacket = new IPv4Packet(payload);
                break;

            case EthernetPacketType.IpV6:
                payloadPacketOrData.ThePacket = new IPv6Packet(payload);
                break;

            case EthernetPacketType.Arp:
                payloadPacketOrData.ThePacket = new ARPPacket(payload);
                break;

            case EthernetPacketType.LLDP:
                payloadPacketOrData.ThePacket = new LLDPPacket(payload);
                break;

            case EthernetPacketType.PointToPointProtocolOverEthernetSessionStage:
                payloadPacketOrData.ThePacket = new PPPoEPacket(payload);
                break;

            case EthernetPacketType.VLanTaggedFrame:
                payloadPacketOrData.ThePacket = new VLanTaggedPacket(payload);
                break;

            default:     // consider the sub-packet to be a byte array
                payloadPacketOrData.TheByteArraySegment = payload;
                break;
            }

            return(payloadPacketOrData);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bas">
        /// A <see cref="ByteArraySegment"/>
        /// </param>
        public Ieee80211MacFrame(ByteArraySegment bas)
        {
            //log.DEBUG("");

            // slice off the header portion as our header
            header = new ByteArraySegment(bas);
            const int defaultLength = 4;

            header.Length = defaultLength;

            FrameControl = new Ieee80211FrameControlField(FrameControlBytes);

            // determine what kind of frame this is based on the type
            if (FrameControl.Types == Ieee80211FrameControlField.FrameTypes.ControlRTS)
            {
                InnerFrame = new RTSFrame(this, bas);
            }
            else if (FrameControl.Types == Ieee80211FrameControlField.FrameTypes.ControlCTS)
            {
                InnerFrame = new CTSOrACKFrame(this, bas);
            }
            else if (FrameControl.Types == Ieee80211FrameControlField.FrameTypes.ControlACK)
            {
                InnerFrame = new CTSOrACKFrame(this, bas);
            }
            else
            {
                throw new System.NotImplementedException("FrameControl.Types of " + FrameControl.Types + " not handled");
            }

            header.Length = InnerFrame.FrameSize;

            // store the payload, less the frame check sequence at the end
            payloadPacketOrData = new PacketOrByteArraySegment();
            payloadPacketOrData.TheByteArraySegment         = header.EncapsulatedBytes();
            payloadPacketOrData.TheByteArraySegment.Length -= Ieee80211MacFields.FrameCheckSequenceLength;
        }