standards/188316: Visibility of ntohl etc. and POSIX 2008
Christian Neukirchen
chneukirchen at gmail.com
Sun Apr 6 14:40:00 UTC 2014
>Number: 188316
>Category: standards
>Synopsis: Visibility of ntohl etc. and POSIX 2008
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-standards
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Sun Apr 06 14:40:00 UTC 2014
>Closed-Date:
>Last-Modified:
>Originator: Christian Neukirchen
>Release: 10.0-RELEASE
>Organization:
>Environment:
FreeBSD mneme.vuxu.org 10.0-RELEASE FreeBSD 10.0-RELEASE #0 r260789: Thu Jan 16 22:34:59 UTC 2014 root at snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64
>Description:
According to POSIX 2008, the functions ntohl etc. are defined in <arpa/inet.h> (http://pubs.opengroup.org/onlinepubs/9699919799/functions/htonl.html), which works because they are defined unconditionally there.
However, just including <netinet/in.h> 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 <arpa/inet.h>. Inclusion of the <netinet/in.h> header may
> also make visible all symbols from <arpa/inet.h>.
But ntohl etc are inside a "#if !defined(_KERNEL) && __BSD_VISIBLE" in <netinet/in.h>, violating the "shall be" requirement above.
>How-To-Repeat:
echo '#include <arpa/inet.h>\nint main(){htonl(1);}' | cc -D_XOPEN_SOURCE=700 -x c -
(all good)
echo '#include <netinet/in.h>\nint main(){htonl(1);}' | cc -D_XOPEN_SOURCE=700 -x c -
<stdin>: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.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-standards
mailing list