Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 6 Apr 2014 14:30:37 GMT
From:      Christian Neukirchen <chneukirchen@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   standards/188316: Visibility of ntohl etc. and POSIX 2008
Message-ID:  <201404061430.s36EUbFE092028@cgiserv.freebsd.org>
Resent-Message-ID: <201404061440.s36Ee0St014046@freefall.freebsd.org>

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

>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@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:



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