Dear Histrung,
Below is the full codes. I replace some of it as per your advice. Another thing just to add I found out that the packet recieved is in ethernet format so the ip packet start only at offset 14. Can that be a cause here?
int i=0;
int j=0,line=0,packSize=h->len;
while(j<packSize/16)
{
printf("%06x: ",line++);
for(i=0;i<16;i++)
{
printf("%02x ",p[j*16+1]);
}
printf(" |");
for(i=0;i<16;i++)
{
if(isprint(p[j*16+1]))
printf("%c",p[j*16+1]);
else
printf(".");
}
printf("|\n");
j++;
}