Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Jun 2010 23:33:25 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Luigi Rizzo <rizzo@iet.unipi.it>
Cc:        Randall Stewart <rrs@lakerest.net>, net@FreeBSD.org
Subject:   Re: Observations from an old timer playing with 64 bit numbers...
Message-ID:  <20100623232402.X45536@delplex.bde.org>
In-Reply-To: <20100622221228.GA93249@onelab2.iet.unipi.it>
References:  <E3C4102C-3106-4D5B-86E5-8D5BDD7FD442@lakerest.net> <20100622221228.GA93249@onelab2.iet.unipi.it>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 23 Jun 2010, Luigi Rizzo wrote:

> On Tue, Jun 22, 2010 at 05:46:02PM -0400, Randall Stewart wrote:
>> Hi all:
>>
>> I have had some fun in my day job playing with exchanging 64bit
>> numbers. Unfortunately
>> there is no ntohll() OR htonll() which would be the logical thing (for
>> us old farts) to use.
>>
>> Yes, I have found htobe64() and friends.. and that would work.. but I
>> still cannot
>> help but feeling we should have the ntohll() and htonll().. for
>> consistency if nothing
>> else.
>>
>> Any objections to this showing up in a head near you soon (speak soon
>> or I will commit
>> the patches to add these ;-D)
>
> strong objection!
> We should instead use names with exact sizes (16,32,64).

Yes, long long should not exist, and there are few places where exact
sizes should be used, but networking code is one place where they
should be used.

ntohs() will break semantically or actually on machines with shorts with
more than 16 bits.

ntohl() is already broken semantically on machines with longs with
more than 32 bits (all 64-bit arches in FreeBSD).  It doesn't actually
handle longs on such arches.  Networking code handles a few cases related
to this with n_long.  This is not quite as bad, but its name is nonsense --
n_long is very far from being a long -- it is unsigned 32 bits exactly,
unlike long which is signed >= 32 bits.

ntohll() would break similarly on machines with long longs with more
or less than 64 bits.  In practice this and other misuses of long long
may prevent the size of long long being changed, like it prevented the
size of long being changed on some systems with historical abuses of
long.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100623232402.X45536>