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 !

有帮助吗?

解决方案

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, ...)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top