lkml.org 
[lkml]   [2006]   [Jan]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: ntohs/ntohl and bitops

On Wed 11-01-06 00:00:20, David S. Miller wrote:
> From: Ulrich Drepper <drepper@redhat.com>
> 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))
> >
> > where the byte-swap can be done at compile time. This is kind of ugly,
> > I guess, so maybe a dedicate macro
> >
> > net_host_bit_p(ih->frag_off, IP_OFFSET)
>
> The first suggestion isn't considered ugly, and the best form is:
>
> if (ih->frag_off & __constant_htons(IP_OFFSET))
>
> I'll fix that up when I get a chance, thanks for catching it Uli.

Could you possibly
#define IP_OFFSET htons(1234)
?

Noone should need it in native endianity, no?

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

\
 
 \ /
  Last update: 2006-01-14 10:36    [W:0.096 / U:1.380 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site