Re: ntohs/ntohl and bitops

From: YOSHIFUJI Hideaki / 吉藤英明
Date: Sat Jan 14 2006 - 04:50:00 EST


In article <20060112010406.GA2367@xxxxxx> (at Thu, 12 Jan 2006 01:04:06 +0000), Pavel Machek <pavel@xxxxxx> says:

>
> On Wed 11-01-06 00:00:20, David S. Miller wrote:
> > From: Ulrich Drepper <drepper@xxxxxxxxxx>
> > Date: Tue, 10 Jan 2006 14:02:52 -0800
> >
> > > I just saw this in a patch:
> > >
> > > + if (ntohs(ih->frag_off) & IP_OFFSET)
> > > + return EBT_NOMATCH;
> > >
> > > This isn't optimal, it requires a byte switch little endian machines.
> > > The compiler isn't smart enough. It would be better to use
> > >
> > > if (ih->frag_off & ntohs(IP_OFFSET))
:
> Could you possibly
> #define IP_OFFSET htons(1234)
> ?

In this case, you should use __constant_htons().
I still prefer:
if (ih->frag_off & htons(IP_OFFSET))
though.

--yoshfuji
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/