Re: 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,
Thnks, Mulyadi
May we know, what does "daddr" refer to?
oops ! I my bad !
Instead :  if  (htonl(0xC0A80067) == daddr)
it should be:
if  (htonl(0xC0A80067) == iph->daddr)
daddr is a field of ip header (struct iphdr) defined thus:
__be32	daddr

See: struct iphdr definition in include/linux/ip.h.

Regards,
Ian

On 6/9/07, Mulyadi Santosa <mulyadi.santosa@xxxxxxxxx> wrote:
Hi..
>
> 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.
Interesting. May we know, what does "daddr" refer to? I mean, clearly
that seems like local variable or local variable and the real "daddr" is
in the skb. So, are you sure it had pointed to the correct "daddr" ?
>
> 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 ?
>
AFAIK, you're correct. However, it won't hurt if you try some ordering
possibility like you said above. Please notice that I absolutely know
nothing about x86_64 byte ordering.

Good luck.

regards,

Mulyadi



--
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