InetAddress.java revision 5888
2362N/A * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved. 1245N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1245N/A * This code is free software; you can redistribute it and/or modify it 1245N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 1245N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 1245N/A * This code is distributed in the hope that it will be useful, but WITHOUT 1245N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1245N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1245N/A * version 2 for more details (a copy is included in the LICENSE file that 1245N/A * You should have received a copy of the GNU General Public License version 1245N/A * 2 along with this work; if not, write to the Free Software Foundation, 1245N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 1245N/A * This class represents an Internet Protocol (IP) address. 1245N/A * <p> An IP address is either a 32-bit or 128-bit unsigned number 1245N/A * used by IP, a lower-level protocol on which protocols like UDP and 1245N/A * TCP are built. The IP address architecture is defined by <a 1245N/A * Assigned Numbers</i></a>, <a 1245N/A * Address Allocation for Private Internets</i></a>, <a 1245N/A * Administratively Scoped IP Multicast</i></a>, and <a 1245N/A * Version 6 Addressing Architecture</i></a>. An instance of an 1245N/A * InetAddress consists of an IP address and possibly its 1245N/A * corresponding host name (depending on whether it is constructed 1245N/A * with a host name or whether it has already done reverse host name 1245N/A * <blockquote><table cellspacing=2 summary="Description of unicast and multicast address types"> 1245N/A * <tr><th valign=top><i>unicast</i></th> 1245N/A * <td>An identifier for a single interface. A packet sent to 1245N/A * a unicast address is delivered to the interface identified by 1245N/A * <p> The Unspecified Address -- Also called anylocal or wildcard 1245N/A * address. It must never be assigned to any node. It indicates the 1245N/A * absence of an address. One example of its use is as the target of 1245N/A * bind, which allows a server to accept a client connection on any 1245N/A * interface, in case the server host has multiple interfaces. 1245N/A * <p> The <i>unspecified</i> address must not be used as 1245N/A * the destination address of an IP packet. 1245N/A * <p> The <i>Loopback</i> Addresses -- This is the address 1245N/A * assigned to the loopback interface. Anything sent to this 1245N/A * IP address loops around and becomes IP input on the local 1245N/A * host. This address is often used when testing a 1245N/A * <tr><th valign=top><i>multicast</i></th> 1245N/A * <td>An identifier for a set of interfaces (typically belonging 1245N/A * to different nodes). A packet sent to a multicast address is 1245N/A * delivered to all interfaces identified by that address.</td></tr> 1245N/A * <h4> IP address scope </h4> 1245N/A * <p> <i>Link-local</i> addresses are designed to be used for addressing 1245N/A * on a single link for purposes such as auto-address configuration, 1245N/A * neighbor discovery, or when no routers are present. 1245N/A * <p> <i>Site-local</i> addresses are designed to be used for addressing 1245N/A * inside of a site without the need for a global prefix. 1245N/A * <p> <i>Global</i> addresses are unique across the internet. 1245N/A * <h4> Textual representation of IP addresses </h4> 1245N/A * The textual representation of an IP address is address family specific. 1245N/A * For IPv4 address format, please refer to <A 1245N/A * address format, please refer to <A 1245N/A * System Properties</a> affecting how IPv4 and IPv6 addresses are used.</P> 1245N/A * <h4> Host Name Resolution </h4> 1245N/A * Host name-to-IP address <i>resolution</i> is accomplished through 1245N/A * the use of a combination of local machine configuration information 1245N/A * and network naming services such as the Domain Name System (DNS) 1245N/A * and Network Information Service(NIS). The particular naming 1245N/A * services(s) being used is by default the local machine configured 1245N/A * one. For any host name, its corresponding IP address is returned. 1245N/A * <p> <i>Reverse name resolution</i> means that for any IP address, 1245N/A * the host associated with the IP address is returned. 1245N/A * <p> The InetAddress class provides methods to resolve host names to 1245N/A * their IP addresses and vice versa. 1245N/A * <h4> InetAddress Caching </h4> 1245N/A * The InetAddress class has a cache to store successful as well as 1245N/A * unsuccessful host name resolutions. 1245N/A * <p> By default, when a security manager is installed, in order to 1245N/A * protect against DNS spoofing attacks, 1245N/A * the result of positive host name resolutions are 1245N/A * cached forever. When a security manager is not installed, the default 1245N/A * behavior is to cache entries for a finite (implementation dependent) 1245N/A * period of time. The result of unsuccessful host 1245N/A * name resolution is cached for a very short period of time (10 1245N/A * seconds) to improve performance. 1245N/A * <p> If the default behavior is not desired, then a Java security property 1245N/A * can be set to a different Time-to-live (TTL) value for positive 1245N/A * caching. Likewise, a system admin can configure a different 1245N/A * negative caching TTL value when needed. 1245N/A * <p> Two Java security properties control the TTL values used for 1245N/A * positive and negative host name resolution caching: 1245N/A * <dt><b>networkaddress.cache.ttl</b></dt> 1245N/A * <dd>Indicates the caching policy for successful name lookups from 1245N/A * the name service. The value is specified as as integer to indicate 1245N/A * the number of seconds to cache the successful lookup. The default 1245N/A * setting is to cache for an implementation specific period of time. 1245N/A * A value of -1 indicates "cache forever". 1245N/A * <dt><b>networkaddress.cache.negative.ttl</b> (default: 10)</dt> 1245N/A * <dd>Indicates the caching policy for un-successful name lookups 1245N/A * from the name service. The value is specified as as integer to 1245N/A * indicate the number of seconds to cache the failure for 1245N/A * A value of 0 indicates "never cache". 1245N/A * A value of -1 indicates "cache forever". 1245N/A * @see java.net.InetAddress#getByAddress(byte[]) 1245N/A * @see java.net.InetAddress#getByAddress(java.lang.String, byte[]) 1245N/A * @see java.net.InetAddress#getAllByName(java.lang.String) 1245N/A * @see java.net.InetAddress#getByName(java.lang.String) 1245N/A * @see java.net.InetAddress#getLocalHost() 1245N/A * Specify the address family: Internet Protocol, Version 4 1245N/A * Specify the address family: Internet Protocol, Version 6 1245N/A /* Specify address family preference */ 1245N/A * Holds a 32-bit IPv4 address. 1245N/A * Specifies the address family type, for instance, '1' for IPv4 1245N/A * addresses, and '2' for IPv6 addresses. 1245N/A /* Used to store the name service provider */ 1245N/A /* Used to store the best available hostname */ 1245N/A /** use serialVersionUID from JDK 1.0.2 for interoperability */ 1245N/A * Load net library into runtime, and perform initializations. 1245N/A * Constructor for the Socket.accept() method. 1245N/A * This creates an empty InetAddress, which is filled in by 1245N/A * the accept() method. This InetAddress, however, is not 1245N/A * put in the address cache, since it is not created by name. 1245N/A * Replaces the de-serialized object with an Inet4Address object. 1245N/A * @return the alternate object to the de-serialized object. 1245N/A * @throws ObjectStreamException if a new object replacing this 1245N/A * object could not be created 1245N/A // will replace the deserialized 'this' object 1245N/A * Utility routine to check if the InetAddress is an 1245N/A * @return a <code>boolean</code> indicating if the InetAddress is 1245N/A * Utility routine to check if the InetAddress in a wildcard address. 1245N/A * @return a <code>boolean</code> indicating if the Inetaddress is 1245N/A * Utility routine to check if the InetAddress is a loopback address. 1245N/A * @return a <code>boolean</code> indicating if the InetAddress is 1245N/A * a loopback address; or false otherwise. 1245N/A * Utility routine to check if the InetAddress is an link local address. 1245N/A * @return a <code>boolean</code> indicating if the InetAddress is 1245N/A * a link local address; or false if address is not a link local unicast address. 1245N/A * Utility routine to check if the InetAddress is a site local address. 1245N/A * @return a <code>boolean</code> indicating if the InetAddress is 1245N/A * a site local address; or false if address is not a site local unicast address. 1245N/A * Utility routine to check if the multicast address has global scope. 1245N/A * @return a <code>boolean</code> indicating if the address has 1245N/A * is a multicast address of global scope, false if it is not 1245N/A * of global scope or it is not a multicast address 1245N/A * Utility routine to check if the multicast address has node scope. 1245N/A * @return a <code>boolean</code> indicating if the address has 1245N/A * is a multicast address of node-local scope, false if it is not 1245N/A * of node-local scope or it is not a multicast address 1245N/A * Utility routine to check if the multicast address has link scope. 1245N/A * @return a <code>boolean</code> indicating if the address has 1245N/A * is a multicast address of link-local scope, false if it is not 1245N/A * of link-local scope or it is not a multicast address 1245N/A * Utility routine to check if the multicast address has site scope. 1245N/A * @return a <code>boolean</code> indicating if the address has 1245N/A * is a multicast address of site-local scope, false if it is not 1245N/A * of site-local scope or it is not a multicast address 1245N/A * Utility routine to check if the multicast address has organization scope. 1245N/A * @return a <code>boolean</code> indicating if the address has 1245N/A * is a multicast address of organization-local scope, 1245N/A * false if it is not of organization-local scope 1245N/A * or it is not a multicast address 1245N/A * Test whether that address is reachable. Best effort is made by the 1245N/A * implementation to try to reach the host, but firewalls and server 1245N/A * configuration may block requests resulting in a unreachable status 1245N/A * while some specific ports may be accessible. 1245N/A * A typical implementation will use ICMP ECHO REQUESTs if the 1245N/A * privilege can be obtained, otherwise it will try to establish 1245N/A * a TCP connection on port 7 (Echo) of the destination host. 1245N/A * The timeout value, in milliseconds, indicates the maximum amount of time 1245N/A * the try should take. If the operation times out before getting an 1245N/A * answer, the host is deemed unreachable. A negative value will result 1245N/A * in an IllegalArgumentException being thrown. 1245N/A * @param timeout the time, in milliseconds, before the call aborts 1245N/A * @return a <code>boolean</code> indicating if the address is reachable. 1245N/A * @throws IOException if a network error occurs 1245N/A * @throws IllegalArgumentException if <code>timeout</code> is negative. 1245N/A * Test whether that address is reachable. Best effort is made by the 1245N/A * implementation to try to reach the host, but firewalls and server 1245N/A * configuration may block requests resulting in a unreachable status 1245N/A * while some specific ports may be accessible. 1245N/A * A typical implementation will use ICMP ECHO REQUESTs if the 1245N/A * privilege can be obtained, otherwise it will try to establish 1245N/A * a TCP connection on port 7 (Echo) of the destination host. 1245N/A * The <code>network interface</code> and <code>ttl</code> parameters 1245N/A * let the caller specify which network interface the test will go through 1245N/A * and the maximum number of hops the packets should go through. 1245N/A * A negative value for the <code>ttl</code> will result in an 1245N/A * IllegalArgumentException being thrown. 1245N/A * The timeout value, in milliseconds, indicates the maximum amount of time 1245N/A * the try should take. If the operation times out before getting an 1245N/A * answer, the host is deemed unreachable. A negative value will result 1245N/A * in an IllegalArgumentException being thrown. 1245N/A * @param netif the NetworkInterface through which the 1245N/A * test will be done, or null for any interface 1245N/A * @param ttl the maximum numbers of hops to try or 0 for the 1245N/A * @param timeout the time, in milliseconds, before the call aborts 1245N/A * @throws IllegalArgumentException if either <code>timeout</code> 1245N/A * or <code>ttl</code> are negative. 1245N/A * @return a <code>boolean</code>indicating if the address is reachable. 1245N/A * @throws IOException if a network error occurs 1245N/A * Gets the host name for this IP address. 1245N/A * <p>If this InetAddress was created with a host name, 1245N/A * this host name will be remembered and returned; 1245N/A * otherwise, a reverse name lookup will be performed 1245N/A * and the result will be returned based on the system 1245N/A * configured name lookup service. If a lookup of the name service 1245N/A * {@link #getCanonicalHostName() getCanonicalHostName}. 1245N/A * <p>If there is a security manager, its 1245N/A * <code>checkConnect</code> method is first called 1245N/A * with the hostname and <code>-1</code> 1245N/A * as its arguments to see if the operation is allowed. 1245N/A * If the operation is not allowed, it will return 1245N/A * the textual representation of the IP address. 1245N/A * @return the host name for this IP address, or if the operation 1245N/A * is not allowed by the security check, the textual 1245N/A * representation of the IP address. 1245N/A * @see InetAddress#getCanonicalHostName 1245N/A * @see SecurityManager#checkConnect 1245N/A * Returns the hostname for this address. 1245N/A * If the host is equal to null, then this address refers to any 1245N/A * of the local machine's available network addresses. 1245N/A * this is package private so SocketPermission can make calls into 1245N/A * here without a security check. 1245N/A * <p>If there is a security manager, this method first 1245N/A * calls its <code>checkConnect</code> method 1245N/A * with the hostname and <code>-1</code> 1245N/A * as its arguments to see if the calling code is allowed to know 1245N/A * the hostname for this IP address, i.e., to connect to the host. 1245N/A * If the operation is not allowed, it will return 1245N/A * the textual representation of the IP address. 1245N/A * @return the host name for this IP address, or if the operation 1245N/A * is not allowed by the security check, the textual 1245N/A * representation of the IP address. 1245N/A * @param check make security check if true 1245N/A * @see SecurityManager#checkConnect 1245N/A * Gets the fully qualified domain name for this IP address. 1245N/A * Best effort method, meaning we may not be able to return 1245N/A * the FQDN depending on the underlying system configuration. 1245N/A * <p>If there is a security manager, this method first 1245N/A * calls its <code>checkConnect</code> method 1245N/A * with the hostname and <code>-1</code> 1245N/A * as its arguments to see if the calling code is allowed to know 1245N/A * the hostname for this IP address, i.e., to connect to the host. 1245N/A * If the operation is not allowed, it will return 1245N/A * the textual representation of the IP address. 1245N/A * @return the fully qualified domain name for this IP address, 1245N/A * or if the operation is not allowed by the security check, 1245N/A * the textual representation of the IP address. 1245N/A * @see SecurityManager#checkConnect 1245N/A * Returns the hostname for this address. 1245N/A * <p>If there is a security manager, this method first 1245N/A * calls its <code>checkConnect</code> method 1245N/A * with the hostname and <code>-1</code> 1245N/A * as its arguments to see if the calling code is allowed to know 1245N/A * the hostname for this IP address, i.e., to connect to the host. 1245N/A * If the operation is not allowed, it will return 1245N/A * the textual representation of the IP address. 1245N/A * @return the host name for this IP address, or if the operation 1245N/A * is not allowed by the security check, the textual 1245N/A * representation of the IP address. 1245N/A * @param check make security check if true 1245N/A * @see SecurityManager#checkConnect 1245N/A // first lookup the hostname 1245N/A /* check to see if calling code is allowed to know 1245N/A * the hostname for this IP address, ie, connect to the host 1245N/A /* now get all the IP addresses for this hostname, 1245N/A * and make sure one of them matches the original IP 1245N/A * address. We do this to try and prevent spoofing. 1245N/A //XXX: if it looks a spoof just return the address? 1245N/A // let next provider resolve the hostname 1245N/A * Returns the raw IP address of this <code>InetAddress</code> 1245N/A * object. The result is in network byte order: the highest order 1245N/A * byte of the address is in <code>getAddress()[0]</code>. 1245N/A * @return the raw IP address of this object. 1245N/A * Returns the IP address string in textual presentation. 1245N/A * @return the raw IP address in a string format. 1245N/A * Returns a hashcode for this IP address. 1245N/A * @return a hash code value for this IP address. 1245N/A * Compares this object against the specified object. 1245N/A * The result is <code>true</code> if and only if the argument is 1245N/A * not <code>null</code> and it represents the same IP address as 1245N/A * Two instances of <code>InetAddress</code> represent the same IP 1245N/A * address if the length of the byte arrays returned by 1245N/A * <code>getAddress</code> is the same for both, and each of the 1245N/A * array components is the same for the byte arrays. 1245N/A * @param obj the object to compare against. 1245N/A * @return <code>true</code> if the objects are the same; 1245N/A * <code>false</code> otherwise. 1245N/A * @see java.net.InetAddress#getAddress() 1245N/A * Converts this IP address to a <code>String</code>. The 1245N/A * string returned is of the form: hostname / literal IP 1245N/A * If the host name is unresolved, no reverse name service lookup 1245N/A * is performed. The hostname part will be represented by an empty string. 1245N/A * @return a string representation of this IP address. 1245N/A * Cached addresses - our own litle nis, not! 1245N/A * A cache that manages entries based on a policy specified 1245N/A * Add an entry to the cache. If there's already an 1245N/A * entry then for this host then the entry will be 1245N/A // purge any expired entries 1245N/A // As we iterate in insertion order we can 1245N/A // terminate when a non-expired entry is found. 1245N/A // create new entry and add it to the cache 1245N/A // -- as a HashMap replaces existing entries we 1245N/A // don't need to explicitly check if there is 1245N/A // already an entry for this host. 1245N/A * Query the cache for the specific host. If found then 1245N/A * return its CacheEntry, or null if not found. 1245N/A // check if entry has expired 1245N/A * Initialize cache and insert anyLocalAddress into the 1245N/A * unknown array with no expiry. 1245N/A * Cache the given hostname and addresses. 1245N/A * Lookup hostname in cache (positive & negative cache). If 1245N/A * found return addresses, null if not found. 1245N/A // search both positive & negative caches 1245N/A // initialize the default name service 1245N/A "Cannot create name service:" 1245N/A // get name service if provided and requested 1245N/A // if not designate any name services provider, 1245N/A * Creates an InetAddress based on the provided host name and IP address. 1245N/A * No name service is checked for the validity of the address. 1245N/A * <p> The host name can either be a machine name, such as 1245N/A * "<code>java.sun.com</code>", or a textual representation of its IP 1245N/A * <p> No validity checking is done on the host name either. 1245N/A * <p> If addr specifies an IPv4 address an instance of Inet4Address 1245N/A * will be returned; otherwise, an instance of Inet6Address 1245N/A * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array 1245N/A * @param host the specified host 1245N/A * @param addr the raw IP address in network byte order 1245N/A * @return an InetAddress object created from the raw IP address. 1245N/A * @exception UnknownHostException if IP address is of illegal length 1245N/A * Determines the IP address of a host, given the host's name. 1245N/A * <p> The host name can either be a machine name, such as 1245N/A * "<code>java.sun.com</code>", or a textual representation of its 1245N/A * IP address. If a literal IP address is supplied, only the 1245N/A * validity of the address format is checked. 1245N/A * <p> For <code>host</code> specified in literal IPv6 address, 1245N/A * either the form defined in RFC 2732 or the literal IPv6 address 1245N/A * format defined in RFC 2373 is accepted. IPv6 scoped addresses are also 1245N/A * <p> If the host is <tt>null</tt> then an <tt>InetAddress</tt> 1245N/A * representing an address of the loopback interface is returned. 1245N/A * @param host the specified host, or <code>null</code>. 1245N/A * @return an IP address for the given host name. 1245N/A * @exception UnknownHostException if no IP address for the 1245N/A * <code>host</code> could be found, or if a scope_id was specified 1245N/A * for a global IPv6 address. 1245N/A * @exception SecurityException if a security manager exists 1245N/A * and its checkConnect method doesn't allow the operation 1245N/A // called from deployment cache manager 1245N/A * Given the name of a host, returns an array of its IP addresses, 1245N/A * based on the configured name service on the system. 1245N/A * <p> The host name can either be a machine name, such as 1245N/A * "<code>java.sun.com</code>", or a textual representation of its IP 1245N/A * address. If a literal IP address is supplied, only the 1245N/A * validity of the address format is checked. 1245N/A * <p> For <code>host</code> specified in <i>literal IPv6 address</i>, 1245N/A * either the form defined in RFC 2732 or the literal IPv6 address 1245N/A * format defined in RFC 2373 is accepted. A literal IPv6 address may 1245N/A * also be qualified by appending a scoped zone identifier or scope_id. 1245N/A * The syntax and usage of scope_ids is described 1245N/A * <p> If the host is <tt>null</tt> then an <tt>InetAddress</tt> 1245N/A * representing an address of the loopback interface is returned. 1245N/A * <p> If there is a security manager and <code>host</code> is not 1245N/A * null and <code>host.length() </code> is not equal to zero, the 1245N/A * <code>checkConnect</code> method is called 1245N/A * with the hostname and <code>-1</code> 1245N/A * as its arguments to see if the operation is allowed. 1245N/A * @param host the name of the host, or <code>null</code>. 1245N/A * @return an array of all the IP addresses for a given host name. 1245N/A * @exception UnknownHostException if no IP address for the 1245N/A * <code>host</code> could be found, or if a scope_id was specified 1245N/A * for a global IPv6 address. 1245N/A * @exception SecurityException if a security manager exists and its 1245N/A * <code>checkConnect</code> method doesn't allow the operation. 1245N/A * @see SecurityManager#checkConnect 1245N/A // This is supposed to be an IPv6 literal 1245N/A // This was supposed to be a IPv6 address, but it's not! 1245N/A // if host is an IP address, we won't do further lookup 1245N/A // see if it is IPv4 address 1245N/A // see if it is IPv6 address 1245N/A // Check if a numeric or string zone id is present 1245N/A // Means an IPv4 litteral between brackets! 1245N/A // We were expecting an IPv6 Litteral, but got something else 1245N/A * Returns the loopback address. 1245N/A * The InetAddress returned will represent the IPv4 1245N/A * loopback address, 127.0.0.1, or the IPv6 loopback 1245N/A * address, ::1. The IPv4 loopback address returned 1245N/A * is only one of many in the form 127.*.*.* 1245N/A * @return the InetAddress loopback instance. 1245N/A * check if the literal address string has %nn appended 1245N/A * returns -1 if not, or the numeric value otherwise. 1245N/A * %nn may also be a string that represents the displayName of 1245N/A * a currently available NetworkInterface. 1245N/A * package private so SocketPermission can call it 1245N/A /* If it gets here it is presumed to be a hostname */ 1245N/A /* Cache.get can return: null, unknownAddress, or InetAddress[] */ 1245N/A /* make sure the connection to the host is allowed, before we 1245N/A /* If no entry in cache, then do the host lookup */ 1245N/A // Check whether the host is in the lookupTable. 1245N/A // 1) If the host isn't in the lookupTable when 1245N/A // checkLookupTable() is called, checkLookupTable() 1245N/A // would add the host in the lookupTable and 1245N/A // return null. So we will do the lookup. 1245N/A // 2) If the host is in the lookupTable when 1245N/A // checkLookupTable() is called, the current thread 1245N/A // would be blocked until the host is removed 1245N/A // from the lookupTable. Then this thread 1245N/A // should try to look up the addressCache. 1245N/A // i) if it found the addresses in the 1245N/A // addressCache, checkLookupTable() would 1245N/A // ii) if it didn't find the addresses in the 1245N/A // addressCache for any reason, 1245N/A // it should add the host in the 1245N/A // lookupTable and return null so the 1245N/A // following code would do a lookup itself. 1245N/A // This is the first thread which looks up the addresses 1245N/A // this host or the cache entry for this host has been 1245N/A // expired so this thread should do the lookup. 1245N/A * Do not put the call to lookup() inside the 1245N/A * constructor. if you do you will still be 1245N/A * allocating space when the lookup fails. 1245N/A for (
int j =
0; j < i; j++) {
1245N/A // Delete host from the lookupTable and notify 1245N/A // all threads waiting on the lookupTable monitor. 1245N/A // If the host isn't in the lookupTable, add it in the 1245N/A // lookuptable and return null. The caller should do 1245N/A // If the host is in the lookupTable, it means that another 1245N/A // thread is trying to look up the addresses of this host. 1245N/A // This thread should wait. 1245N/A // The other thread has finished looking up the addresses of 1245N/A // the host. This thread should retry to get the addresses 1245N/A // from the addressCache. If it doesn't get the addresses from 1245N/A // the cache, it will try to look up the addresses itself. 1245N/A * Returns an <code>InetAddress</code> object given the raw IP address . 1245N/A * The argument is in network byte order: the highest order 1245N/A * byte of the address is in <code>getAddress()[0]</code>. 1245N/A * <p> This method doesn't block, i.e. no reverse name service lookup 1245N/A * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array 1245N/A * @param addr the raw IP address in network byte order 1245N/A * @return an InetAddress object created from the raw IP address. 1245N/A * @exception UnknownHostException if IP address is of illegal length 1245N/A * Returns the address of the local host. This is achieved by retrieving 1245N/A * the name of the host from the system, then resolving that name into 1245N/A * an <code>InetAddress</code>. 1245N/A * <P>Note: The resolved address may be cached for a short period of time. 1245N/A * <p>If there is a security manager, its 1245N/A * <code>checkConnect</code> method is called 1245N/A * with the local host name and <code>-1</code> 1245N/A * as its arguments to see if the operation is allowed. 1245N/A * If the operation is not allowed, an InetAddress representing 1245N/A * the loopback address is returned. 1245N/A * @return the address of the local host. 1245N/A * @exception UnknownHostException if the local host name could not 1245N/A * be resolved into an address. 1245N/A * @see SecurityManager#checkConnect 1245N/A * @see java.net.InetAddress#getByName(java.lang.String) 1245N/A // we are calling getAddressesFromNameService directly 1245N/A // to avoid getting localHost from cache 1245N/A // Rethrow with a more informative error message. 1245N/A * Perform class load-time initializations. 1245N/A * Returns the InetAddress representing anyLocalAddress 1245N/A * (typically 0.0.0.0 or ::0) 1245N/A * Load and instantiate an underlying impl class 1245N/A * Property "impl.prefix" will be prepended to the classname 1245N/A * of the implementation object we instantiate, to which we 1245N/A * delegate the real work (like native methods). This 1245N/A * property can vary across implementations of the java. 1245N/A * classes. The default is an empty String "". 1245N/A "in your properties file.");
1245N/A "in your properties file.");
1245N/A "in your properties file.");
1245N/A throw new Error(
"System property impl.prefix incorrect");
1245N/A /* needed because the serializable fields no longer exist */ 1245N/A * @serialField hostName String 1245N/A * Simple factory to create the impl 1245N/A "Inet6AddressImpl" :
"Inet4AddressImpl");