Reputation: 1998
please look at the code snippet
char ipAddr[] = {192, 168, 88, 2};
struct iphdr *ip_hdr = (struct iphdr*)(some_valid_eth_hdr_pointer + 1);
if (0 == memcmp((void*)(ip_hdr->saddr), (void*)ipAddr, 4)) /*memcmp cause my whole system crashed*/
{
printk("ip source addr matched\n");
}
the code is extracted from a linux netfilter hook function, which means the ip_hdr->saddr may belongs to the kernel space memory, and i am pretty sure the ip_hdr points to valid memory. still dont know what the problem is, so please help me out.
thanks in advance !
Upvotes: 1
Views: 174
Reputation: 26322
Well, here's your problem:
memcmp((void*)(ip_hdr->saddr), ...
This interprets the source IP address as a pointer. What you wanted to do was this:
memcmp(&ip_hdr->saddr, ...)
Upvotes: 1