< prev index next >

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

Print this page




  32 import java.security.AccessController;
  33 import java.io.File;
  34 import java.io.FileNotFoundException;
  35 import java.io.ObjectStreamException;
  36 import java.io.ObjectStreamField;
  37 import java.io.IOException;
  38 import java.io.InvalidObjectException;
  39 import java.io.ObjectInputStream;
  40 import java.io.ObjectInputStream.GetField;
  41 import java.io.ObjectOutputStream;
  42 import java.io.ObjectOutputStream.PutField;
  43 import java.lang.annotation.Native;
  44 import java.util.concurrent.ConcurrentHashMap;
  45 import java.util.concurrent.ConcurrentMap;
  46 import java.util.concurrent.ConcurrentSkipListSet;
  47 import java.util.concurrent.atomic.AtomicLong;
  48 import java.util.Arrays;
  49 
  50 import jdk.internal.access.JavaNetInetAddressAccess;
  51 import jdk.internal.access.SharedSecrets;

  52 import sun.security.action.*;
  53 import sun.net.InetAddressCachePolicy;
  54 import sun.net.util.IPAddressUtil;
  55 
  56 /**
  57  * This class represents an Internet Protocol (IP) address.
  58  *
  59  * <p> An IP address is either a 32-bit or 128-bit unsigned number
  60  * used by IP, a lower-level protocol on which protocols like UDP and
  61  * TCP are built. The IP address architecture is defined by <a
  62  * href="http://www.ietf.org/rfc/rfc790.txt"><i>RFC&nbsp;790:
  63  * Assigned Numbers</i></a>, <a
  64  * href="http://www.ietf.org/rfc/rfc1918.txt"> <i>RFC&nbsp;1918:
  65  * Address Allocation for Private Internets</i></a>, <a
  66  * href="http://www.ietf.org/rfc/rfc2365.txt"><i>RFC&nbsp;2365:
  67  * Administratively Scoped IP Multicast</i></a>, and <a
  68  * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC&nbsp;2373: IP
  69  * Version 6 Addressing Architecture</i></a>. An instance of an
  70  * InetAddress consists of an IP address and possibly its
  71  * corresponding host name (depending on whether it is constructed


 903          * @param addr byte array representing an IP address
 904          * @return {@code String} representing the host name mapping
 905          * @throws UnknownHostException
 906          *             if no host found for the specified IP address
 907          */
 908         String getHostByAddr(byte[] addr) throws UnknownHostException;
 909 
 910     }
 911 
 912     /**
 913      * The default NameService implementation, which delegates to the underlying
 914      * OS network libraries to resolve host address mappings.
 915      *
 916      * @since 9
 917      */
 918     private static final class PlatformNameService implements NameService {
 919 
 920         public InetAddress[] lookupAllHostAddr(String host)
 921             throws UnknownHostException
 922         {
 923             return impl.lookupAllHostAddr(host);
 924         }
 925 
 926         public String getHostByAddr(byte[] addr)
 927             throws UnknownHostException
 928         {
 929             return impl.getHostByAddr(addr);
 930         }
 931     }
 932 
 933     /**
 934      * The HostsFileNameService provides host address mapping
 935      * by reading the entries in a hosts file, which is specified by
 936      * {@code jdk.net.hosts.file} system property
 937      *
 938      * <p>The file format is that which corresponds with the /etc/hosts file
 939      * IP Address host alias list.
 940      *
 941      * <p>When the file lookup is enabled it replaces the default NameService
 942      * implementation
 943      *
 944      * @since 9
 945      */
 946     private static final class HostsFileNameService implements NameService {
 947 
 948         private final String hostsFile;
 949 




  32 import java.security.AccessController;
  33 import java.io.File;
  34 import java.io.FileNotFoundException;
  35 import java.io.ObjectStreamException;
  36 import java.io.ObjectStreamField;
  37 import java.io.IOException;
  38 import java.io.InvalidObjectException;
  39 import java.io.ObjectInputStream;
  40 import java.io.ObjectInputStream.GetField;
  41 import java.io.ObjectOutputStream;
  42 import java.io.ObjectOutputStream.PutField;
  43 import java.lang.annotation.Native;
  44 import java.util.concurrent.ConcurrentHashMap;
  45 import java.util.concurrent.ConcurrentMap;
  46 import java.util.concurrent.ConcurrentSkipListSet;
  47 import java.util.concurrent.atomic.AtomicLong;
  48 import java.util.Arrays;
  49 
  50 import jdk.internal.access.JavaNetInetAddressAccess;
  51 import jdk.internal.access.SharedSecrets;
  52 import jdk.internal.misc.Blocker;
  53 import sun.security.action.*;
  54 import sun.net.InetAddressCachePolicy;
  55 import sun.net.util.IPAddressUtil;
  56 
  57 /**
  58  * This class represents an Internet Protocol (IP) address.
  59  *
  60  * <p> An IP address is either a 32-bit or 128-bit unsigned number
  61  * used by IP, a lower-level protocol on which protocols like UDP and
  62  * TCP are built. The IP address architecture is defined by <a
  63  * href="http://www.ietf.org/rfc/rfc790.txt"><i>RFC&nbsp;790:
  64  * Assigned Numbers</i></a>, <a
  65  * href="http://www.ietf.org/rfc/rfc1918.txt"> <i>RFC&nbsp;1918:
  66  * Address Allocation for Private Internets</i></a>, <a
  67  * href="http://www.ietf.org/rfc/rfc2365.txt"><i>RFC&nbsp;2365:
  68  * Administratively Scoped IP Multicast</i></a>, and <a
  69  * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC&nbsp;2373: IP
  70  * Version 6 Addressing Architecture</i></a>. An instance of an
  71  * InetAddress consists of an IP address and possibly its
  72  * corresponding host name (depending on whether it is constructed


 904          * @param addr byte array representing an IP address
 905          * @return {@code String} representing the host name mapping
 906          * @throws UnknownHostException
 907          *             if no host found for the specified IP address
 908          */
 909         String getHostByAddr(byte[] addr) throws UnknownHostException;
 910 
 911     }
 912 
 913     /**
 914      * The default NameService implementation, which delegates to the underlying
 915      * OS network libraries to resolve host address mappings.
 916      *
 917      * @since 9
 918      */
 919     private static final class PlatformNameService implements NameService {
 920 
 921         public InetAddress[] lookupAllHostAddr(String host)
 922             throws UnknownHostException
 923         {
 924             return Blocker.run(() -> impl.lookupAllHostAddr(host));
 925         }
 926 
 927         public String getHostByAddr(byte[] addr)
 928             throws UnknownHostException
 929         {
 930             return Blocker.run(() -> impl.getHostByAddr(addr));
 931         }
 932     }
 933 
 934     /**
 935      * The HostsFileNameService provides host address mapping
 936      * by reading the entries in a hosts file, which is specified by
 937      * {@code jdk.net.hosts.file} system property
 938      *
 939      * <p>The file format is that which corresponds with the /etc/hosts file
 940      * IP Address host alias list.
 941      *
 942      * <p>When the file lookup is enabled it replaces the default NameService
 943      * implementation
 944      *
 945      * @since 9
 946      */
 947     private static final class HostsFileNameService implements NameService {
 948 
 949         private final String hostsFile;
 950 


< prev index next >