/// <summary> /// Returns the IP header and the first 8 byte of the IP data segment /// as an array of bytes. /// </summary> /// <param name="packet">The IP packet whose data to return.</param> /// <returns>An arry of bytes containing the IP header and the first /// 8 bytes of IP data of the specified IP packet.</returns> /// <exception cref="ArgumentNullException">Thrown if the packet /// parameter is null.</exception> /// <remarks>Many ICMP packets include the IP header and the first 8 /// bytes of data of an IP packet.</remarks> static byte[] GetIpData(IpPacket packet) { packet.ThrowIfNull("packet"); // Many ICMP packets include the 20-byte IP header and the first // 8 bytes of an IP packet. var serialized = packet.Serialize(); var size = Math.Min(20 + 8, serialized.Length); var data = new byte[size]; Array.Copy(serialized, data, data.Length); return(data); }
/// <summary> /// Creates a new "Destination Unreachable" ICMP packet. /// </summary> /// <param name="packet">The IP packet whose destination is /// unreachable.</param> /// <returns>An initialized instance of the IcmpPacket class representing /// a "Destination Network Unreachable" ICMP packet.</returns> /// <exception cref="ArgumentNullException">Thrown if the packet parameter /// is null.</exception> public static IcmpPacket Unreachable(IpPacket packet) { packet.ThrowIfNull("packet"); return new IcmpPacket(IcmpType.Unreachable, IcmpCode.DestinationNetworkUnreachable, GetIpData(packet)); }
/// <summary> /// Creates a new "Time Exceeded" ICMP packet. /// </summary> /// <param name="packet">The IP packet whose TTL value expired.</param> /// <returns>An initialized instance of the IcmpPacket class representing /// a "TTL expired in transit" ICMP packet.</returns> /// <exception cref="ArgumentNullException">Thrown if the packet parameter /// is null.</exception> public static IcmpPacket TimeExceeded(IpPacket packet) { packet.ThrowIfNull("packet"); return new IcmpPacket(IcmpType.TimeExceed, IcmpCode.TtlExpired, GetIpData(packet)); }
/// <summary> /// Returns the IP header and the first 8 byte of the IP data segment /// as an array of bytes. /// </summary> /// <param name="packet">The IP packet whose data to return.</param> /// <returns>An arry of bytes containing the IP header and the first /// 8 bytes of IP data of the specified IP packet.</returns> /// <exception cref="ArgumentNullException">Thrown if the packet /// parameter is null.</exception> /// <remarks>Many ICMP packets include the IP header and the first 8 /// bytes of data of an IP packet.</remarks> static byte[] GetIpData(IpPacket packet) { packet.ThrowIfNull("packet"); // Many ICMP packets include the 20-byte IP header and the first // 8 bytes of an IP packet. var serialized = packet.Serialize(); var size = Math.Min(20 + 8, serialized.Length); var data = new byte[size]; Array.Copy(serialized, data, data.Length); return data; }
/// <summary> /// Creates a new "Source Quench" ICMP packet. /// </summary> /// <param name="packet">The IP packet in whose response the source /// quench packet is being sent.</param> /// <returns>An initialized instance of the IcmpPacket class representing /// a "Source Quench" ICMP packet.</returns> /// <exception cref="ArgumentNullException">Thrown if the packet parameter /// is null.</exception> public static IcmpPacket SourceQuench(IpPacket packet) { packet.ThrowIfNull("packet"); return new IcmpPacket(IcmpType.SourceQuench, 0, GetIpData(packet)); }
/// <summary> /// Creates a new "Fragmentation Required" ICMP packet. /// </summary> /// <param name="packet">The IP packet for which fragmentation is /// required.</param> /// <returns>An initialized instance of the IcmpPacket class representing /// a "Fragmentation Required" ICMP packet.</returns> /// <exception cref="ArgumentNullException">Thrown if the packet parameter /// is null.</exception> public static IcmpPacket FragmentationRequired(IpPacket packet) { packet.ThrowIfNull("packet"); return new IcmpPacket(IcmpType.Unreachable, IcmpCode.FragmentationRequired, GetIpData(packet)); }
/// <summary> /// Creates a new "Destination Unreachable" ICMP packet. /// </summary> /// <param name="packet">The IP packet whose destination is /// unreachable.</param> /// <returns>An initialized instance of the IcmpPacket class representing /// a "Destination Network Unreachable" ICMP packet.</returns> /// <exception cref="ArgumentNullException">Thrown if the packet parameter /// is null.</exception> public static IcmpPacket Unreachable(IpPacket packet) { packet.ThrowIfNull("packet"); return(new IcmpPacket(IcmpType.Unreachable, IcmpCode.DestinationNetworkUnreachable, GetIpData(packet))); }
/// <summary> /// Creates a new "Time Exceeded" ICMP packet. /// </summary> /// <param name="packet">The IP packet whose TTL value expired.</param> /// <returns>An initialized instance of the IcmpPacket class representing /// a "TTL expired in transit" ICMP packet.</returns> /// <exception cref="ArgumentNullException">Thrown if the packet parameter /// is null.</exception> public static IcmpPacket TimeExceeded(IpPacket packet) { packet.ThrowIfNull("packet"); return(new IcmpPacket(IcmpType.TimeExceed, IcmpCode.TtlExpired, GetIpData(packet))); }
/// <summary> /// Creates a new "Source Quench" ICMP packet. /// </summary> /// <param name="packet">The IP packet in whose response the source /// quench packet is being sent.</param> /// <returns>An initialized instance of the IcmpPacket class representing /// a "Source Quench" ICMP packet.</returns> /// <exception cref="ArgumentNullException">Thrown if the packet parameter /// is null.</exception> public static IcmpPacket SourceQuench(IpPacket packet) { packet.ThrowIfNull("packet"); return(new IcmpPacket(IcmpType.SourceQuench, 0, GetIpData(packet))); }
/// <summary> /// Creates a new "Fragmentation Required" ICMP packet. /// </summary> /// <param name="packet">The IP packet for which fragmentation is /// required.</param> /// <returns>An initialized instance of the IcmpPacket class representing /// a "Fragmentation Required" ICMP packet.</returns> /// <exception cref="ArgumentNullException">Thrown if the packet parameter /// is null.</exception> public static IcmpPacket FragmentationRequired(IpPacket packet) { packet.ThrowIfNull("packet"); return(new IcmpPacket(IcmpType.Unreachable, IcmpCode.FragmentationRequired, GetIpData(packet))); }