/// <summary> /// Look for the innermost payload. This method is useful because /// while some packets are LinuxSSL->IpPacket or /// EthernetPacket->IpPacket, there are some packets that are /// EthernetPacket->PPPoEPacket->PPPPacket->IpPacket, and for these cases /// we really want to get to the IpPacket /// </summary> /// <returns> /// A <see cref="Packet"/> /// </returns> public static Packet GetInnerPayload(InternetLinkLayerPacket packet) { // is this an ethernet packet? if (packet is EthernetPacket) { //log.DEBUG("packet is EthernetPacket"); var thePayload = packet.PayloadPacket; // is this packets payload a PPPoEPacket? If so, // the PPPoEPacket payload should be a PPPPacket and we want // the payload of the PPPPpacket if (thePayload is PPPoEPacket) { //log.DEBUG("thePayload is PPPoEPacket"); return(thePayload.PayloadPacket.PayloadPacket); } if (thePayload is VLanTaggedPacket) { return(thePayload.PayloadPacket); } return(thePayload); } else { //log.DEBUG("else"); return(packet.PayloadPacket); } }
/// <summary> /// Returns the encapsulated ARPPacket of the Packet p or null if /// there is no encapsulated packet /// </summary> /// <param name="p"> /// A <see cref="Packet"/> /// </param> /// <returns> /// A <see cref="ARPPacket"/> /// </returns> public static ARPPacket GetEncapsulated(Packet p) { if (p is InternetLinkLayerPacket) { var payload = InternetLinkLayerPacket.GetInnerPayload((InternetLinkLayerPacket)p); if (payload is ARPPacket) { return((ARPPacket)payload); } } return(null); }
/// <summary> /// Returns the IpPacket inside of the Packet p or null if /// there is no encapsulated packet /// </summary> /// <param name="p"> /// A <see cref="Packet"/> /// </param> /// <returns> /// A <see cref="IpPacket"/> /// </returns> public static IpPacket GetEncapsulated(Packet p) { //log.DEBUG(""); if (p is InternetLinkLayerPacket) { var payload = InternetLinkLayerPacket.GetInnerPayload((InternetLinkLayerPacket)p); if (payload is IpPacket) { return((IpPacket)payload); } } return(null); }
/// <summary> /// Returns the TcpPacket embedded in Packet p or null if /// there is no embedded TcpPacket /// </summary> public static TcpPacket GetEncapsulated(Packet p) { if (p is InternetLinkLayerPacket) { var payload = InternetLinkLayerPacket.GetInnerPayload((InternetLinkLayerPacket)p); if (payload is IpPacket) { var innerPayload = payload.PayloadPacket; if (innerPayload is TcpPacket) { return((TcpPacket)innerPayload); } } } return(null); }
/// <summary> /// Returns the encapsulated IGMPv2Packet of the Packet p or null if /// there is no encapsulated packet /// </summary> /// <param name="p"> /// A <see cref="Packet"/> /// </param> /// <returns> /// A <see cref="IGMPv2Packet"/> /// </returns> public static IGMPv2Packet GetEncapsulated(Packet p) { if (p is InternetLinkLayerPacket) { var payload = InternetLinkLayerPacket.GetInnerPayload((InternetLinkLayerPacket)p); if (payload is IpPacket) { Console.WriteLine("Is an IP packet"); var innerPayload = payload.PayloadPacket; if (innerPayload is IGMPv2Packet) { return((IGMPv2Packet)innerPayload); } } } return(null); }