diff options
author | Emil Ivov <emcho@jitsi.org> | 2006-12-04 21:43:45 +0000 |
---|---|---|
committer | Emil Ivov <emcho@jitsi.org> | 2006-12-04 21:43:45 +0000 |
commit | b6593380c08dfc30bead9b00fdc4b33800959f0c (patch) | |
tree | 8c905ae5c473c32241264aa73ddf16b98a110113 /src | |
parent | 75cb7535b10ae0fdf1b775461295e764660782ad (diff) | |
download | jitsi-b6593380c08dfc30bead9b00fdc4b33800959f0c.zip jitsi-b6593380c08dfc30bead9b00fdc4b33800959f0c.tar.gz jitsi-b6593380c08dfc30bead9b00fdc4b33800959f0c.tar.bz2 |
Made the getLocalHost() method slightly more aware of ipv6 addresses on Windows.
Diffstat (limited to 'src')
-rw-r--r-- | src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java b/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java index 71add8c..8bbf9de 100644 --- a/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java +++ b/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java @@ -14,6 +14,7 @@ import net.java.sip.communicator.service.netaddr.*; import net.java.sip.communicator.util.*; import net.java.stun4j.*; import net.java.stun4j.client.*; +import java.util.*; /** @@ -244,10 +245,42 @@ public class NetworkAddressManagerServiceImpl { try { - localHost = InetAddress.getLocalHost(); + //all that's inside the if is an ugly IPv6 hack + //(good ol' IPv6 - always causing more problems that it solves.) + if (intendedDestination instanceof Inet6Address) + { + //return the first globally routable ipv6 address we find + //on the machine (and hope it's a good one) + Enumeration interfaces + = NetworkInterface.getNetworkInterfaces(); + + while (interfaces.hasMoreElements()) + { + NetworkInterface iface + = (NetworkInterface)interfaces.nextElement(); + Enumeration addresses = iface.getInetAddresses(); + while(addresses.hasMoreElements()) + { + InetAddress address + = (InetAddress)addresses.nextElement(); + if(address instanceof Inet6Address) + { + if(!address.isAnyLocalAddress() + && !address.isLinkLocalAddress() + && !address.isSiteLocalAddress() + && !address.isLoopbackAddress()) + { + return address; + } + } + } + } + } + else + localHost = InetAddress.getLocalHost(); /** @todo test on windows for ipv6 cases */ } - catch (UnknownHostException ex) + catch (Exception ex) { //sigh ... ok return 0.0.0.0 logger.warn("Failed to get localhost ", ex); @@ -257,6 +290,7 @@ public class NetworkAddressManagerServiceImpl return localHost; } + /** * The method queries a Stun server for a binding for the specified port. * @param port the port to resolve (the stun message gets sent trhough that |