Re: icmp traceroute
Re: icmp traceroute
- Subject: Re: icmp traceroute
- From: "Peter Sichel" <email@hidden>
- Date: Mon, 28 Aug 2006 09:10:59 -0400
On 8/28/06, Dalton Hamilton wrote:
>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??
You have to pay careful attention to the actual definition of these
structures. The IP header for example is not fixed length but may
include one or more options. The correct solution is to extract the
header length (ip->hlen) from the packet itself, something like this:
dp = (UInt8*)[[inMessage data] bytes];
inDataSize = [[inMessage data] length];
// setup pointer to ip header
ip_header = (ip_header_t*)dp;
// setup pointer to icmp header
icmp_header = (icmp_header_t*)&dp[(ip_header->hlen & 0x0F) * 4];
// setup pointer to ip header of triggering datagram
ip_header2 = (ip_header_t*)&icmp_header->data[0];
// setup pointer to icmp header of triggering datagram
icmp_header2 = (icmp_header_t*)&icmp_header->data[(ip_header2->hlen
& 0x0F) * 4];
// setup pointer to udp header of triggering datagram
udp_header2 = (udp_header_t*)&icmp_header->data[(ip_header2->hlen &
0x0F) * 4];
Notice the "hlen" field is 4-bits wide and gives the header length in 4-
byte words. Having a good reference book like Stevens or Comer at your
elbow can really help.
Kind Regards,
- Peter
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden