However, I found an application called MTR. I downloaded the code and looked at it. Here is what it does and it acts as the EXPIRED response includes the original ICMP header immediately after the returned IP Header.
To get this to work, I had to define two structures as MTR did. The two I defined are:
struct ICMPHeader { uint8_t type; uint8_t code; uint16_t checksum; uint16_t id; uint16_t sequence; };
/* Structure of an IP header. */ struct IPHeader { uint8_t version; uint8_t tos; uint16_t len; uint16_t id; uint16_t frag; uint8_t ttl; uint8_t protocol; uint16_t check; uint saddr; uint daddr; };
I then used these structures to move forward in the packet (as MTR) does.
if(packetInterpretedAsICMPPacket->icmp_type == ICMP_TTL_EXPIRE) { packetInterpretedAsIPPacket = (struct ip *)&(packetInterpretedAsICMPPacket->icmp_ip);
header = (struct ICMPHeader *)(pingReplyBuffer + sizeof (struct IPHeader) + sizeof (struct ICMPHeader) + sizeof (struct IPHeader)); printf("Actual Seq# = %d icmp packet icmp_seq = %d\n",sequenceNumber,header->sequence);
if(header->sequence != sequenceNumber) continue;
However, what baffles me is why I can't just do this:
header = (struct ICMPHeader *)(pingReplyBuffer + sizeof (struct ip) + sizeof (struct icmp) + sizeof (struct ip));
Or do this:
int ipHeaderLength = packetInterpretedAsIPPacket->ip_hl << 2; ipHeaderPtr = (struct ip *)(pingReplyBuffer + ipHeaderLength + sizeof(struct icmp)) int ipHeaderLength2 = ipHeaderPtr->ip_hl << 2; header = (struct ICMPHeader *)(pingReplyBuffer + ipHeaderLength + sizeof (struct icmp) + ipHeaderLength2);
But none of these worked for me. I tried many different (logical) methods to move forward in the packet to the returned ICMP Header but none gave me the correct results. I finally decided to try the exact method MTR uses -- i.e. to define their IPHeader struct and ICMPHeader struct and then move forward in the pingReplyBuffer by increments computed by the sizeof their structures. Why doesn't our /usr/include/netinet/ip.h and ip_icmp.h structures for struct ip and struct icmp work?????? This seems like a kludge to me. What am I missing here??
Many thanks for all your help. I couldn't have gotten this working without the help from this working group - in this case, specifically from Josh and Peter. This type of community effort and support is so appreciated by people like me.
THANKS!!!!
The code is working now but I'm just a bit un-happy with the way I got it to work.
Thanks Dalton Hamilton
|