Subject: Re: htons - POSIX vs BSD
To: Ian Zagorskih <ianzag@megasignal.com>
From: Klaus Klein <kleink@mibh.de>
List: tech-userlevel
Date: 06/10/2004 13:26:18
On Thursday 10 June 2004 12:45, Ian Zagorskih wrote:
> $ uname -a
> NetBSD IANZAG 2.0_BETA NetBSD 2.0_BETA (IANZAG) #0: Thu Jun 3 20:54:46 NOVST
> 2004 ianzag@IANZAG:/usr/src/sys/arch/i386/compile/IANZAG i386
>
> According to htons manual page host/network convertion functions declared as:
>
> ---cut---
> SYNOPSIS
> #include <sys/types.h>
>
> in_addr_t
> htonl(in_addr_t host32);
>
> in_port_t
> htons(in_port_t host16);
>
> in_addr_t
> ntohl(in_addr_t net32);
>
> in_port_t
> ntohs(in_port_t net16);
> ---cut---
>
> ...which is not compatible with POSIX declaration:
> http://www.opengroup.org/onlinepubs/009695399/functions/htonl.html
In this context, there's no formal definition of "compatible".
> ---cut---
> SYNOPSIS
> #include <arpa/inet.h>
>
> uint32_t htonl(uint32_t hostlong);
> uint16_t htons(uint16_t hostshort);
> uint32_t ntohl(uint32_t netlong);
> uint16_t ntohs(uint16_t netshort);
> ---cut---
>
> Different header files, different types, even different goals of convertion -
> POSIX deals with any integers of fixed length and NetBSD deals only with
> internet port/address numbers.
>
> Maybe i'm missing something but this style looks a bit weird, don't you
> think ? :)
If you look at the history of these interfaces and don't ignore
standardization efforts long before POSIX-2001 you'll find it not
all that "weird", given the slow transition from short/long over
in_port_t/in_addr_t to uint16_t/uint32_t.
Now, in any case, if you have a look the implementation of these
you'll find that NetBSD has been using the XNS5-style declarations
for almost 3 years; it's just been missed to update the documentation
at that time.
- Klaus