Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 05 Jun 2008 00:33:19 +0200
From:      Nanno Langstraat <nlcom_os@ii.nl>
To:        freebsd-hackers@freebsd.org
Subject:   Standard byteorder functions across BSD / Linux
Message-ID:  <4847182F.80105@ii.nl>

next in thread | raw e-mail | index | archive | help
Hello,

I think it would be nice to have standard byteorder conversion functions for user applications across the BSDs and Linux.
betoh64(), htobe64(), etc.  (like OpenBSD's sys/endian.h)

Just small convenience functions/macros, but useful because it's such a common requirement; applications currently have to roll their own over&over with an annoying tangle of #ifdefs.

Summary of the story so far:

    * glibc added the basic macros to <endian.h>

    * OpenBSD already had the macros in <sys/endian.h>. They are for
      both kernel and application use according to the manpage.
      OpenBSD didn't want my patch that made <endian.h> the standard
      include file for user applications.

    * FreeBSD has similar but incompatible macros in <sys/endian.h>.
      They are for kernel use, not application use according to the manpage.

Full details below. (pretty long story for such a tiny feature)

----

My original proposal to the GNU glibc maintainers:

* glibc Bugzilla 6442 - Adding cross-Unix endianness functions:
  betoh() / htobe() 64,32,16
    http://sources.redhat.com/bugzilla/show_bug.cgi?id=6442

* Pro/con:
    http://sourceware.org/ml/libc-alpha/2008-05/msg00022.html

----

I planned to have a little coordination between glibc/FreeBSD/OpenBSD before starting on patches. That didn't happen, the glibc maintainers gave zero response for a full month, then created the basic macros in /usr/include/endian.h without any discussion.

  * ('endian.h' pre-existed in glibc to define __LITTLE_ENDIAN etc. The
    file does not pre-exist on OpenBSD / FreeBSD)

  * (glibc didn't adopt the "swap64()" etc. functions. Glibc already
    contains variants with a different naming pattern: "bswap_64()"
    etc.)

  * (be32enc() and friends only got a small mention by me, not adopted
    by glibc)

----

The discussion on the OpenBSD mailinglist can be read here:
http://thread.gmane.org/gmane.os.openbsd.tech/15161/focus=15161

Of particular interest to FreeBSD: this charmless but informative email by Theo de Raadt, which outlines the history of the BSD kernel byteorder functions:
http://thread.gmane.org/gmane.os.openbsd.tech/15161/focus=15179

============================================================

My question to FreeBSD: 
I don't use FreeBSD myself, but I'll prepare a patch if you like the idea and if you indicate what you'll accept:

    * <endian.h> or <sys/endian.h> ?
      I maintain that it should be <endian.h> for user applications:
      IMHO <sys/> is for the user-kernel API, and byteorder belongs to
      libc not the kernel API.
      glibc apparently agrees, OpenBSD disagreed.

    * You're OK with userspace applications standardizing on OpenBSD's
      original betoh64() instead of FreeBSD's derivate be64toh() ?

    Regards,
    Nanno





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