I have an IP packet stored in a char buffer:
char packet[] = "450000CC68C4000001114C4F0A0A0A0AEFFFFFFADEA9076C00B832074D2D534541524348202A20485454502F312E310D0A484F53543A203233392E3235352E3235352E3235303A313930300D0A4D414E3A2022737364703A646973636F766572220D0A4D583A20310D0A53543A2075726E3A6469616C2D6D756C746973637265656E2D6F72673A736572766963653A6469616C3A310D0A555345522D4147454E543A20476F6F676C65204368726F6D652F3130372E302E353330342E313130204D6163204F5320580D0A0D0A"
I am try to parse this IP header using netinet/ip.h ip definition.
But when i try to print the ip packet details like ip header length, it is printing garbage:
#include <netinet/ip.h>
void decodeIPPacket(const char *packet)
{
struct ip *ipHdr = (struct ip*)(long)packet;
printf("decodeIPPacket:: IP Len: %d", ipHdr->ip_len);
printf("decodeIPPacket:: srcip: %u", ipHdr->ip_src.s_addr);
printf("decodeIPPacket:: dstip: %u", ipHdr->ip_dst.s_addr);
}
decodeIPPacket:: IP Len: 12336
decodeIPPacket:: srcip: 808464432
decodeIPPacket:: dstip: 825307440
What am i doing wrong here?
ipHdr? Can you also update your question with what you have tried?