Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Raw sockets corrupting IP headers (SOLVED)

 

I'm listening for ICMP packets using the following method to capture packets. I'm also running a packet sniffer to see what goes in and out of the box.

 

Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 100);
socket.Bind((EndPoint)new IPEndPoint(System.Net.IPAddress.Any, 0));

byte[] buffer = new byte[2000];
IPEndPoint ipendpoint = new IPEndPoint(System.Net.IPAddress.Any, 0);
EndPoint endpoint = (EndPoint)ipendpoint;
socket.ReceiveFrom(buffer, buffer.Length, SocketFlags.Peek, ref endpoint);

 

However, what I'm finding is that some of the values in the IP header returned differ from what the sniffer is showing. Specifically, the TTL is different.

 

Does anybody know what could be causing this? Even better, does anybody know how to prevent this?

Edited by jasonbstubbs
Posted (edited)

The sniffer gives a TTL of 128 on a icmp echo reply from a Windows XP machine which is what I would expect. Sockets is returning a TTL of 255, which is incidentally the TTL that I used when sending out the echo request but that was done using a different Socket instance.

 

And the answer to your second question: the sniffer is Ethereal and is running on the same machine that is receiving the packets. The "pinger" and "pingee" are connected to the same switch.

Edited by jasonbstubbs
Posted
Arggg. Never mind. In my class that holds an IP packet, I was initializing the header with some nice default values in the constructor. Unfortunately (or idiotically) that was overwriting the received packet's data.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...