1

I have piece of code, which obtains local IPv6 address. gcc and clang with std=c99 crashes on those lines:

ipv6addr.s6_addr16[i] = htons((unsigned short int)tmp);

if (!(IN6_IS_ADDR_LOOPBACK(ipv6addr.s6_addr32)
        || IN6_IS_ADDR_UNSPECIFIED(ipv6addr.s6_addr32)
        || IN6_IS_ADDR_LINKLOCAL(ipv6addr.s6_addr32))){

ipv6.c:43:13: error: no member named 's6_addr16' in 'struct in6_addr'
                    ipv6addr.s6_addr16[i] = htons((unsigned short int)tmp);
                    ~~~~~~~~ ^
ipv6.c:45:39: error: no member named 's6_addr32' in 'struct in6_addr'
            if (!(IN6_IS_ADDR_LOOPBACK(ipv6addr.s6_addr32)
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~

etc.

Compiling with standard options results in success. Why is that? Full source is available at http://pastebin.com/hQ3VBSKe

aleek
  • 61
  • 6
  • 1
    If the compiler actually _crashes_ that's really bad news. I think the compiler is simply complaining about faulty code. – dschulz Apr 16 '12 at 16:30
  • Your code compiles here, but not without warnings. First, in line `#31` you're returning `NULL` from `int main()`. That's not ok, `return -1` or something, an `int`!. Then in line `#53` you use `printf()` without a format string. That's pretty ugly. Replace with something like `printf("Text: %s\n", txt_ipv6_address );` – dschulz Apr 16 '12 at 16:38
  • 1
    Sorry, I've not tried to compile with `-std=c99`. Now I see the errors. But again, the compiler **does not** crashes. – dschulz Apr 16 '12 at 16:45
  • yes, it does not crash. It does not compile this program. Please don't pay attention to another warnings and notices. Its not my code, I will fix them after fixing my main problem mentioned here :) – aleek Apr 16 '12 at 16:51

2 Answers2

2

Would appear to be an OSX artifact judging by related posts from 2007-2009,

+#if defined(__APPLE__) || defined(__darwin__)
+/* OSX seems not to define these. */
+#ifndef s6_addr16
+#define s6_addr16 __u6_addr.__u6_addr16
+#endif
+#ifndef s6_addr32
+#define s6_addr32 __u6_addr.__u6_addr32
+#endif
+#endif

http://archives.seul.org/or/cvs/Jul-2007/msg00167.html

Plus,

RFC 2553, UNP and SUS, in6_addr{} only requires s6_addr

http://seclists.org/nmap-dev/2009/q1/493

Steve-o
  • 12,678
  • 2
  • 41
  • 60
  • I have "#define s6_addr16 in6_u.u6_addr16" etc in my /usr/include/linux/in6.h – aleek Apr 16 '12 at 16:57
  • @aleek the problem is that IN6_IS_ADDR_LOOPBACK and the other macros used in the code references to a `s6_addr32` struct member that's not there anymore in the new `in6_addr` struct declaration. You can try replacing all `s6_addr32` to `s6_addr` and then redefining those macros in your code (copy from `/usr/include/netinet/in.h` and do the same with the `s6_addr32`) – dschulz Apr 16 '12 at 17:21
0

See declaration of struct in6_addr please. You need to compile as gnu99 to get extensions.

BTW error != crash

moorray
  • 577
  • 3
  • 9