2

Disclaimer: networking is not my strong suit. This may be a very basic question.

Why, when I bind a socket to 0.0.0.0, does Java also bind to the equivalent of :: (IP6)? I thought that 0.0.0.0, being in dotted quad notation, represents "any IP4 address", not "any IP address, 4 and/or 6".

I'm aware of the -Djava.net.preferIPv4Stack=true system property setting, but I'm not asking about that. I'm asking specifically why Java interprets 0.0.0.0 as "any address at all, IP4 or IP6".

Laird Nelson
  • 15,321
  • 19
  • 73
  • 127
  • https://stackoverflow.com/a/11110685/514463 – DavidC Jan 10 '19 at 18:12
  • Well, this answer is actually exactly my question: it states that "Using 0.0.0.0 will only bind to IPv4-enabled interfaces." But of course my question is that given that this is demonstrably false for Java programs, why? – Laird Nelson Jan 10 '19 at 18:19
  • Or, in StackOverflow link parlance: https://stackoverflow.com/a/3655796/208288 :-) – Laird Nelson Jan 10 '19 at 18:25
  • 1
    In that question, there is also another answer that says binding to 0.0.0.0 binds to all addresses, if you tested it, and that is indeed the case, I suggest you upvote that one – Ferrybig Jan 10 '19 at 18:26
  • I understand that it does indeed do this in a Java program. My question is why, given that `0.0.0.0` is supposed to bind only to IP4 addresses, not IP6 addresses. – Laird Nelson Jan 10 '19 at 18:30
  • https://docs.oracle.com/javase/8/docs/technotes/guides/net/ipv6_guide/ – Jin Kwon Sep 02 '23 at 15:44

0 Answers0