Re: [conntrack-tools PATCH] conntrack: Fix CIDR to mask conversion on Big Endian

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

 



Hi,

On Wed, Sep 04, 2019 at 10:21:28AM +0200, Florian Westphal wrote:
> Phil Sutter <phil@xxxxxx> wrote:
> > What we need in b is 'ff ff ff 00' for a prefix length of 24. Your
> > suggested alternative does not compile, so I tried both options for the
> > closing brace:
> > 
> > | htonl((1 << 24) - 1)
> > 
> > This turns into '00 ff ff ff' for both LE and BE, the opposite of what
> > we need.
> > 
> > | htonl((1 << 24)) - 1
> > 
> > This turns into '00 00 00 00' on LE and '00 ff ff ff' on BE.
> > 
> > My code leads to correct result on either architecture and I don't see a
> > simpler way of doing it.
> 
> htonl(~0u << (32 - i)) would work, assuming i > 0 and <= 32.

Ah, indeed! Left-shifting all-ones didn't come to mind. I'll send a v2.

Thanks, Phil



[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux