I am required to compare two IPs. One IP is stored in u8 format where I managed to convert it to char * which i stored in the variable arp_tbuf. However, the second IP to be compared is in u32 format (from ip.h). But every time I try to convert the IP in u32 format to char * as follows,
unsigned int pkt_da = (unsigned int)ip_header->daddr;
char pkt_tbuf[16];
char pkt_tbuf_tmp[4];
pkt_tbuf_tmp[0] = pkt_da & 0x000000FF;
pkt_tbuf_tmp[1] = (pkt_da & 0x0000FF00) >> 8;
pkt_tbuf_tmp[2] = (pkt_da & 0x00FF0000) >> 16;
pkt_tbuf_tmp[3] = (pkt_da & 0xFF000000) >> 24;
sprintf(pkt_tbuf, "%d.%d.%d.%d\n", pkt_tbuf_tmp[0], pkt_tbuf_tmp[1], pkt_tbuf_tmp[2], pkt_tbuf_tmp[3]);
I get a kernel panic error.
I am aware of the functionality memcmp to compare to characters.
It would be a great help if you experts would help me in converting this IP to char * and to compare the two IP's like memcmp(arp_tbuf, pkt_tbuf).
Thank you very much :)
EDIT
As @BobJarvis suggested, I ran the code again in my kernel. IT worked fine for converting the IPs in the LAN. However, When I loaded the web page, the kernel panic error occured. I there a cleaner way to perform this IP conversion from unsigned int into char * (dotted IP format) ?