+ All Categories
Home > Technology > Java API: java.net.InetAddress

Java API: java.net.InetAddress

Date post: 22-May-2015
Category:
Upload: sayak-sarkar
View: 882 times
Download: 0 times
Share this document with a friend
Description:
Network Programming Slides on the java.net.InetAddress Class
Popular Tags:
17
{ { Java API: java.net.InetAddress java.net.InetAddress Ankit Gadgil: 11030142027 Ankit Gadgil: 11030142027 Sayak Sarkar: 11030142046 Sayak Sarkar: 11030142046
Transcript
Page 1: Java API: java.net.InetAddress

{{

Java API: java.net.InetAddressjava.net.InetAddress

Ankit Gadgil: 11030142027Ankit Gadgil: 11030142027Sayak Sarkar: 11030142046Sayak Sarkar: 11030142046

Page 2: Java API: java.net.InetAddress

The InetAddress class is the abstraction representing an The InetAddress class is the abstraction representing an IP (Internet Protocol) address, which is either a 32-bit or IP (Internet Protocol) address, which is either a 32-bit or 128-bit unsigned number used by IP, a lower-level 128-bit unsigned number used by IP, a lower-level protocol on which protocols like UDP and TCP are built.protocol on which protocols like UDP and TCP are built.

It has two subclasses: It has two subclasses: Inet4Address for IPv4 addresses.Inet4Address for IPv4 addresses.Inet6Address for IPv6 addresses.Inet6Address for IPv6 addresses.

In most cases, there is no need to deal directly with the In most cases, there is no need to deal directly with the subclasses, as the InetAddress abstraction covers most subclasses, as the InetAddress abstraction covers most of the needed functionality.of the needed functionality.

The InetAddress ClassThe InetAddress Class

Page 3: Java API: java.net.InetAddress

An instance of an InetAddress consists of an IP address An instance of an InetAddress consists of an IP address and possibly its corresponding host name (depending on and possibly its corresponding host name (depending on whether it is constructed with a host name or whether it whether it is constructed with a host name or whether it has already done reverse host name resolution). has already done reverse host name resolution).

The IP address architecture is defined by RFC 790: The IP address architecture is defined by RFC 790: Assigned Numbers, RFC 1918: Address Allocation for Assigned Numbers, RFC 1918: Address Allocation for Internets, RFC 2365: Administratively Scoped IP Internets, RFC 2365: Administratively Scoped IP Multicast, and RFC 2373: IP Version 6 Addressing Multicast, and RFC 2373: IP Version 6 Addressing Architecture.Architecture.

Class Declaration:Class Declaration:public class public class InetAddress InetAddress extends Object implements extends Object implements SerializableSerializable

The InetAddress ClassThe InetAddress Class

Page 4: Java API: java.net.InetAddress

This class represents an Internet Protocol version This class represents an Internet Protocol version 4 (IPv4) address. 4 (IPv4) address.

It has been defined by RFC790:Assigned Numbers, It has been defined by RFC790:Assigned Numbers, RFC1918: Address Allocation for Private Internets, RFC1918: Address Allocation for Private Internets, and RFC 2365: Administratively Scoped IP and RFC 2365: Administratively Scoped IP MulticastMulticast

Class Declaration:Class Declaration:public final class public final class Inet4Address Inet4Address extends InetAddressextends InetAddress

The Inet4Address The Inet4Address ClassClass

Page 5: Java API: java.net.InetAddress

This class represents an Internet Protocol version This class represents an Internet Protocol version 6 (IPv6) address. 6 (IPv6) address.

It has been defined by RFC 2373: IP Version 6 It has been defined by RFC 2373: IP Version 6 Addressing ArchitectureAddressing Architecture..

Class Declaration:Class Declaration:public final class public final class Inet6Address Inet6Address extends InetAddressextends InetAddress

The Inet6Address The Inet6Address ClassClass

Page 6: Java API: java.net.InetAddress

unicast: unicast: An identifier for a single interface. An identifier for a single interface.

A packet sent to a unicast address is delivered to the interface A packet sent to a unicast address is delivered to the interface identified by that address. identified by that address.

The Unspecified Address -- Also called wildcard address, must The Unspecified Address -- Also called wildcard address, must never be assigned to any node. It indicates the absence of an never be assigned to any node. It indicates the absence of an address. The address. The unspecifiedunspecified address must not be used as the address must not be used as the destination address of an IP packet. destination address of an IP packet.

The The LoopbackLoopback Addresses -- This is the address assigned to the Addresses -- This is the address assigned to the loopback interface. Anything sent to this IP address loops around loopback interface. Anything sent to this IP address loops around and becomes IP input on the local host. This address is often used and becomes IP input on the local host. This address is often used when testing a client.when testing a client.

InetAddress: InetAddress: Address Address Types Types

Page 7: Java API: java.net.InetAddress

multicast:multicast:

An identifier for a set of interfaces (typically belonging to An identifier for a set of interfaces (typically belonging to different nodes). A packet sent to a multicast address is different nodes). A packet sent to a multicast address is delivered to all interfaces identified by that address.delivered to all interfaces identified by that address.

InetAddress: InetAddress: Address Address Types Types

Page 8: Java API: java.net.InetAddress

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

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

GlobalGlobal addresses are unique across the internet. addresses are unique across the internet.

InetAddress: InetAddress: IP address IP address scope scope

Page 9: Java API: java.net.InetAddress

Host name-to-IP address Host name-to-IP address resolutionresolution is accomplished is accomplished through the use of a combination of local machine through the use of a combination of local machine configuration information and network naming services configuration information and network naming services such as the Domain Name System (DNS) and Network such as the Domain Name System (DNS) and Network Information Service(NIS). Information Service(NIS).

The particular naming services(s) being used is by default The particular naming services(s) being used is by default the local machine configured one. the local machine configured one.

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

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

Resolution Resolution

Page 10: Java API: java.net.InetAddress

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

By default, when a security manager is installed, in order to By default, when a security manager is installed, in order to protect against DNS spoofing attacks, the result of positive protect against DNS spoofing attacks, the result of positive host name resolutions are cached forever. host name resolutions are cached forever.

When a security manager is not installed, the default behavior When a security manager is not installed, the default behavior is to cache entries for a finite (implementation dependent) is to cache entries for a finite (implementation dependent) period of time. period of time.

The result of unsuccessful host name resolution is cached for a The result of unsuccessful host name resolution is cached for a very short period of time (10 seconds) to improve very short period of time (10 seconds) to improve performance. performance.

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

InetAddress: InetAddress: CachingCaching

Page 11: Java API: java.net.InetAddress

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

networkaddress.cache.ttlnetworkaddress.cache.ttl Indicates the caching policy Indicates the caching policy for successful name lookups from the name service. The for successful name lookups from the name service. The value is specified as integer to indicate the number of value is specified as integer to indicate the number of seconds to cache the successful lookup. The default setting seconds to cache the successful lookup. The default setting is to cache for an implementation specific period of time. A is to cache for an implementation specific period of time. A value of -1 indicates "cache forever". value of -1 indicates "cache forever".

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

InetAddress: InetAddress: Caching Caching

Page 12: Java API: java.net.InetAddress

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

networkaddress.cache.ttl 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".

networkaddress.cache.negative.ttl (default: 10) Indicates the caching policy for un-successful name lookups from the name service. The value is specified 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".

InetAddress: InetAddress: Caching Caching

Page 13: Java API: java.net.InetAddress

 boolean equals(Object obj)           Compares this object against the specified object.

 byte[] getAddress()           Returns the raw IP address of this InetAddress object.

static InetAddress[]

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

static InetAddress

getByAddress(byte[] addr)           Returns an InetAddress object given the raw IP address .

static InsetAddress

getByAddress(String host, byte[] addr)           Create an InetAddress based on the provided host name and IP address No name service is checked for the validity of the address.

static InetAddress

getByName(String host)           Determines the IP address of a host, given the host's name.InetAddress: InetAddress: MethodsMethods

Page 14: Java API: java.net.InetAddress

 String getCanonicalHostName()           Gets the fully qualified domain name for this IP address.

 String getHostAddress()           Returns the IP address string in textual presentation.

 String getHostName()           Gets the host name for this IP address.

static InetAddress

getLocalHost()           Returns the local host.

 int hashCode()           Returns a hashcode for this IP address.

 boolean isAnyLocalAddress()           Utility routine to check if the InetAddress in a wildcard address.

InetAddress: InetAddress: MethodsMethods

Page 15: Java API: java.net.InetAddress

 boolean isLinkLocalAddress()           Utility routine to check if the InetAddress is an link local address.

 boolean isLoopbackAddress()           Utility routine to check if the InetAddress is a loopback address.

 boolean isMCGlobal()           Utility routine to check if the multicast address has global scope.

 boolean isMCLinkLocal()           Utility routine to check if the multicast address has link scope.

 boolean isMCNodeLocal()           Utility routine to check if the multicast address has node scope.

 boolean isMCOrgLocal()           Utility routine to check if the multicast address has organization scope.

InetAddress: InetAddress: MethodsMethods

Page 16: Java API: java.net.InetAddress

 boolean isMCSiteLocal()           Utility routine to check if the multicast address has site scope.

 boolean isMulticastAddress()           Utility routine to check if the InetAddress is an IP multicast address.

 boolean isReachable(int timeout)           Test whether that address is reachable.

 boolean isReachable(NetworkInterface netif, int ttl, int timeout)           Test whether that address is reachable.

 boolean isSiteLocalAddres()           Utility routine to check if the InetAddress is a site local address.

 String toString()           Converts this IP address to a String.

InetAddress: InetAddress: MethodsMethods

Page 17: Java API: java.net.InetAddress

Thank You…Thank You…


Recommended