< prev index next >

src/java.base/share/classes/java/net/Inet6AddressImpl.java

Print this page
@@ -23,14 +23,13 @@
   * questions.
   */
  package java.net;
  
  import java.io.IOException;
+ import java.net.spi.InetAddressResolver.LookupPolicy;
  
- import static java.net.InetAddress.IPv6;
- import static java.net.InetAddress.PREFER_IPV6_VALUE;
- import static java.net.InetAddress.PREFER_SYSTEM_VALUE;
+ import static java.net.InetAddress.PLATFORM_LOOKUP_POLICY;
  
  /*
   * Package private implementation of InetAddressImpl for dual
   * IPv4/IPv6 stack.
   * <p>

@@ -46,12 +45,17 @@
   */
  final class Inet6AddressImpl implements InetAddressImpl {
  
      public native String getLocalHostName() throws UnknownHostException;
  
-     public native InetAddress[] lookupAllHostAddr(String hostname)
-         throws UnknownHostException;
+     public InetAddress[] lookupAllHostAddr(String hostname, LookupPolicy lookupPolicy)
+             throws UnknownHostException {
+         return lookupAllHostAddr(hostname, lookupPolicy.characteristics());
+     }
+ 
+     private native InetAddress[] lookupAllHostAddr(String hostname, int characteristics)
+             throws UnknownHostException;
  
      public native String getHostByAddr(byte[] addr) throws UnknownHostException;
  
      private native boolean isReachable0(byte[] addr, int scope, int timeout,
                                          byte[] inf, int ttl, int if_scope)

@@ -94,12 +98,13 @@
          return isReachable0(addr.getAddress(), scope, timeout, ifaddr, ttl, netif_scope);
      }
  
      public synchronized InetAddress anyLocalAddress() {
          if (anyLocalAddress == null) {
-             if (InetAddress.preferIPv6Address == PREFER_IPV6_VALUE ||
-                 InetAddress.preferIPv6Address == PREFER_SYSTEM_VALUE) {
+             int flags = PLATFORM_LOOKUP_POLICY.characteristics();
+             if (InetAddress.ipv6AddressesFirst(flags) ||
+                 InetAddress.systemAddressesOrder(flags)) {
                  anyLocalAddress = new Inet6Address();
                  anyLocalAddress.holder().hostName = "::";
              } else {
                  anyLocalAddress = (new Inet4AddressImpl()).anyLocalAddress();
              }

@@ -107,13 +112,13 @@
          return anyLocalAddress;
      }
  
      public synchronized InetAddress loopbackAddress() {
          if (loopbackAddress == null) {
-             boolean preferIPv6Address =
-                 InetAddress.preferIPv6Address == PREFER_IPV6_VALUE ||
-                 InetAddress.preferIPv6Address == PREFER_SYSTEM_VALUE;
+             int flags = PLATFORM_LOOKUP_POLICY.characteristics();
+             boolean preferIPv6Address = InetAddress.ipv6AddressesFirst(flags) ||
+                     InetAddress.systemAddressesOrder(flags);
  
              for (int i = 0; i < 2; i++) {
                  InetAddress address;
                  // Order the candidate addresses by preference.
                  if (i == (preferIPv6Address ? 0 : 1)) {
< prev index next >