how to detect icmp packets

Feb 4, 2011 at 4:01 PM

how can we detect icmp packets just like tcp or udp packets

 

e.g

if (ethernet.EtherType == EthernetType.IpV4)
{
IpV4Datagram ip = packet.Ethernet.IpV4;

if (ip.Protocol == IpV4Protocol.Tcp)
{
TcpDatagram tcp = ip.Tcp;
Console.WriteLine("TCP " + ip.Source + ":" + tcp.SourcePort + " -> " + ip.Destination + ":" + tcp.DestinationPort);
}
if (ip.Protocol == IpV4Protocol.Udp)
{
UdpDatagram udp = ip.Udp;
Console.WriteLine("UDP " + ip.Source + ":" + udp.SourcePort + " -> " + ip.Destination + ":" + udp.DestinationPort);
}

}

thanks in advance

Feb 4, 2011 at 5:28 PM

ok i got it.We can use the enumeration IpV4Protocol.InternetControlMessageProtocol.

HURRAH