Redefinition of s6_addr in Linux environnement

Asked by FWX

 Hello,

 While cross-compiling the rohc-tcp branch, I encounter a problem of redefinition for s6_addrXXX :

In file src/common/protocols/ipv6.h :

/**
 * @brief The IPv6 address
 */
struct ipv6_addr
{
        union
        {
                uint8_t __u6_addr8[16];
                uint16_t __u6_addr16[8];
                uint32_t __u6_addr32[4];
        } __in6_u;
#define s6_addr __in6_u.__u6_addr8
#define s6_addr16 __in6_u.__u6_addr16
#define s6_addr32 __in6_u.__u6_addr32
};

With last GCC, it is the same definitions in file /usr/include/netinet/in.h

/* IPv6 address */
struct in6_addr
  {
    union
      {
        uint8_t __u6_addr8[16];
#if defined __USE_MISC || defined __USE_GNU
        uint16_t __u6_addr16[8];
        uint32_t __u6_addr32[4];
#endif
      } __in6_u;
#define s6_addr __in6_u.__u6_addr8
#if defined __USE_MISC || defined __USE_GNU
# define s6_addr16 __in6_u.__u6_addr16
# define s6_addr32 __in6_u.__u6_addr32
#endif
  };

But with the cross-compiler for ARM (or PowerPC), it is NOT the same definitions in file /usr/include/netinet/in.h

/* IPv6 address */
struct in6_addr
  {
    union
      {
        uint8_t u6_addr8[16];
        uint16_t u6_addr16[8];
        uint32_t u6_addr32[4];
      } in6_u;
#define s6_addr in6_u.u6_addr8
#define s6_addr16 in6_u.u6_addr16
#define s6_addr32 in6_u.u6_addr32
  };

 Can you add test for definition of _NETINET_IN_H before define s6_addrXXX in your common/protocols/ipv6.h file ?

/**
 * @brief The IPv6 address
 */
struct ipv6_addr
{
        union
        {
                uint8_t __u6_addr8[16];
                uint16_t __u6_addr16[8];
                uint32_t __u6_addr32[4];
        } __in6_u;
#ifndef _NETINET_IN_H
#define s6_addr __in6_u.__u6_addr8
#define s6_addr16 __in6_u.__u6_addr16
#define s6_addr32 __in6_u.__u6_addr32
#endif
};

 Thank you,

 Best regards,

            FWX.

Question information

Language:
English Edit question
Status:
Solved
For:
rohc Edit question
Assignee:
No assignee Edit question
Solved by:
FWX
Solved:
Last query:
Last reply:
Revision history for this message
Didier Barvaux (didier-barvaux) said :
#1

> Can you add test for definition of _NETINET_IN_H before define s6_addrXXX in your common/protocols/ipv6.h file ?

Sorry, no. The definition from protocols/ipv6.h is embedded in the library to be portable on Windows and BSD. I tried to do it with ifdef, but it was a nightmare. To avoid problems, do not use netinet/in.h inside the library. Use the definition from protocols/ipv6.h instead.

Regards,
Didier

Revision history for this message
FWX (dialine-rohc-team) said :
#2

 Didier,

 You embeded the structure, that's ok, but with another name (struct ipv6_addr != struct in6_addr) but you use the same name for the macros s6_addrXXX: this is an error in my mind!
 I think it would be better to change the name of them, like st6_addrXXX for example...
 Actually, I can't build the library for ARM or PPC platform, and test it.

Revision history for this message
FWX (dialine-rohc-team) said :
#3

 Didier,

 In file comp/c_ip.c, file "c_ip.h" is included.

 c_ip.h includes <arpa/inet.h>

and then arpa/inet.h includes <netinet/in.h> where s6_addr are defined!

Can you do some corrdction about that point, please ?

Revision history for this message
FWX (dialine-rohc-team) said :
#4

Hello,

 I propose to rename s6_addrXXX definitions in src/common/ipv6.h to su6_addrXXX, so that, there no conflict with definitions in linux include file /netinet/in.h
 Then, I propose to use these new definitions in src/common/ip.h file

Here is the patch :

=== modified file 'src/common/ip.h'
--- src/common/ip.h 2012-09-16 14:13:44 +0000
+++ src/common/ip.h 2012-10-31 10:29:29 +0000
@@ -203,7 +203,7 @@

 /// The data to print an IPv6 address in (struct ipv6_addr *) format
 #define IPV6_ADDR_IN6(x) \
- IPV6_ADDR_RAW((x)->s6_addr)
+ IPV6_ADDR_RAW((x)->su6_addr)

 /// The data to print an IPv6 address in raw format
 #define IPV6_ADDR_RAW(x) \
@@ -212,10 +212,10 @@

 /// Compare two IPv6 addresses in (struct ipv6_addr *) format
 #define IPV6_ADDR_CMP(x, y) \
- ((x)->s6_addr32[0] == (y)->s6_addr32[0] && \
- (x)->s6_addr32[1] == (y)->s6_addr32[1] && \
- (x)->s6_addr32[2] == (y)->s6_addr32[2] && \
- (x)->s6_addr32[3] == (y)->s6_addr32[3])
+ ((x)->su6_addr32[0] == (y)->su6_addr32[0] && \
+ (x)->su6_addr32[1] == (y)->su6_addr32[1] && \
+ (x)->su6_addr32[2] == (y)->su6_addr32[2] && \
+ (x)->su6_addr32[3] == (y)->su6_addr32[3])

 /*

=== modified file 'src/common/protocols/ipv6.h'
--- src/common/protocols/ipv6.h 2012-09-16 14:13:44 +0000
+++ src/common/protocols/ipv6.h 2012-10-31 10:29:51 +0000
@@ -44,9 +44,9 @@
   uint16_t __u6_addr16[8];
   uint32_t __u6_addr32[4];
  } __in6_u;
-#define s6_addr __in6_u.__u6_addr8
-#define s6_addr16 __in6_u.__u6_addr16
-#define s6_addr32 __in6_u.__u6_addr32
+#define su6_addr __in6_u.__u6_addr8
+#define su6_addr16 __in6_u.__u6_addr16
+#define su6_addr32 __in6_u.__u6_addr32
 };

Revision history for this message
Didier Barvaux (didier-barvaux) said :
#5

I fixed the problem in main branch. See http://bazaar.launchpad.net/~didier-barvaux/rohc/main/revision/614

Regards,
Didier