Example #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);
        }
Example #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bas">
        /// A <see cref="ByteArraySegment"/>
        /// </param>
        public WakeOnLanPacket(ByteArraySegment bas)
        {
            log.Debug("");

            if (WakeOnLanPacket.IsValid(bas))
            {
                // set the header field, header field values are retrieved from this byte array
                header        = new ByteArraySegment(bas);
                header.Length = Bytes.Length;
            }
        }