Comparing 32 bit address from an ip header in a kernel module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I am writing a kernel module which deals with security.
I am able to catch packets correctly. I want to compare the value of
destination address in the ip header agains a specified ip, where the
specified ip
is in the form : "192.168.0.103".

The destination address I am talking about is fron the ip header of the
frame; to be more specific, I am talking about an instance of iphdr struct
from include/linux/ip.h.
This struct has the following member:
	__be32	daddr;
	
	- which is the destination ip address. (32 bits).
	
The specified ip I am talking about is : 192.168.0.103

Now, how should I comapare the value of daddr (which is __be32) in my module
to that specified ip : "192.168.0.103"?

I tried the following:
  ...
	 struct iphdr *iph;
	 iph = skb->nh.iph;
	 if (iph)
	 	{
		if  (htonl(0xC0A80067) == daddr)
	 	  printk("got daddr=192.168.0.103\n");
               else
			printk("did not get daddr=192.168.0.103\n");
		}
		
And I get **wrong** answer , namely it prints: "did not get daddr" , even
though I know for sure that the daddr of the ip header is 192.168.0.103.
		
I think that the hex representation for
192.168.0.103 is 0xC0A80067; am I right in this ? (I caclulated this thus:
C0=192, A8=168, 00=0, 67=103).
But maybe the order of the bytes should be different ? something like:
if  (htonl(0x6700A8C0) == daddr)
	 	printk("got daddr=192.168.0.103\n");
Or is there another way I should do this ?

Any help will be appreciated!


(I want to add that I am working on x86_64 machine with Intel processor.)

Regards,
Ian

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux