java.net
Class InetAddress
- Serializable
This class models an Internet address. It does not have a public
constructor. Instead, new instances of this objects are created
using the static methods getLocalHost(), getByName(), and
getAllByName().
This class fulfills the function of the C style functions gethostname(),
gethostbyname(), and gethostbyaddr(). It resolves Internet DNS names
into their corresponding numeric addresses and vice versa.
boolean | equals(Object obj) - Tests this address for equality against another InetAddress.
|
byte[] | getAddress() - Returns the IP address of this object as a byte array.
|
static InetAddress[] | getAllByName(String hostname) - Returns an array of InetAddress objects representing all the host/ip
addresses of a given host, given the host's name.
|
static InetAddress | getByAddress(byte[] addr) - Returns an InetAddress object given the raw IP address.
|
static InetAddress | getByAddress(String host, byte[] addr) - Creates an InetAddress based on the provided host name and IP address.
|
static InetAddress | getByName(String hostname) - Returns an InetAddress object representing the IP address of the given
hostname.
|
String | getCanonicalHostName() - Returns the canonical hostname represented by this InetAddress
|
String | getHostAddress() - Returns the IP address of this object as a String.
|
String | getHostName() - Returns the hostname for this address.
|
static InetAddress | getLocalHost() - Returns an InetAddress object representing the address of the current
host.
|
int | hashCode() - Returns a hash value for this address.
|
boolean | isAnyLocalAddress() - Utility routine to check if the InetAddress in a wildcard address
This method cannot be abstract for backward compatibility reasons.
|
boolean | isLinkLocalAddress() - Utility routine to check if InetAddress is a link local address
This method cannot be abstract for backward compatibility reasons.
|
boolean | isLoopbackAddress() - Utility routine to check if the InetAddress is a loopback address
This method cannot be abstract for backward compatibility reasons.
|
boolean | isMCGlobal() - Utility routine to check if InetAddress is a global multicast address
This method cannot be abstract for backward compatibility reasons.
|
boolean | isMCLinkLocal() - Utility routine to check if InetAddress is a link local multicast address.
|
boolean | isMCNodeLocal() - Utility routine to check if InetAddress is a node local multicast address.
|
boolean | isMCOrgLocal() - Utility routine to check if InetAddress is a organization local
multicast address.
|
boolean | isMCSiteLocal() - Utility routine to check if InetAddress is a site local multicast address.
|
boolean | isMulticastAddress() - Returns true if this address is a multicast address, false otherwise.
|
boolean | isSiteLocalAddress() - Utility routine to check if InetAddress is a site local address
This method cannot be abstract for backward compatibility reasons.
|
String | toString() - Converts this address to a String.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
equals
public boolean equals(Object obj)
Tests this address for equality against another InetAddress. The two
addresses are considered equal if they contain the exact same octets.
This implementation overrides Object.equals()
- equals in interface Object
obj
- The address to test for equality
- true if the passed in object's address is equal to this one's,
false otherwise
getAddress
public byte[] getAddress()
Returns the IP address of this object as a byte array.
getAllByName
public static InetAddress[] getAllByName(String hostname)
throws UnknownHostException
Returns an array of InetAddress objects representing all the host/ip
addresses of a given host, given the host's name. This name can be
either a hostname such as "www.urbanophile.com" or an IP address in
dotted decimal format such as "127.0.0.1". If the value is null, the
hostname of the local machine is supplied by default.
hostname
- The name of the desired host, or null for the
local loopback address.
- All addresses of the host as an array of InetAddress objects.
getByAddress
public static InetAddress getByAddress(byte[] addr)
throws UnknownHostException
Returns an InetAddress object given the raw IP address.
The argument is in network byte order: the highest order byte of the
address is in getAddress()[0].
addr
- The IP address to create the InetAddress object from
getByAddress
public static InetAddress getByAddress(String host,
byte[] addr)
throws UnknownHostException
Creates an InetAddress based on the provided host name and IP address.
No name service is checked for the validity of the address.
host
- The hostname of the InetAddress object to createaddr
- The IP address to create the InetAddress object from
getByName
public static InetAddress getByName(String hostname)
throws UnknownHostException
Returns an InetAddress object representing the IP address of the given
hostname. This name can be either a hostname such as "www.urbanophile.com"
or an IP address in dotted decimal format such as "127.0.0.1". If the
hostname is null or "", the hostname of the local machine is supplied by
default. This method is equivalent to returning the first element in
the InetAddress array returned from GetAllByName.
hostname
- The name of the desired host, or null for the local
loopback address.
- The address of the host as an InetAddress object.
getHostAddress
public String getHostAddress()
Returns the IP address of this object as a String.
This method cannot be abstract for backward compatibility reasons. By
default it always throws
UnsupportedOperationException
unless
overridden.
- The IP address of this object in String form
getHostName
public String getHostName()
Returns the hostname for this address. This will return the IP address
as a String if there is no hostname available for this address
- The hostname for this address
hashCode
public int hashCode()
Returns a hash value for this address. Useful for creating hash
tables. Overrides Object.hashCode()
- hashCode in interface Object
- A hash value for this address.
isAnyLocalAddress
public boolean isAnyLocalAddress()
Utility routine to check if the InetAddress in a wildcard address
This method cannot be abstract for backward compatibility reasons. By
default it always throws
UnsupportedOperationException
unless
overridden.
isLinkLocalAddress
public boolean isLinkLocalAddress()
Utility routine to check if InetAddress is a link local address
This method cannot be abstract for backward compatibility reasons. By
default it always throws
UnsupportedOperationException
unless
overridden.
isLoopbackAddress
public boolean isLoopbackAddress()
Utility routine to check if the InetAddress is a loopback address
This method cannot be abstract for backward compatibility reasons. By
default it always throws
UnsupportedOperationException
unless
overridden.
isMCGlobal
public boolean isMCGlobal()
Utility routine to check if InetAddress is a global multicast address
This method cannot be abstract for backward compatibility reasons. By
default it always throws
UnsupportedOperationException
unless
overridden.
isMCLinkLocal
public boolean isMCLinkLocal()
Utility routine to check if InetAddress is a link local multicast address.
This method cannot be abstract for backward compatibility reasons. By
default it always throws
UnsupportedOperationException
unless
overridden.
isMCNodeLocal
public boolean isMCNodeLocal()
Utility routine to check if InetAddress is a node local multicast address.
This method cannot be abstract for backward compatibility reasons. By
default it always throws
UnsupportedOperationException
unless
overridden.
isMCOrgLocal
public boolean isMCOrgLocal()
Utility routine to check if InetAddress is a organization local
multicast address.
This method cannot be abstract for backward compatibility reasons. By
default it always throws
UnsupportedOperationException
unless
overridden.
isMCSiteLocal
public boolean isMCSiteLocal()
Utility routine to check if InetAddress is a site local multicast address.
This method cannot be abstract for backward compatibility reasons. By
default it always throws
UnsupportedOperationException
unless
overridden.
isMulticastAddress
public boolean isMulticastAddress()
Returns true if this address is a multicast address, false otherwise.
An address is multicast if the high four bits are "1110". These are
also known as "Class D" addresses.
This method cannot be abstract for backward compatibility reasons. By
default it always throws
UnsupportedOperationException
unless
overridden.
- true if mulitcast, false if not
isSiteLocalAddress
public boolean isSiteLocalAddress()
Utility routine to check if InetAddress is a site local address
This method cannot be abstract for backward compatibility reasons. By
default it always throws
UnsupportedOperationException
unless
overridden.
toString
public String toString()
Converts this address to a String. This string contains the IP in
dotted decimal form. For example: "127.0.0.1" This method is equivalent
to getHostAddress() and overrides Object.toString()
- toString in interface Object
- This address in String form
InetAddress.java -- Class to model an Internet address
Copyright (C) 1998, 1999, 2002, 2004, 2005, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.