/// <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); }
/// <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); }
/// <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 = Ieee80211.MacFrame.ParsePacket(bas); break; case LinkLayers.Ieee80211_Radio: p = new Ieee80211.RadioPacket(bas); break; case LinkLayers.PerPacketInformation: p = new Ieee80211.PpiPacket(bas); break; default: throw new System.NotImplementedException("LinkLayer of " + LinkLayer + " is not implemented"); } return(p); }