示例#1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bas">
        /// A <see cref="ByteArraySegment"/>
        /// </param>
        public L2TPPacket(ByteArraySegment bas, Packet ParentPacket)
        {
            // slice off the header portion
            header = new ByteArraySegment(bas);

            header.Length = L2TPFields.HeaderLength;
            if (HasLength)
            {
                header.Length += L2TPFields.LengthsLength;
            }
            if (HasSequence)
            {
                header.Length += L2TPFields.NsLength + L2TPFields.NrLength;
            }
            if (HasOffset)
            {
                header.Length += L2TPFields.OffsetSizeLength + L2TPFields.OffsetPadLength;
            }

            var payload = header.EncapsulatedBytes();

            try
            {
                PayloadPacket = new PPPPacket(payload);
                PayloadPacket.ParentPacket = this;
            } catch (Exception)
            {
                //it's not a PPP packet, just attach the data
                payloadPacketOrData.Value.TheByteArraySegment = payload;
            }
            this.ParentPacket = ParentPacket;
        }
示例#2
0
        /// <summary>
        /// 通过PacketDotNet类库实现
        /// </summary>
        /// <param name="ppp"></param>
        private void PPP(PacketDotNet.PPPPacket ppp)
        {
            if (PPPNode == null)
            {
                PPPNode = CreatNode("PPP", 10);
            }
            PPPNode.Text = "PPP [0x" + ((ushort)ppp.Protocol).ToString("X4") + "]";
            PPPNode.Nodes.Clear();

            PPPNode.Nodes.Add("Protocol: " + ppp.Protocol.ToString() + " [0x" + ppp.Protocol.ToString("X") + "]");

            Tree.Nodes.Add(PPPNode);

            switch (ppp.Protocol)
            {
            case PPPProtocol.IPv4:
            case PPPProtocol.IPv6:
                IpPacket ip = IpPacket.GetEncapsulated(packet);
                IP(ip);
                break;

            case PPPProtocol.LCP:
                LCPPacket lcp = LCPPacket.GetEncapsulated(packet);
                LCP(lcp);
                break;

            case PPPProtocol.CompressedDatagram:
                ExtraData(ppp.PayloadData);
                return;

            case PPPProtocol.Padding:    //填充
                break;
            }
        }
示例#3
0
        /// <summary>
        /// Parse bytes into a packet
        /// </summary>
        /// <param name="LinkLayer">
        /// A <see cref="LinkLayers"/>
        /// </param>
        /// <param name="PacketData">
        /// A <see cref="System.Byte"/>
        /// </param>
        /// <returns>
        /// A <see cref="Packet"/>
        /// </returns>
        public static Packet ParsePacket(LinkLayers LinkLayer,
                                         byte[] PacketData)
        {
            Packet p;
            var    bas = new ByteArraySegment(PacketData);

            switch (LinkLayer)
            {
            case LinkLayers.Ethernet:
                p = new EthernetPacket(bas);
                break;

            case LinkLayers.LinuxSLL:
                p = new LinuxSLLPacket(bas);
                break;

            case LinkLayers.Ppp:
                p = new PPPPacket(bas);
                break;

            case LinkLayers.Ieee80211:
                p = new Ieee80211MacFrame(bas);
                break;

            case LinkLayers.Ieee80211_Radio:
                p = new Ieee80211RadioPacket(bas);
                break;

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

            return(p);
        }
示例#4
0
        /// <summary>
        /// Parse bytes into a packet
        /// </summary>
        /// <param name="LinkLayer">
        /// A <see cref="LinkLayers"/>
        /// </param>
        /// <param name="PacketData">
        /// A <see cref="System.Byte"/>
        /// </param>
        /// <returns>
        /// A <see cref="Packet"/>
        /// </returns>
        public static Packet ParsePacket(LinkLayers LinkLayer,
                                         byte[] PacketData)
        {
            Packet p;
            var    bas = new ByteArraySegment(PacketData);

            log.DebugFormat("LinkLayer {0}", LinkLayer);

            switch (LinkLayer)
            {
            case LinkLayers.Ethernet:
                p = new EthernetPacket(bas);
                break;

            case LinkLayers.LinuxSLL:
                p = new LinuxSLLPacket(bas);
                break;

            case LinkLayers.Null:
                p = new NullPacket(bas);
                break;

            case LinkLayers.Ppp:
                p = new PPPPacket(bas);
                break;

            case LinkLayers.Ieee80211:
                p = Ieee80211.MacFrame.ParsePacket(bas);
                break;

            case LinkLayers.Ieee80211_Radio:
                p = new Ieee80211.RadioPacket(bas);
                break;

            case LinkLayers.PerPacketInformation:
                p = new Ieee80211.PpiPacket(bas);
                break;

            case LinkLayers.Raw:
                p = new RawIPPacket(bas);
                break;

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

            return(p);
        }
示例#5
0
        /// <summary>
        ///     Parse bytes into a packet
        /// </summary>
        /// <param name="linkLayer">
        ///     A <see cref="LinkLayers" />
        /// </param>
        /// <param name="packetData">
        ///     A <see cref="System.Byte" />
        /// </param>
        /// <returns>
        ///     A <see cref="Packet" />
        /// </returns>
        public static Packet ParsePacket(LinkLayers linkLayer, byte[] packetData)
        {
            Packet p;
            var    bas = new ByteArraySegment(packetData);

            Log.DebugFormat("LinkLayer {0}", linkLayer);

            switch (linkLayer)
            {
            case LinkLayers.Ethernet:
                p = new EthernetPacket(bas);
                break;

            case LinkLayers.LinuxSLL:
                p = new LinuxSLLPacket(bas);
                break;

            case LinkLayers.Ppp:
                p = new PPPPacket(bas);
                break;

            case LinkLayers.Ieee80211:
                p = MacFrame.ParsePacket(bas);
                break;

            case LinkLayers.Ieee80211_Radio:
                p = new RadioPacket(bas);
                break;

            case LinkLayers.PerPacketInformation:
                p = new PpiPacket(bas);
                break;

            //http://sourceforge.net/p/packetnet/patches/1/
            case LinkLayers.Raw:
                var ipVer = (packetData[0] & 0xf0) >> 4;
                p = (ipVer == 4)? new IPv4Packet(bas) : new IPv6Packet(bas) as Packet;
                break;

            default:
                throw new NotImplementedException("LinkLayer of " + linkLayer + " is not implemented");
            }

            return(p);
        }
示例#6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bas">A <see cref="ByteArraySegment" /></param>
        /// <param name="parentPacket">The parent packet.</param>
        public L2TPPacket(ByteArraySegment bas, Packet parentPacket)
        {
            // slice off the header portion
            // ReSharper disable once UseObjectOrCollectionInitializer
            Header        = new ByteArraySegment(bas);
            Header.Length = L2TPFields.HeaderLength;

            if (HasLength)
            {
                Header.Length += L2TPFields.LengthsLength;
            }
            if (HasSequence)
            {
                Header.Length += L2TPFields.NsLength + L2TPFields.NrLength;
            }
            if (HasOffset)
            {
                Header.Length += L2TPFields.OffsetSizeLength + L2TPFields.OffsetPadLength;
            }

            var payload = Header.EncapsulatedBytes();

            try
            {
                PayloadPacket = new PPPPacket(payload)
                {
                    ParentPacket = this
                };
            }
            catch (Exception)
            {
                //it's not a PPP packet, just attach the data
                PayloadPacketOrData.Value.ByteArraySegment = payload;
            }

            ParentPacket = parentPacket;
        }