IPv6 v IPv4 in Java

It turns out that if your Java app is getting IPv6 addresses back from InetAddress.getLocalHost().getHostAddress() you can use flags to the Java VM to control this behaviour

-Djava.net.preferIPv4Stack=true

if you only want IPv4 addresses returned, or

-Djava.net.preferIPv6Stack=true

if you need to test your code against IPv6 addresses. These flags are only valid when passed to the JVM when it’s started up (ie they can’t be changed once the App’s running).

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • digg
  • Ma.gnolia
  • NewsVine
  • Reddit
  • RawSugar

Leave a Reply

  • JoyOfTech

  • Recent Comments

  • Was it useful? Was it funny? Was it weird? Please tip the author!
  • Pages

  • Archives

  • Meta