Exemplo n.º 1
0
        /// <summary>
        /// Returns the embedded Wake-On-LAN packet
        ///  or null if there is none
        /// </summary>
        /// <returns>
        /// A Wake-On-LAN packet
        /// </returns>
        public static WakeOnLanPacket GetEncapsulated(Packet p)
        {
            if (p is EthernetPacket)
            {
                var payload = EthernetPacket.GetInnerPayload((InternetLinkLayerPacket)p);
                if (((EthernetPacket)p).Type == EthernetPacketType.WakeOnLan)
                {
                    var payloadBas = new ByteArraySegment(p.PayloadData);
                    if (WakeOnLanPacket.IsValid(payloadBas))
                    {
                        return(new WakeOnLanPacket(payloadBas));
                    }
                }

                if (payload != null && payload is IpPacket)
                {
                    var innerPayload = payload.PayloadPacket;

                    if ((innerPayload != null) &&
                        (innerPayload.PayloadData != null) &&
                        (innerPayload is UdpPacket))
                    {
                        var innerPayloadBas = new ByteArraySegment(innerPayload.PayloadData);
                        if (WakeOnLanPacket.IsValid(innerPayloadBas))
                        {
                            return(new WakeOnLanPacket(innerPayloadBas));
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
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 = 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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bas">
        /// A <see cref="ByteArraySegment"/>
        /// </param>
        public LinuxSLLPacket(ByteArraySegment bas)
        {
            header        = new ByteArraySegment(bas);
            header.Length = LinuxSLLFields.SLLHeaderLength;

            // parse the payload via an EthernetPacket method
            payloadPacketOrData = EthernetPacket.ParseEncapsulatedBytes(header,
                                                                        EthernetProtocolType);
        }
Exemplo n.º 4
0
 public VLanTaggedPacket(ByteArraySegment bas)
 {
     header              = new ByteArraySegment(bas);
     header.Length       = 4;
     payloadPacketOrData = EthernetPacket.ParseEncapsulatedBytes(header, Type);
 }