From owner-freebsd-net@FreeBSD.ORG Wed Jun 23 13:33:32 2010 Return-Path: Delivered-To: net@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C5CC3106564A for ; Wed, 23 Jun 2010 13:33:32 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail01.syd.optusnet.com.au (mail01.syd.optusnet.com.au [211.29.132.182]) by mx1.freebsd.org (Postfix) with ESMTP id 5E3098FC0A for ; Wed, 23 Jun 2010 13:33:31 +0000 (UTC) Received: from c122-106-145-229.carlnfd1.nsw.optusnet.com.au (c122-106-145-229.carlnfd1.nsw.optusnet.com.au [122.106.145.229]) by mail01.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id o5NDXPdg006808 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 23 Jun 2010 23:33:28 +1000 Date: Wed, 23 Jun 2010 23:33:25 +1000 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Luigi Rizzo In-Reply-To: <20100622221228.GA93249@onelab2.iet.unipi.it> Message-ID: <20100623232402.X45536@delplex.bde.org> References: <20100622221228.GA93249@onelab2.iet.unipi.it> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Randall Stewart , net@FreeBSD.org Subject: Re: Observations from an old timer playing with 64 bit numbers... X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jun 2010 13:33:32 -0000 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