Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6718504

IN6_IS_ADDR_ANY tests only 12 bytes of 16-byte address

    Details

    • Subcomponent:
    • Resolved In Build:
      b94
    • CPU:
      sparc
    • OS:
      solaris_2.5.1
    • Verification:
      Verified

      Backports

        Description

        This is observed in Java 5 and Java 6.

        When called with -Djava.net.preferIPv6Addresses=true the call to DatagramSocket getLocalSocketAddress returns an all-zero address, instead of ::1.

                   InetAddress iNet = InetAddress.getByName("localhost");
                    DatagramSocket soc = new DatagramSocket( 12345, iNet);
                    SocketAddress sa = soc. getLocalSocketAddress();

                    System.out.println("iNet: " + iNet);
                    System.out.println("Expected: " + iNet + ":12345");
                    System.out.println("Returned: " + ((InetSocketAddress)sa).getAddress());
        workaround: Here's a fix:
        In net_util_md.h, the macro IN6_IS_ADDR_ANY is defined as:
        #define IN6_IS_ADDR_ANY(a) \
            (((a)->s6_words[0] == 0) && ((a)->s6_words[1] == 0) && \
            ((a)->s6_words[2] == 0) && ((a)->s6_words[3] == 0) && \
            ((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0))

        It should be:
        #define IN6_IS_ADDR_ANY(a) \
            (((a)->s6_words[0] == 0) && ((a)->s6_words[1] == 0) && \
            ((a)->s6_words[2] == 0) && ((a)->s6_words[3] == 0) && \
            ((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0) && \
            ((a)->s6_words[6] == 0) && ((a)->s6_words[7] == 0))

        IPV6 addresses are 16 bytes long, the macros only tests 12 bytes.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  chegar Chris Hegarty
                  Reporter:
                  dkorbel David Korbel (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: