Hi,
As part of an application I'd like to capture Icmpv6 packets thrown
when an application is not listening on a given port. I.e. I send a
packet to another host on a port and listen for Icmp destination
unreachable,port unreachable messages. While this method works for
Icmpv4 on C# it doesn't for Icmpv6. ( I'm using .net 2.0) I also know
that this packet is been sent by the other host as I can view the
Icmpv6 packet via Ethereal. ( It is a host unreachable , port
unreachable packet). I've posted the code I'm using below, if anyone
has any ideas I'd really appreciate it. The receive call blocks
indefinitely ( if no timeout is set).
Socket pingSocket = new Socket(
AddressFamily.InterNetworkV6,
SocketType.Dgram,
ProtocolType.Udp);
Socket pingSocket2 = new Socket(
AddressFamily.InterNetworkV6,
SocketType.Raw,
ProtocolType.IcmpV6);
string data = "Syslog test message";
IPAddress destAdd =
IPAddress.Parse("2002:a155:624b::a155:624b");
IPEndPoint ipep = new IPEndPoint(destAdd, 514);
IPEndPoint ipep2 = new IPEndPoint(IPAddress.IPv6Any, 0);
EndPoint ep = (EndPoint)ipep2;
string destAddress = destAdd.ToString();
ASCIIEncoding asc = new ASCIIEncoding();
byte[] myArray = asc.GetBytes(data);
byte [] recBuffer = new byte[0x140];
try {
pingSocket2.ReceiveTimeout = 1000;
pingSocket2.Bind(ep);
pingSocket1.SendTo(myArray, myArray.Length,
SocketFlags.None, ipep);
pingSocket2.ReceiveFrom(
recBuffer,
ref ep);
Console.WriteLine("Received {0} bytes ",
recBuffer.Length);
}
catch(Exception e)
{}
}
}
Thanks,
Piyush