ICMP socket reply from false host

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I needed to write a ping tool with VB.NET. Since there are many examples on
how to create the neccessary ICMP paket, this was not so hard at the first
glance.

Then a strange error occured:
SOmetimes, my tool thought it was receiving a ping reply, though this cannot
be, because I used an impossible IP address for testing ... or the host was
unreachable from beginning and although, the ping received a reply.

I found out, that when the ping was waiting for a reply
(socket.receivefrom), actually *any* ICMP echo reply would be interpreted as
a reply, even if sent from a totally different host...

As a workaround, I checked the ICMP echo reply buffer and saw, that the IP
address of the replying host is within the buffer, so I took the Address,
parsed it into an IPAddress and checked for equality against the desired host
address to find out whether the reply came from the correct host.

Anyway ... I though, that the receivefrom method already makes sure, that
only echo replies from the correct hosts are received?

Any comments?
 
Hello =?Utf-8?B?VHJvbmV4?=,
I found out, that when the ping was waiting for a reply
(socket.receivefrom), actually *any* ICMP echo reply would be
interpreted as a reply, even if sent from a totally different host...

This is by design!
ICMP is not connection orientend and therefor you will receive every ICMP
reply!
 
This is by design!
ICMP is not connection orientend and therefor you will receive every ICMP
reply!

Thanks!

I've got a question though:
As I wrote earlier, I am getting the IP Address from the reply buffer and
compare it with the source address, I am waiting to get an answer from. I
guess, this is the correct solution then. But I am not sure if the way I am
doing this is the best solution:

Dim strIPAddress As String = String.Format("{0}.{1}.{2}.{3}",
ReplyBuffer(12), ReplyBuffer(13), ReplyBuffer(14), ReplyBuffer(15))

srcIPAddress = System.Net.IPAddress.Parse(strIPAddress)

If srcIPAddress.Equals(dstIPAddress) Then
....
End If

1. Is there a better way to extract the IP Address out of the buffer?
2. Is it given, that the source IP Address is always encoded into the ICMP
echo reply buffer?

Greetings,
Tronex
 
Back
Top