netinet/in.h address check macros such as IN6_IS_ADDR_V4MAPPED broken in strict conformance mode (gcc -std=c99)

Bug #1187301 reported by Matthias Andree
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
eglibc (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

The eglibc netinet/in.h macros to deal with IPv6 address classes are broken in strict conformance mode because they access symbols that are not expose in strict conformance mode.

The macros should be looking at s6_addr, rather than s6_addr32.

Download the attached try.c and then see:

: this is relaxed mode:
$ gcc -c -Wall -Wextra -std=gnu99 /tmp/try.c -o /tmp/try.o
(no console output -> success)

: this is conformance mode (c99 instead of gnu99):
$ LC_ALL=C gcc -c -Wall -Wextra -std=c99 /tmp/try.c -o /tmp/try.o
/tmp/try.c: In function 'f':
/tmp/try.c:5:18: error: 'const struct in6_addr' has no member named 's6_addr32'
/tmp/try.c:5:18: error: 'const struct in6_addr' has no member named 's6_addr32'
/tmp/try.c:5:18: error: 'const struct in6_addr' has no member named 's6_addr32'

Line numbers in try.c are:

     1 #include <netinet/in.h>
     2
     3 int f(void) {
     4 struct sockaddr_in6 sa;
     5 int result = IN6_IS_ADDR_V4MAPPED(&sa.sin6_addr);
     6 return result;
     7 }

POSIX:

       The <netinet/in.h> header shall define the in6_addr structure that contains at
       least the following member:

              uint8_t s6_addr[16]

So s6_addr32 is unavailable in strict mode (this is deliberate through preprocessing inside in.h near line 209):

   197 /* IPv6 address */
   198 struct in6_addr
   199 {
   200 union
   201 {
   202 uint8_t __u6_addr8[16];
   203 #if defined __USE_MISC || defined __USE_GNU
   204 uint16_t __u6_addr16[8];
   205 uint32_t __u6_addr32[4];
   206 #endif
   207 } __in6_u;
   208 #define s6_addr __in6_u.__u6_addr8
   209 #if defined __USE_MISC || defined __USE_GNU
   210 # define s6_addr16 __in6_u.__u6_addr16
   211 # define s6_addr32 __in6_u.__u6_addr32
   212 #endif
   213 };
   214

Workaround:

#define _GNU_SOURCE
_before_ the very first #include line in the same compilation unit (.c file)

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: libc6-dev 2.15-0ubuntu10.4
ProcVersionSignature: Ubuntu 3.2.0-45.70-generic 3.2.44
Uname: Linux 3.2.0-45-generic x86_64
NonfreeKernelModules: fglrx
ApportVersion: 2.0.1-0ubuntu17.2
Architecture: amd64
Date: Tue Jun 4 10:30:53 2013
MarkForUpload: True
ProcEnviron:
 LANGUAGE=de_DE:en
 TERM=xterm
 PATH=(custom, no user)
 LANG=de_DE.UTF-8
 SHELL=/bin/bash
SourcePackage: eglibc
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Matthias Andree (matthias-andree) wrote :
Changed in eglibc (Ubuntu):
status: New → Confirmed
Revision history for this message
Matthias Andree (matthias-andree) wrote :

confirmed from reading the affected .h file

Revision history for this message
Matthias Andree (matthias-andree) wrote :

Bug did not show in previous Ubuntu versions, but no version walk has been made to check the date of introduction (too much effort for this obvious bug).

description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.