< prev index next >

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

Print this page




  55  * This class represents an Internet Protocol (IP) address.
  56  *
  57  * <p> An IP address is either a 32-bit or 128-bit unsigned number
  58  * used by IP, a lower-level protocol on which protocols like UDP and
  59  * TCP are built. The IP address architecture is defined by <a
  60  * href="http://www.ietf.org/rfc/rfc790.txt"><i>RFC&nbsp;790:
  61  * Assigned Numbers</i></a>, <a
  62  * href="http://www.ietf.org/rfc/rfc1918.txt"> <i>RFC&nbsp;1918:
  63  * Address Allocation for Private Internets</i></a>, <a
  64  * href="http://www.ietf.org/rfc/rfc2365.txt"><i>RFC&nbsp;2365:
  65  * Administratively Scoped IP Multicast</i></a>, and <a
  66  * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC&nbsp;2373: IP
  67  * Version 6 Addressing Architecture</i></a>. An instance of an
  68  * InetAddress consists of an IP address and possibly its
  69  * corresponding host name (depending on whether it is constructed
  70  * with a host name or whether it has already done reverse host name
  71  * resolution).
  72  *
  73  * <h3> Address types </h3>
  74  *
  75  * <blockquote><table class="borderless">
  76  *   <caption style="display:none">Description of unicast and multicast address types</caption>



  77  *   <tbody>
  78  *   <tr><th style="vertical-align:top"><i>unicast</i></th>
  79  *       <td>An identifier for a single interface. A packet sent to
  80  *         a unicast address is delivered to the interface identified by
  81  *         that address.
  82  *
  83  *         <p> The Unspecified Address -- Also called anylocal or wildcard
  84  *         address. It must never be assigned to any node. It indicates the
  85  *         absence of an address. One example of its use is as the target of
  86  *         bind, which allows a server to accept a client connection on any
  87  *         interface, in case the server host has multiple interfaces.
  88  *
  89  *         <p> The <i>unspecified</i> address must not be used as
  90  *         the destination address of an IP packet.
  91  *
  92  *         <p> The <i>Loopback</i> Addresses -- This is the address
  93  *         assigned to the loopback interface. Anything sent to this
  94  *         IP address loops around and becomes IP input on the local
  95  *         host. This address is often used when testing a
  96  *         client.</td></tr>
  97  *   <tr><th style="vertical-align:top"><i>multicast</i></th>
  98  *       <td>An identifier for a set of interfaces (typically belonging
  99  *         to different nodes). A packet sent to a multicast address is
 100  *         delivered to all interfaces identified by that address.</td></tr>
 101  * </tbody>
 102  * </table></blockquote>
 103  *
 104  * <h4> IP address scope </h4>
 105  *
 106  * <p> <i>Link-local</i> addresses are designed to be used for addressing
 107  * on a single link for purposes such as auto-address configuration,
 108  * neighbor discovery, or when no routers are present.
 109  *
 110  * <p> <i>Site-local</i> addresses are designed to be used for addressing
 111  * inside of a site without the need for a global prefix.
 112  *
 113  * <p> <i>Global</i> addresses are unique across the internet.
 114  *
 115  * <h4> Textual representation of IP addresses </h4>
 116  *
 117  * The textual representation of an IP address is address family specific.
 118  *
 119  * <p>
 120  *
 121  * For IPv4 address format, please refer to <A
 122  * HREF="Inet4Address.html#format">Inet4Address#format</A>; For IPv6


 146  * The InetAddress class has a cache to store successful as well as
 147  * unsuccessful host name resolutions.
 148  *
 149  * <p> By default, when a security manager is installed, in order to
 150  * protect against DNS spoofing attacks,
 151  * the result of positive host name resolutions are
 152  * cached forever. When a security manager is not installed, the default
 153  * behavior is to cache entries for a finite (implementation dependent)
 154  * period of time. The result of unsuccessful host
 155  * name resolution is cached for a very short period of time (10
 156  * seconds) to improve performance.
 157  *
 158  * <p> If the default behavior is not desired, then a Java security property
 159  * can be set to a different Time-to-live (TTL) value for positive
 160  * caching. Likewise, a system admin can configure a different
 161  * negative caching TTL value when needed.
 162  *
 163  * <p> Two Java security properties control the TTL values used for
 164  *  positive and negative host name resolution caching:
 165  *
 166  * <blockquote>
 167  * <dl>
 168  * <dt><b>networkaddress.cache.ttl</b></dt>
 169  * <dd>Indicates the caching policy for successful name lookups from
 170  * the name service. The value is specified as an integer to indicate
 171  * the number of seconds to cache the successful lookup. The default
 172  * setting is to cache for an implementation specific period of time.
 173  * <p>
 174  * A value of -1 indicates "cache forever".
 175  * </dd>
 176  * <dt><b>networkaddress.cache.negative.ttl</b> (default: 10)</dt>
 177  * <dd>Indicates the caching policy for un-successful name lookups
 178  * from the name service. The value is specified as an integer to
 179  * indicate the number of seconds to cache the failure for
 180  * un-successful lookups.
 181  * <p>
 182  * A value of 0 indicates "never cache".
 183  * A value of -1 indicates "cache forever".
 184  * </dd>
 185  * </dl>
 186  * </blockquote>
 187  *
 188  * @author  Chris Warth
 189  * @see     java.net.InetAddress#getByAddress(byte[])
 190  * @see     java.net.InetAddress#getByAddress(java.lang.String, byte[])
 191  * @see     java.net.InetAddress#getAllByName(java.lang.String)
 192  * @see     java.net.InetAddress#getByName(java.lang.String)
 193  * @see     java.net.InetAddress#getLocalHost()
 194  * @since 1.0
 195  */
 196 public
 197 class InetAddress implements java.io.Serializable {
 198 
 199     @Native static final int PREFER_IPV4_VALUE = 0;
 200     @Native static final int PREFER_IPV6_VALUE = 1;
 201     @Native static final int PREFER_SYSTEM_VALUE = 2;
 202 
 203     /**
 204      * Specify the address family: Internet Protocol, Version 4
 205      * @since 1.4
 206      */




  55  * This class represents an Internet Protocol (IP) address.
  56  *
  57  * <p> An IP address is either a 32-bit or 128-bit unsigned number
  58  * used by IP, a lower-level protocol on which protocols like UDP and
  59  * TCP are built. The IP address architecture is defined by <a
  60  * href="http://www.ietf.org/rfc/rfc790.txt"><i>RFC&nbsp;790:
  61  * Assigned Numbers</i></a>, <a
  62  * href="http://www.ietf.org/rfc/rfc1918.txt"> <i>RFC&nbsp;1918:
  63  * Address Allocation for Private Internets</i></a>, <a
  64  * href="http://www.ietf.org/rfc/rfc2365.txt"><i>RFC&nbsp;2365:
  65  * Administratively Scoped IP Multicast</i></a>, and <a
  66  * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC&nbsp;2373: IP
  67  * Version 6 Addressing Architecture</i></a>. An instance of an
  68  * InetAddress consists of an IP address and possibly its
  69  * corresponding host name (depending on whether it is constructed
  70  * with a host name or whether it has already done reverse host name
  71  * resolution).
  72  *
  73  * <h3> Address types </h3>
  74  *
  75  * <table class="striped" style="margin-left:2em">
  76  *   <caption style="display:none">Description of unicast and multicast address types</caption>
  77  *   <thead>
  78  *   <tr><th scope="col">Address Type</th><th scope="col">Description</th></tr>
  79  *   </thead>
  80  *   <tbody>
  81  *   <tr><th scope="row" style="vertical-align:top">unicast</th>
  82  *       <td>An identifier for a single interface. A packet sent to
  83  *         a unicast address is delivered to the interface identified by
  84  *         that address.
  85  *
  86  *         <p> The Unspecified Address -- Also called anylocal or wildcard
  87  *         address. It must never be assigned to any node. It indicates the
  88  *         absence of an address. One example of its use is as the target of
  89  *         bind, which allows a server to accept a client connection on any
  90  *         interface, in case the server host has multiple interfaces.
  91  *
  92  *         <p> The <i>unspecified</i> address must not be used as
  93  *         the destination address of an IP packet.
  94  *
  95  *         <p> The <i>Loopback</i> Addresses -- This is the address
  96  *         assigned to the loopback interface. Anything sent to this
  97  *         IP address loops around and becomes IP input on the local
  98  *         host. This address is often used when testing a
  99  *         client.</td></tr>
 100  *   <tr><th scope="row" style="vertical-align:top">multicast</th>
 101  *       <td>An identifier for a set of interfaces (typically belonging
 102  *         to different nodes). A packet sent to a multicast address is
 103  *         delivered to all interfaces identified by that address.</td></tr>
 104  * </tbody>
 105  * </table>
 106  *
 107  * <h4> IP address scope </h4>
 108  *
 109  * <p> <i>Link-local</i> addresses are designed to be used for addressing
 110  * on a single link for purposes such as auto-address configuration,
 111  * neighbor discovery, or when no routers are present.
 112  *
 113  * <p> <i>Site-local</i> addresses are designed to be used for addressing
 114  * inside of a site without the need for a global prefix.
 115  *
 116  * <p> <i>Global</i> addresses are unique across the internet.
 117  *
 118  * <h4> Textual representation of IP addresses </h4>
 119  *
 120  * The textual representation of an IP address is address family specific.
 121  *
 122  * <p>
 123  *
 124  * For IPv4 address format, please refer to <A
 125  * HREF="Inet4Address.html#format">Inet4Address#format</A>; For IPv6


 149  * The InetAddress class has a cache to store successful as well as
 150  * unsuccessful host name resolutions.
 151  *
 152  * <p> By default, when a security manager is installed, in order to
 153  * protect against DNS spoofing attacks,
 154  * the result of positive host name resolutions are
 155  * cached forever. When a security manager is not installed, the default
 156  * behavior is to cache entries for a finite (implementation dependent)
 157  * period of time. The result of unsuccessful host
 158  * name resolution is cached for a very short period of time (10
 159  * seconds) to improve performance.
 160  *
 161  * <p> If the default behavior is not desired, then a Java security property
 162  * can be set to a different Time-to-live (TTL) value for positive
 163  * caching. Likewise, a system admin can configure a different
 164  * negative caching TTL value when needed.
 165  *
 166  * <p> Two Java security properties control the TTL values used for
 167  *  positive and negative host name resolution caching:
 168  *
 169  * <dl style="margin-left:2em">

 170  * <dt><b>networkaddress.cache.ttl</b></dt>
 171  * <dd>Indicates the caching policy for successful name lookups from
 172  * the name service. The value is specified as an integer to indicate
 173  * the number of seconds to cache the successful lookup. The default
 174  * setting is to cache for an implementation specific period of time.
 175  * <p>
 176  * A value of -1 indicates "cache forever".
 177  * </dd>
 178  * <dt><b>networkaddress.cache.negative.ttl</b> (default: 10)</dt>
 179  * <dd>Indicates the caching policy for un-successful name lookups
 180  * from the name service. The value is specified as an integer to
 181  * indicate the number of seconds to cache the failure for
 182  * un-successful lookups.
 183  * <p>
 184  * A value of 0 indicates "never cache".
 185  * A value of -1 indicates "cache forever".
 186  * </dd>
 187  * </dl>

 188  *
 189  * @author  Chris Warth
 190  * @see     java.net.InetAddress#getByAddress(byte[])
 191  * @see     java.net.InetAddress#getByAddress(java.lang.String, byte[])
 192  * @see     java.net.InetAddress#getAllByName(java.lang.String)
 193  * @see     java.net.InetAddress#getByName(java.lang.String)
 194  * @see     java.net.InetAddress#getLocalHost()
 195  * @since 1.0
 196  */
 197 public
 198 class InetAddress implements java.io.Serializable {
 199 
 200     @Native static final int PREFER_IPV4_VALUE = 0;
 201     @Native static final int PREFER_IPV6_VALUE = 1;
 202     @Native static final int PREFER_SYSTEM_VALUE = 2;
 203 
 204     /**
 205      * Specify the address family: Internet Protocol, Version 4
 206      * @since 1.4
 207      */


< prev index next >