• Post Reply Bookmark Topic Watch Topic
  • New Topic

Return IPv6 in Java  RSS feed

 
Kaplash Sharma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I'm trying to print ipv6 address of my system using following java program but it returns only ipv4 address.
When I do ipconfig it shows both ipv4 and ipv6 address.



Also on debugging i found though impl refers to Inet6Address but findNative() method of ClassLoader.class calls init() method of Inet4Address.class in place of calling init() method of Inet6Address.class
Anyone have any idea of why its doing this?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch. Try something like this:
 
Kaplash Sharma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the solution.It worked.
I have some doubts :
I have explicitly set system property to prefer ipv6 address then why the method returns ipv4 address.
System.setProperty("java.net.preferIPv6Addresses", "true");
a. does Java API does not honor the flag.
b. is there any way or flag to force JVM to use IPv6 if dual IP addresses are available.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that according to http://download.java.net/jdk7/archive/b123/docs/api/java/net/doc-files/net-properties.html, that property is not checked at runtime, but only at startup. So it may not have been in effect due to the way you set it.
 
Kaplash Sharma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I stopped all java processes and ran the program as follows
java -Djava.net.preferIPv6Addresses=true classname

but still it returned ipv4 address.Is this startup time.If not then can you please explain what is startup time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!