Dissecting a Captured packet

Status
Not open for further replies.

amanchenna

Solid State Member
Messages
10
Hi all,

I have written a small program using pcap library which captures a packet. My task is to capture a packet from the mobile device and determine whether this packet is from a router which acts as an HomeAgent or Foreign Agent (Mobile IP).

Theory of Mobile IP : Generally if a router acts as either a HomeAgent or Foreign Agent it will send advertisements to the broadcast address giving information that it is a Agent which can serve the mobile nodes. So the format for Mobile IP advertisment packet looks like the following.

Ether packet + IP packet + ICMP Packet + Mobile IP advertisement packet.

Through my code I am able to know the captured packet is an IP packet by checking the type in ether header. After checking the protocol in IP packet I came to know it is an ICMP packet. My task is to capture a packet which is a mobile IP advertisement package which follows generally a ICMP router advertisement packet.

here is sample of the code to check which packet it is.

packet = pcap_next(descr, &hdr); /* received the packet */

eptr = (struct ether_header *) packet; /* to check ethernet header */

if (ntohs (eptr->ether_type) == ETHERTYPE_IP)
{
printf("ethernet type is an IP protocol");

ipptr = (struct iphdr *) (eptr + 1);

if (ipptr->protocol == !)
{
printf("IP protocol type is an ICMP packet");

icmpptr = (struct icmphdr *) (ipptr + 1);

if ((icmpptr->type == 1) && (icmpptr->code == 16))
{
printf("this icmp packet is followed by a Mobile IP advertisement packet extension");
}
}
}

so far so good. By checking type = 1 and code = 16 I came to know that it is ICMP Router advertisement packet followed by one of the extensions of Mobile IP advertisement packet.

But I don`t know what to do further. i.e I have to check each and every field of ICMP packet and go through the mobile IP advertisement packet which follows it and by checking in the flags of this advertisement have to decide whether the packet received is from either the HomeAgent or Foreing Agent.

please tell me how to program for finding the mobile IP advertisement packet in ICMP packet.

if u want to know the format of ICMP router advertisement packet and extensions of Mobile IP packet go to the following links,
http://www.tcpipguide.com/free/t_ICMPv4RouterAdvertisementandRouterSolicitationMess-2.htm
http://www.tcpipguide.com/free/t_MobileIPAgentDiscoveryandAgentAdvertisementandSoli-4.htm

please solve my problem,
thanks in advance.

Dinesh.
 
Status
Not open for further replies.
Back
Top Bottom