Subject: Re: getting rid of NTOHS() in ip_input()
To: None <itojun@iijlab.net>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: tech-net
Date: 08/13/2002 07:21:48
On Tue, Aug 13, 2002 at 02:28:54PM +0900, itojun@iijlab.net wrote:
> byte-swapping constant is good. i've updated my tree.
>
> > > @@ -764,3 +759,3 @@
> > > */
> > > - if (mff || ip->ip_off) {
> > > + if (mff || ntohs(ip->ip_off)) {
> >Don't need to byte-swap if you're testing != 0.
>
> for completeness i'd like to have it.
Then you could so:
if (mff || ip->ip_off != htons(0)) {
which byte-swaps a constant, which the compiler will optimize away :-)
>
> > > Index: netinet/raw_ip.c
> > > ===================================================================
> > > RCS file: /cvsroot/syssrc/sys/netinet/raw_ip.c,v
> > > retrieving revision 1.61
> > > diff -u -1 -r1.61 raw_ip.c
> > > --- netinet/raw_ip.c 2002/06/09 16:33:43 1.61
> > > +++ netinet/raw_ip.c 2002/08/12 22:57:50
> > > @@ -165,5 +165,7 @@
> > > * XXX Compatibility: programs using raw IP expect ip_len
> > > - * XXX to have the header length subtracted.
> > > + * XXX to have the header length subtracted, and in host order.
> > > + * XXX ip_off is also expected to be host order.
> > > */
> > > - ip->ip_len -= ip->ip_hl << 2;
> > > + ip->ip_len = ntohs(ip->ip_len) - (ip->ip_hl << 2);
> > > + NTOHS(ip->ip_off);
> >You're converting from host-to-net, so use htons() and HTONS(), right?
>
> no, this is in rip_input, so net-to-host.
Ah, sorry, my mistake (that's what I get for reviewing code right before
I go to bed :-)
--
-- Jason R. Thorpe <thorpej@wasabisystems.com>