From owner-freebsd-standards@FreeBSD.ORG Sun Apr 6 17:43:57 2014 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9F4CD1F8; Sun, 6 Apr 2014 17:43:57 +0000 (UTC) Received: from mail104.syd.optusnet.com.au (mail104.syd.optusnet.com.au [211.29.132.246]) by mx1.freebsd.org (Postfix) with ESMTP id 317CA74D; Sun, 6 Apr 2014 17:43:56 +0000 (UTC) Received: from c122-106-147-133.carlnfd1.nsw.optusnet.com.au (c122-106-147-133.carlnfd1.nsw.optusnet.com.au [122.106.147.133]) by mail104.syd.optusnet.com.au (Postfix) with ESMTPS id 90FDD42421F; Mon, 7 Apr 2014 03:43:47 +1000 (EST) Date: Mon, 7 Apr 2014 03:43:44 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Christian Neukirchen Subject: Re: standards/188316: Visibility of ntohl etc. and POSIX 2008 In-Reply-To: <201404061430.s36EUbFE092028@cgiserv.freebsd.org> Message-ID: <20140407024203.M6470@besplex.bde.org> References: <201404061430.s36EUbFE092028@cgiserv.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=U6SrU4bu c=1 sm=1 tr=0 a=7NqvjVvQucbO2RlWB8PEog==:117 a=PO7r1zJSAAAA:8 a=xzXVF2VtB1oA:10 a=kj9zAlcOel0A:10 a=JzwRw_2MAAAA:8 a=uZvujYp8AAAA:8 a=kLQtRtzyPeRkiQONIdsA:9 a=CjuIK1q_8ugA:10 a=50LJwXkts08A:10 a=nFfl2XBgbq4A:10 Cc: freebsd-gnats-submit@freebsd.org, freebsd-standards@freebsd.org X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Apr 2014 17:43:57 -0000 On Sun, 6 Apr 2014, Christian Neukirchen wrote: >> Description: > According to POSIX 2008, the functions ntohl etc. are defined in (http://pubs.opengroup.org/onlinepubs/9699919799/functions/htonl.html), which works because they are defined unconditionally there. > > However, just including should also define them (http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html): > >> The htonl(), htons(), ntohl(), and ntohs() functions shall be available >> as described in . Inclusion of the header may >> also make visible all symbols from . POSIX.1-2001 also says this. > But ntohl etc are inside a "#if !defined(_KERNEL) && __BSD_VISIBLE" in , violating the "shall be" requirement above. The requirement was somehow missed before. Probably due to its bad wording. The bad wording "shall be available" is only used for namespaces twice in POSIX.1-2001-draft7 (for {h_errno} in and for {ntoh*} in . The normal wording is "shall be defined as described in "). >> How-To-Repeat: > echo '#include \nint main(){htonl(1);}' | cc -D_XOPEN_SOURCE=700 -x c - > (all good) > > echo '#include \nint main(){htonl(1);}' | cc -D_XOPEN_SOURCE=700 -x c - > :2:12: warning: implicit declaration of function 'htonl' is invalid in C99 [-Wimplicit-function-declaration] > int main(){htonl(1);} > ^ > 1 warning generated. > >> Fix: > Guard the definition with __POSIX_VISIBLE >= 200112. This is wrong too, and is inconsistent with where there the symbols are defined unconditionally (if this wouldn't be redundant). The correctness of this depends on the symbols being in a header that doesn't exist in versions of POSIX that don't have the symbols. I think it is indeed correct, because POSIX started specifying both the symbols and the headers in 2001. Howver, the unconditional declarations may be wrong for XSI, and aren't really right for BSD. In 4.4BSD, they were declared unconditionally in via nested pollution from , and were only declared in the POSIX headers as a side effect of these headers being broken unless the application included . Similarly in FreeBSD-1 (and Net/2?). Applications written for this polluted API are no longer supported. However, the documented API (byteorder.3) was that these functions are declared in . It is now that these functions are declared in the 2 POSIX headers. In the kernel, the ntoh* family is still declared in , but this is misdocumented in byteorder.9 which says that these functions are declared in . actually declares almost all official endianness-related functions except these. and presumably all the functions of it are not documented in any application man page. mips still has bogus ntoh* functions in libc in asm. Bruce