InetAddress Class

Definition

This class represents an Internet Protocol (IP) address.

[Android.Runtime.Register("java/net/InetAddress", DoNotGenerateAcw=true)]
public class InetAddress : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.IO.ISerializable
[<Android.Runtime.Register("java/net/InetAddress", DoNotGenerateAcw=true)>]
type InetAddress = class
    inherit Object
    interface ISerializable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Inheritance
InetAddress
Derived
Attributes
Implements

Remarks

This class represents an Internet Protocol (IP) address.

An IP address is either a 32-bit or 128-bit unsigned number used by IP, a lower-level protocol on which protocols like UDP and TCP are built. The IP address architecture is defined by RFC&nbsp;790: Assigned Numbershttp://www.ietf.org/rfc/rfc790.txt, RFC&nbsp;1918: Address Allocation for Private Internetshttp://www.ietf.org/rfc/rfc1918.txt, RFC&nbsp;2365: Administratively Scoped IP Multicasthttp://www.ietf.org/rfc/rfc2365.txt, and RFC&nbsp;2373: IP Version 6 Addressing Architecturehttp://www.ietf.org/rfc/rfc2373.txt. An instance of an InetAddress consists of an IP address and possibly its corresponding host name (depending on whether it is constructed with a host name or whether it has already done reverse host name resolution).

<h3> Address types </h3>

<blockquote><table cellspacing=2 summary="Description of unicast and multicast address types"> <tr><th valign=top>unicast</th> <td>An identifier for a single interface. A packet sent to a unicast address is delivered to the interface identified by that address.

The Unspecified Address -- Also called anylocal or wildcard address. It must never be assigned to any node. It indicates the absence of an address. One example of its use is as the target of bind, which allows a server to accept a client connection on any interface, in case the server host has multiple interfaces.

The unspecified address must not be used as the destination address of an IP packet.

The Loopback Addresses -- This is the address assigned to the loopback interface. Anything sent to this IP address loops around and becomes IP input on the local host. This address is often used when testing a client.</td></tr> <tr><th valign=top>multicast</th> <td>An identifier for a set of interfaces (typically belonging to different nodes). A packet sent to a multicast address is delivered to all interfaces identified by that address.</td></tr> </table></blockquote>

<h4> IP address scope </h4>

Link-local addresses are designed to be used for addressing on a single link for purposes such as auto-address configuration, neighbor discovery, or when no routers are present.

Site-local addresses are designed to be used for addressing inside of a site without the need for a global prefix.

Global addresses are unique across the internet.

<h4> Textual representation of IP addresses </h4>

The textual representation of an IP address is address family specific.

For IPv4 address format, please refer to Inet4Address#format; For IPv6 address format, please refer to Inet6Address#format.

There is a couple of System Properties affecting how IPv4 and IPv6 addresses are used.

<h4> Host Name Resolution </h4>

Host name-to-IP address resolution is accomplished through the use of a combination of local machine configuration information and network naming services such as the Domain Name System (DNS) and Network Information Service(NIS). The particular naming services(s) being used is by default the local machine configured one. For any host name, its corresponding IP address is returned.

Reverse name resolution means that for any IP address, the host associated with the IP address is returned.

The InetAddress class provides methods to resolve host names to their IP addresses and vice versa.

<h4> InetAddress Caching </h4>

The InetAddress class has a cache to store successful as well as unsuccessful host name resolutions.

By default, when a security manager is installed, in order to protect against DNS spoofing attacks, the result of positive host name resolutions are cached forever. When a security manager is not installed, the default behavior is to cache entries for a finite (implementation dependent) period of time. The result of unsuccessful host name resolution is cached for a very short period of time (10 seconds) to improve performance.

If the default behavior is not desired, then a Java security property can be set to a different Time-to-live (TTL) value for positive caching. Likewise, a system admin can configure a different negative caching TTL value when needed.

Two Java security properties control the TTL values used for positive and negative host name resolution caching:

<blockquote> <dl> <dt><b>networkaddress.cache.ttl</b></dt> <dd>Indicates the caching policy for successful name lookups from the name service. The value is specified as as integer to indicate the number of seconds to cache the successful lookup. The default setting is to cache for an implementation specific period of time.

A value of -1 indicates "cache forever". </dd> <dt><b>networkaddress.cache.negative.ttl</b> (default: 10)</dt> <dd>Indicates the caching policy for un-successful name lookups from the name service. The value is specified as as integer to indicate the number of seconds to cache the failure for un-successful lookups.

A value of 0 indicates "never cache". A value of -1 indicates "cache forever". </dd> </dl> </blockquote>

Added in JDK1.0.

Java documentation for java.net.InetAddress.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

InetAddress(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Properties

CanonicalHostName

Gets the fully qualified domain name for this IP address.

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
HostAddress

Returns the IP address string in textual presentation.

HostName

Gets the host name for this IP address.

IsAnyLocalAddress

Utility routine to check if the InetAddress in a wildcard address.

IsLinkLocalAddress

Utility routine to check if the InetAddress is an link local address.

IsLoopbackAddress

Utility routine to check if the InetAddress is a loopback address.

IsMCGlobal

Utility routine to check if the multicast address has global scope.

IsMCLinkLocal

Utility routine to check if the multicast address has link scope.

IsMCNodeLocal

Utility routine to check if the multicast address has node scope.

IsMCOrgLocal

Utility routine to check if the multicast address has organization scope.

IsMCSiteLocal

Utility routine to check if the multicast address has site scope.

IsMulticastAddress

Utility routine to check if the InetAddress is an IP multicast address.

IsSiteLocalAddress

Utility routine to check if the InetAddress is a site local address.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
LocalHost

Returns the address of the local host.

LoopbackAddress

Returns the loopback address.

PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetAddress()

Returns the raw IP address of this InetAddress object.

GetAllByName(String)

Given the name of a host, returns an array of its IP addresses, based on the configured name service on the system.

GetByAddress(Byte[])

Returns an InetAddress object given the raw IP address .

GetByAddress(String, Byte[])

Creates an InetAddress based on the provided host name and IP address.

GetByName(String)

Determines the IP address of a host, given the host's name.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
IsReachable(Int32)

Test whether that address is reachable.

IsReachable(NetworkInterface, Int32, Int32)

Test whether that address is reachable.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to