|
From: <ls...@us...> - 2009-03-18 21:02:45
|
Revision: 5114
http://jnode.svn.sourceforge.net/jnode/?rev=5114&view=rev
Author: lsantha
Date: 2009-03-18 21:02:34 +0000 (Wed, 18 Mar 2009)
Log Message:
-----------
OpenJDK integration.
Modified Paths:
--------------
trunk/all/conf/openjdk-annotations.properties
trunk/core/src/classpath/java/java/net/DatagramSocket.java
trunk/core/src/classpath/java/java/net/ServerSocket.java
trunk/core/src/classpath/java/java/net/Socket.java
Added Paths:
-----------
trunk/core/src/openjdk/java/java/net/Inet4Address.java
trunk/core/src/openjdk/java/java/net/Inet4AddressImpl.java
trunk/core/src/openjdk/java/java/net/Inet6Address.java
trunk/core/src/openjdk/java/java/net/Inet6AddressImpl.java
trunk/core/src/openjdk/java/java/net/InetAddress.java
trunk/core/src/openjdk/java/java/net/InetAddressImpl.java
trunk/core/src/openjdk/java/java/net/InetSocketAddress.java
trunk/core/src/openjdk/vm/java/net/NativeInet4Address.java
trunk/core/src/openjdk/vm/java/net/NativeInet4AddressImpl.java
trunk/core/src/openjdk/vm/java/net/NativeInet6Address.java
trunk/core/src/openjdk/vm/java/net/NativeInet6AddressImpl.java
trunk/core/src/openjdk/vm/java/net/NativeInetAddress.java
trunk/core/src/openjdk/vm/java/net/NativeInetAddressImplFactory.java
Removed Paths:
-------------
trunk/core/src/classpath/java/java/net/Inet4Address.java
trunk/core/src/classpath/java/java/net/Inet6Address.java
trunk/core/src/classpath/java/java/net/InetAddress.java
trunk/core/src/classpath/java/java/net/InetSocketAddress.java
Modified: trunk/all/conf/openjdk-annotations.properties
===================================================================
--- trunk/all/conf/openjdk-annotations.properties 2009-03-17 13:25:49 UTC (rev 5113)
+++ trunk/all/conf/openjdk-annotations.properties 2009-03-18 21:02:34 UTC (rev 5114)
@@ -11,6 +11,8 @@
java/awt/Toolkit.class=SharedStatics
java/lang/ThreadLocal.class=SharedStatics
java/lang/Throwable.class=MagicPermission
+java/net/InetAddress.class=SharedStatics
+java/net/URLConnection.class=SharedStatics
java/util/Currency.class=SharedStatics
java/util/concurrent/locks/LockSupport.class=SharedStatics
sun/awt/AppContext.class=SharedStatics
Modified: trunk/core/src/classpath/java/java/net/DatagramSocket.java
===================================================================
--- trunk/core/src/classpath/java/java/net/DatagramSocket.java 2009-03-17 13:25:49 UTC (rev 5113)
+++ trunk/core/src/classpath/java/java/net/DatagramSocket.java 2009-03-18 21:02:34 UTC (rev 5114)
@@ -317,7 +317,7 @@
}
catch (SecurityException e)
{
- localAddr = InetAddress.ANY_IF;
+ localAddr = NativeInetAddress.ANY_IF;
}
catch (SocketException e)
{
@@ -673,7 +673,7 @@
s.checkListen(port);
if (addr == null)
- addr = InetAddress.ANY_IF;
+ addr = NativeInetAddress.ANY_IF;
try
{
Deleted: trunk/core/src/classpath/java/java/net/Inet4Address.java
===================================================================
--- trunk/core/src/classpath/java/java/net/Inet4Address.java 2009-03-17 13:25:49 UTC (rev 5113)
+++ trunk/core/src/classpath/java/java/net/Inet4Address.java 2009-03-18 21:02:34 UTC (rev 5114)
@@ -1,233 +0,0 @@
-/* Inet4Address.java --
- Copyright (C) 2002, 2003, 2004, 2005 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. */
-
-
-package java.net;
-
-import java.io.ObjectStreamException;
-
-/*
- * Written using on-line Java Platform 1.4 API Specification and
- * RFC 1884 (http://www.ietf.org/rfc/rfc1884.txt),
- * RFC 1918 (http://www.ietf.org/rfc/rfc1918.txt),
- * RFC 2365 (http://www.ietf.org/rfc/rfc2365.txt)
- *
- * @author Michael Koch
- * @status Believed complete and correct.
- */
-public final class Inet4Address extends InetAddress
-{
- /**
- * For compatability with Sun's JDK 1.4.2 rev. 5
- */
- static final long serialVersionUID = 3286316764910316507L;
-
- /**
- * needed for serialization
- */
- private Object writeReplace() throws ObjectStreamException
- {
- return new InetAddress(addr, hostName);
- }
-
- /**
- * Initializes this object's addr instance variable from the passed in
- * byte array. Note that this constructor is protected and is called
- * only by static methods in this class.
- *
- * @param addr The IP number of this address as an array of bytes
- * @param host The hostname of this IP address.
- */
- Inet4Address(byte[] addr, String host)
- {
- super(addr, host);
- }
-
- /**
- * Checks if the address is a multicast address
- *
- * @since 1.1
- */
- public boolean isMulticastAddress()
- {
- return super.isMulticastAddress();
- }
-
- /**
- * Checks if this address is a loopback address
- */
- public boolean isLoopbackAddress()
- {
- return super.isLoopbackAddress();
- }
-
- /**
- * Checks if this address is a wildcard address
- *
- * @since 1.4
- */
- public boolean isAnyLocalAddress()
- {
- return super.isAnyLocalAddress();
- }
-
- /**
- * Checks if this address is a link local address
- *
- * @since 1.4
- */
- public boolean isLinkLocalAddress()
- {
- return super.isLinkLocalAddress();
- }
-
- /**
- * Checks if this address is a site local address
- *
- * @since 1.4
- */
- public boolean isSiteLocalAddress()
- {
- return super.isSiteLocalAddress();
- }
-
- /**
- * Checks if this multicast address has global scope
- *
- * @since 1.4
- */
- public boolean isMCGlobal()
- {
- return super.isMCGlobal();
- }
-
- /**
- * Checks if this multicast address has node scope
- *
- * @since 1.4
- */
- public boolean isMCNodeLocal()
- {
- return super.isMCNodeLocal();
- }
-
- /**
- * Checks if this multicast address has link scope
- *
- * @since 1.4
- */
- public boolean isMCLinkLocal()
- {
- return super.isMCLinkLocal();
- }
-
- /**
- * Checks if this multicast address has site scope
- *
- * @since 1.4
- */
- public boolean isMCSiteLocal()
- {
- return super.isMCSiteLocal();
- }
-
- /**
- * Checks if this multicast address has organization scope
- *
- * @since 1.4
- */
- public boolean isMCOrgLocal()
- {
- return super.isMCOrgLocal();
- }
-
- /**
- * Returns the address of the current instance
- */
- public byte[] getAddress()
- {
- return (byte[]) addr.clone();
- }
-
- /**
- * Returns the address as string
- *
- * @since 1.0.2
- */
- public String getHostAddress()
- {
- return super.getHostAddress();
- }
-
- /**
- * Computes the hashcode of the instance
- */
- public int hashCode()
- {
- int hash = 0;
- int len = addr.length;
- int i = len > 4 ? len - 4 : 0;
-
- for (; i < len; i++)
- hash = (hash << 8) | (addr[i] & 0xFF);
-
- return hash;
- }
-
- /**
- * Compare the current Inet4Address instance with obj
- *
- * @param obj Object to compare with
- */
- public boolean equals(Object obj)
- {
- if (! (obj instanceof InetAddress))
- return false;
-
- byte[] addr1 = addr;
- byte[] addr2 = ((InetAddress) obj).addr;
-
- if (addr1.length != addr2.length)
- return false;
-
- for (int i = addr1.length; --i >= 0;)
- if (addr1[i] != addr2[i])
- return false;
-
- return true;
- }
-}
Deleted: trunk/core/src/classpath/java/java/net/Inet6Address.java
===================================================================
--- trunk/core/src/classpath/java/java/net/Inet6Address.java 2009-03-17 13:25:49 UTC (rev 5113)
+++ trunk/core/src/classpath/java/java/net/Inet6Address.java 2009-03-18 21:02:34 UTC (rev 5114)
@@ -1,422 +0,0 @@
-/* Inet6Address.java --
- Copyright (C) 2002, 2003, 2004 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. */
-
-
-package java.net;
-
-import java.util.Arrays;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.IOException;
-
-/*
- * Written using on-line Java Platform 1.4 API Specification and
- * RFC 1884 (http://www.ietf.org/rfc/rfc1884.txt)
- *
- * @author Michael Koch
- * @status Updated to 1.5. Serialization compatibility is tested.
- */
-public final class Inet6Address extends InetAddress
-{
- static final long serialVersionUID = 6880410070516793377L;
-
- /**
- * Needed for serialization
- */
- byte[] ipaddress;
-
- /**
- * The scope ID, if any.
- * @since 1.5
- * @serial
- */
- private int scope_id;
-
- /**
- * The scope ID, if any.
- * @since 1.5
- * @serial
- */
- private boolean scope_id_set;
-
- /**
- * Whether ifname is set or not.
- * @since 1.5
- * @serial
- */
- private boolean scope_ifname_set;
-
- /**
- * Name of the network interface, used only by the serialization methods
- * @since 1.5
- * @serial
- */
- private String ifname;
-
- /**
- * Scope network interface, or <code>null</code>.
- */
- private transient NetworkInterface nif;
-
- /**
- * Create an Inet6Address object
- *
- * @param addr The IP address
- * @param host The hostname
- */
- Inet6Address(byte[] addr, String host)
- {
- super(addr, host);
- // Super constructor clones the addr. Get a reference to the clone.
- this.ipaddress = this.addr;
- ifname = null;
- scope_ifname_set = scope_id_set = false;
- scope_id = 0;
- nif = null;
- }
-
- /**
- * Utility routine to check if the InetAddress is an IP multicast address
- *
- * @since 1.1
- */
- public boolean isMulticastAddress()
- {
- return ipaddress[0] == 0xFF;
- }
-
- /**
- * Utility routine to check if the InetAddress in a wildcard address
- *
- * @since 1.4
- */
- public boolean isAnyLocalAddress()
- {
- byte[] anylocal = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
- return Arrays.equals(ipaddress, anylocal);
- }
-
- /**
- * Utility routine to check if the InetAddress is a loopback address
- *
- * @since 1.4
- */
- public boolean isLoopbackAddress()
- {
- byte[] loopback = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
-
- return Arrays.equals(ipaddress, loopback);
- }
-
- /**
- * Utility routine to check if the InetAddress is an link local address
- *
- * @since 1.4
- */
- public boolean isLinkLocalAddress()
- {
- return ipaddress[0] == 0xFA;
- }
-
- /**
- * Utility routine to check if the InetAddress is a site local address
- *
- * @since 1.4
- */
- public boolean isSiteLocalAddress()
- {
- return ipaddress[0] == 0xFB;
- }
-
- /**
- * Utility routine to check if the multicast address has global scope
- *
- * @since 1.4
- */
- public boolean isMCGlobal()
- {
- if (! isMulticastAddress())
- return false;
-
- return (ipaddress[1] & 0x0F) == 0xE;
- }
-
- /**
- * Utility routine to check if the multicast address has node scope
- *
- * @since 1.4
- */
- public boolean isMCNodeLocal()
- {
- if (! isMulticastAddress())
- return false;
-
- return (ipaddress[1] & 0x0F) == 0x1;
- }
-
- /**
- * Utility routine to check if the multicast address has link scope
- *
- * @since 1.4
- */
- public boolean isMCLinkLocal()
- {
- if (! isMulticastAddress())
- return false;
-
- return (ipaddress[1] & 0x0F) == 0x2;
- }
-
- /**
- * Utility routine to check if the multicast address has site scope
- *
- * @since 1.4
- */
- public boolean isMCSiteLocal()
- {
- if (! isMulticastAddress())
- return false;
-
- return (ipaddress[1] & 0x0F) == 0x5;
- }
-
- /**
- * Utility routine to check if the multicast address has organization scope
- *
- * @since 1.4
- */
- public boolean isMCOrgLocal()
- {
- if (! isMulticastAddress())
- return false;
-
- return (ipaddress[1] & 0x0F) == 0x8;
- }
-
- /**
- * Returns the raw IP address of this InetAddress object. The result is in
- * network byte order: the highest order byte of the address is i
- * n getAddress()[0]
- */
- public byte[] getAddress()
- {
- return (byte[]) ipaddress.clone();
- }
-
- /**
- * Creates a scoped Inet6Address where the scope has an integer id.
- *
- * @throws UnkownHostException if the address is an invalid number of bytes.
- * @since 1.5
- */
- public static Inet6Address getByAddress(String host, byte[] addr,
- int scopeId)
- throws UnknownHostException
- {
- if( addr.length != 16 )
- throw new UnknownHostException("Illegal address length: " + addr.length
- + " bytes.");
- Inet6Address ip = new Inet6Address( addr, host );
- ip.scope_id = scopeId;
- ip.scope_id_set = true;
- return ip;
- }
-
- /**
- * Creates a scoped Inet6Address where the scope is a given
- * NetworkInterface.
- *
- * @throws UnkownHostException if the address is an invalid number of bytes.
- * @since 1.5
- */
- public static Inet6Address getByAddress(String host, byte[] addr,
- NetworkInterface nif)
- throws UnknownHostException
- {
- if( addr.length != 16 )
- throw new UnknownHostException("Illegal address length: " + addr.length
- + " bytes.");
- Inet6Address ip = new Inet6Address( addr, host );
- ip.nif = nif;
-
- return ip;
- }
-
- /**
- * Returns the <code>NetworkInterface</code> of the address scope
- * if it is a scoped address and the scope is given in the form of a
- * NetworkInterface.
- * (I.e. the address was created using the
- * getByAddress(String, byte[], NetworkInterface) method)
- * Otherwise this method returns <code>null</code>.
- * @since 1.5
- */
- public NetworkInterface getScopedInterface()
- {
- return nif;
- }
-
- /**
- * Returns the scope ID of the address scope if it is a scoped adress using
- * an integer to identify the scope.
- *
- * Otherwise this method returns 0.
- * @since 1.5
- */
- public int getScopeId()
- {
- // check scope_id_set because some JDK-serialized objects seem to have
- // scope_id set to a nonzero value even when scope_id_set == false
- if( scope_id_set )
- return scope_id;
- return 0;
- }
-
- /**
- * Returns the IP address string in textual presentation
- */
- public String getHostAddress()
- {
- StringBuffer sbuf = new StringBuffer(40);
-
- for (int i = 0; i < 16; i += 2)
- {
- int x = ((ipaddress[i] & 0xFF) << 8) | (ipaddress[i + 1] & 0xFF);
-
- if (i > 0)
- sbuf.append(':');
-
- sbuf.append(Integer.toHexString(x));
- }
- if( nif != null )
- sbuf.append( "%" + nif.getName() );
- else if( scope_id_set )
- sbuf.append( "%" + scope_id );
-
- return sbuf.toString();
- }
-
- /**
- * Returns a hashcode for this IP address
- * (The hashcode is independent of scope)
- */
- public int hashCode()
- {
- return super.hashCode();
- }
-
- /**
- * Compares this object against the specified object
- */
- public boolean equals(Object obj)
- {
- if (! (obj instanceof Inet6Address))
- return false;
-
- Inet6Address ip = (Inet6Address)obj;
- if (ipaddress.length != ip.ipaddress.length)
- return false;
-
- for (int i = 0; i < ip.ipaddress.length; i++)
- if (ipaddress[i] != ip.ipaddress[i])
- return false;
-
- if( ip.nif != null && nif != null )
- return nif.equals( ip.nif );
- if( ip.nif != nif )
- return false;
- if( ip.scope_id_set != scope_id_set )
- return false;
- if( scope_id_set )
- return (scope_id == ip.scope_id);
- return true;
- }
-
- /**
- * Utility routine to check if the InetAddress is an
- * IPv4 compatible IPv6 address
- *
- * @since 1.4
- */
- public boolean isIPv4CompatibleAddress()
- {
- if (ipaddress[0] != 0x00 || ipaddress[1] != 0x00 || ipaddress[2] != 0x00
- || ipaddress[3] != 0x00 || ipaddress[4] != 0x00
- || ipaddress[5] != 0x00 || ipaddress[6] != 0x00
- || ipaddress[7] != 0x00 || ipaddress[8] != 0x00
- || ipaddress[9] != 0x00 || ipaddress[10] != 0x00
- || ipaddress[11] != 0x00)
- return false;
-
- return true;
- }
-
- /**
- * Required for 1.5-compatible serialization.
- * @since 1.5
- */
- private void readObject(ObjectInputStream s)
- throws IOException, ClassNotFoundException
- {
- s.defaultReadObject();
- try
- {
- if( scope_ifname_set )
- nif = NetworkInterface.getByName( ifname );
- }
- catch( SocketException se )
- {
- // FIXME: Ignore this? or throw an IOException?
- }
- }
-
- /**
- * Required for 1.5-compatible serialization.
- * @since 1.5
- */
- private void writeObject(ObjectOutputStream s)
- throws IOException
- {
- if( nif != null )
- {
- ifname = nif.getName();
- scope_ifname_set = true;
- }
- s.defaultWriteObject();
- }
-}
Deleted: trunk/core/src/classpath/java/java/net/InetAddress.java
===================================================================
--- trunk/core/src/classpath/java/java/net/InetAddress.java 2009-03-17 13:25:49 UTC (rev 5113)
+++ trunk/core/src/classpath/java/java/net/InetAddress.java 2009-03-18 21:02:34 UTC (rev 5114)
@@ -1,698 +0,0 @@
-/* InetAddress.java -- Class to model an Internet address
- Copyright (C) 1998, 1999, 2002, 2004, 2005 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. */
-
-
-package java.net;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamException;
-import java.io.Serializable;
-import java.util.StringTokenizer;
-
-/**
- * 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().
- *
- * <p>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.</p>
- *
- * @author Aaron M. Renn (ar...@ur...)
- * @author Per Bothner
- *
- * @specnote This class is not final since JK 1.4
- */
-public class InetAddress implements Serializable
-{
- private static final long serialVersionUID = 3286316764910316507L;
-
- /**
- * The special IP address INADDR_ANY.
- */
- private static InetAddress inaddr_any;
-
- /**
- * Dummy InetAddress, used to bind socket to any (all) network interfaces.
- */
- static InetAddress ANY_IF;
-
- /**
- * Stores static localhost address object.
- */
- static InetAddress LOCALHOST;
-
- static
- {
- // precompute the ANY_IF address
- try
- {
- ANY_IF = getInaddrAny();
-
- byte[] ip_localhost = { 127, 0, 0, 1 };
- LOCALHOST = new Inet4Address(ip_localhost, "localhost");
- }
- catch (UnknownHostException uhe)
- {
- // Hmmm, make one up and hope that it works.
- byte[] zeros = { 0, 0, 0, 0 };
- ANY_IF = new Inet4Address(zeros, "0.0.0.0");
- }
- }
-
- /**
- * The Serialized Form specifies that an int 'address' is saved/restored.
- * This class uses a byte array internally so we'll just do the conversion
- * at serialization time and leave the rest of the algorithm as is.
- */
- private int address;
-
- /**
- * An array of octets representing an IP address.
- */
- transient byte[] addr;
-
- /**
- * The name of the host for this address.
- */
- String hostName;
-
- /**
- * The field 'family' seems to be the AF_ value.
- * FIXME: Much of the code in the other java.net classes does not make
- * use of this family field. A better implementation would be to make
- * use of getaddrinfo() and have other methods just check the family
- * field rather than examining the length of the address each time.
- */
- int family;
-
- /**
- * Initializes this object's addr instance variable from the passed in
- * byte array. Note that this constructor is protected and is called
- * only by static methods in this class.
- *
- * @param ipaddr The IP number of this address as an array of bytes
- * @param hostname The hostname of this IP address.
- */
- InetAddress(byte[] ipaddr, String hostname)
- {
- addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone();
- hostName = hostname;
-
- family = 2; /* AF_INET */
- }
-
- /**
- * 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.
- *
- * @return true if mulitcast, false if not
- *
- * @since 1.1
- */
- public boolean isMulticastAddress()
- {
- // Mask against high order bits of 1110
- if (addr.length == 4)
- return (addr[0] & 0xf0) == 0xe0;
-
- return false;
- }
-
- /**
- * Utility routine to check if the InetAddress in a wildcard address
- *
- * @since 1.4
- */
- public boolean isAnyLocalAddress()
- {
- // This is the IPv4 implementation.
- // Any class derived from InetAddress should override this.
- return equals(ANY_IF);
- }
-
- /**
- * Utility routine to check if the InetAddress is a loopback address
- *
- * @since 1.4
- */
- public boolean isLoopbackAddress()
- {
- // This is the IPv4 implementation.
- // Any class derived from InetAddress should override this.
- return (addr[0] & 0xff) == 0x7f;
- }
-
- /**
- * Utility routine to check if InetAddress is a link local address
- *
- * @since 1.4
- */
- public boolean isLinkLocalAddress()
- {
- // This is the IPv4 implementation.
- // Any class derived from InetAddress should override this.
- // XXX: This seems to not exist with IPv4 addresses
- return false;
- }
-
- /**
- * Utility routine to check if InetAddress is a site local address
- *
- * @since 1.4
- */
- public boolean isSiteLocalAddress()
- {
- // This is the IPv4 implementation.
- // Any class derived from InetAddress should override this.
-
- // 10.0.0.0/8
- if ((addr[0] & 0xff) == 0x0a)
- return true;
-
- // 172.16.0.0/12
- if ((addr[0] & 0xff) == 0xac && (addr[1] & 0xf0) == 0x10)
- return true;
-
- // 192.168.0.0/16
- if ((addr[0] & 0xff) == 0xc0 && (addr[1] & 0xff) == 0xa8)
- return true;
-
- // XXX: Do we need to check more addresses here ?
- return false;
- }
-
- /**
- * Utility routine to check if InetAddress is a global multicast address
- *
- * @since 1.4
- */
- public boolean isMCGlobal()
- {
- // This is the IPv4 implementation.
- // Any class derived from InetAddress should override this.
- // XXX: This seems to not exist with IPv4 addresses
- return false;
- }
-
- /**
- * Utility routine to check if InetAddress is a node local multicast address.
- *
- * @since 1.4
- */
- public boolean isMCNodeLocal()
- {
- // This is the IPv4 implementation.
- // Any class derived from InetAddress should override this.
- // XXX: This seems to not exist with IPv4 addresses
- return false;
- }
-
- /**
- * Utility routine to check if InetAddress is a link local multicast address.
- *
- * @since 1.4
- */
- public boolean isMCLinkLocal()
- {
- // This is the IPv4 implementation.
- // Any class derived from InetAddress should override this.
- if (! isMulticastAddress())
- return false;
-
- return ((addr[0] & 0xff) == 0xe0
- && (addr[1] & 0xff) == 0x00
- && (addr[2] & 0xff) == 0x00);
- }
-
- /**
- * Utility routine to check if InetAddress is a site local multicast address.
- *
- * @since 1.4
- */
- public boolean isMCSiteLocal()
- {
- // This is the IPv4 implementation.
- // Any class derived from InetAddress should override this.
- // XXX: This seems to not exist with IPv4 addresses
- return false;
- }
-
- /**
- * Utility routine to check if InetAddress is a organization local
- * multicast address.
- *
- * @since 1.4
- */
- public boolean isMCOrgLocal()
- {
- // This is the IPv4 implementation.
- // Any class derived from InetAddress should override this.
- // XXX: This seems to not exist with IPv4 addresses
- return false;
- }
-
- /**
- * Returns the hostname for this address. This will return the IP address
- * as a String if there is no hostname available for this address
- *
- * @return The hostname for this address
- */
- public String getHostName()
- {
- if (hostName != null)
- return hostName;
-
- try
- {
- hostName = VMInetAddress.getHostByAddr(addr);
- return hostName;
- }
- catch (UnknownHostException e)
- {
- return getHostAddress();
- }
- }
-
- //jnode
- String getHostName(boolean check){
- return getHostName();
- }
-
- /**
- * Returns the canonical hostname represented by this InetAddress
- *
- * @since 1.4
- */
- public String getCanonicalHostName()
- {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null)
- {
- try
- {
- sm.checkConnect(hostName, -1);
- }
- catch (SecurityException e)
- {
- return getHostAddress();
- }
- }
-
- // Try to find the FDQN now
- InetAddress address;
- byte[] ipaddr = getAddress();
-
- if (ipaddr.length == 16)
- address = new Inet6Address(getAddress(), null);
- else
- address = new Inet4Address(getAddress(), null);
-
- return address.getHostName();
- }
-
- /**
- * Returns the IP address of this object as a byte array.
- *
- * @return IP address
- */
- public byte[] getAddress()
- {
- // An experiment shows that JDK1.2 returns a different byte array each
- // time. This makes sense, in terms of security.
- return (byte[]) addr.clone();
- }
-
- /**
- * Returns the IP address of this object as a String. The address is in
- * the dotted octet notation, for example, "127.0.0.1".
- *
- * @return The IP address of this object in String form
- *
- * @since 1.0.2
- */
- public String getHostAddress()
- {
- StringBuffer sb = new StringBuffer(40);
-
- int len = addr.length;
- int i = 0;
-
- for ( ; ; )
- {
- sb.append(addr[i] & 0xff);
- i++;
-
- if (i == len)
- break;
-
- sb.append('.');
- }
-
- return sb.toString();
- }
-
- /**
- * Returns a hash value for this address. Useful for creating hash
- * tables. Overrides Object.hashCode()
- *
- * @return A hash value for this address.
- */
- public int hashCode()
- {
- // There hashing algorithm is not specified, but a simple experiment
- // shows that it is equal to the address, as a 32-bit big-endian integer.
- int hash = 0;
- int len = addr.length;
- int i = len > 4 ? len - 4 : 0;
-
- for (; i < len; i++)
- hash = (hash << 8) | (addr[i] & 0xff);
-
- return hash;
- }
-
- /**
- * 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()
- *
- * @param obj The address to test for equality
- *
- * @return true if the passed in object's address is equal to this one's,
- * false otherwise
- */
- public boolean equals(Object obj)
- {
- if (! (obj instanceof InetAddress))
- return false;
-
- // "The Java Class Libraries" 2nd edition says "If a machine has
- // multiple names instances of InetAddress for different name of
- // that same machine are not equal. This is because they have
- // different host names." This violates the description in the
- // JDK 1.2 API documentation. A little experimentation
- // shows that the latter is correct.
- byte[] addr2 = ((InetAddress) obj).addr;
-
- if (addr.length != addr2.length)
- return false;
-
- for (int i = 0; i < addr.length; i++)
- if (addr[i] != addr2[i])
- return false;
-
- return true;
- }
-
- /**
- * 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()
- *
- * @return This address in String form
- */
- public String toString()
- {
- String addr = getHostAddress();
- String host = (hostName != null) ? hostName : "";
- return host + "/" + addr;
- }
-
- /**
- * 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].
- *
- * @param addr The IP address to create the InetAddress object from
- *
- * @exception UnknownHostException If IP address has illegal length
- *
- * @since 1.4
- */
- public static InetAddress getByAddress(byte[] addr)
- throws UnknownHostException
- {
- return getByAddress(null, addr);
- }
-
- /**
- * Creates an InetAddress based on the provided host name and IP address.
- * No name service is checked for the validity of the address.
- *
- * @param host The hostname of the InetAddress object to create
- * @param addr The IP address to create the InetAddress object from
- *
- * @exception UnknownHostException If IP address is of illegal length
- *
- * @since 1.4
- */
- public static InetAddress getByAddress(String host, byte[] addr)
- throws UnknownHostException
- {
- if (addr.length == 4)
- return new Inet4Address(addr, host);
-
- if (addr.length == 16)
- return new Inet6Address(addr, host);
-
- throw new UnknownHostException("IP address has illegal length");
- }
-
- /**
- * If hostname is a valid numeric IP address, return the numeric address.
- * Otherwise, return null.
- *
- * @param hostname the name of the host
- */
- private static byte[] aton(String hostname)
- {
- StringTokenizer st = new StringTokenizer(hostname, ".");
-
- if (st.countTokens() == 4)
- {
- int index;
- byte[] address = new byte[4];
-
- for (index = 0; index < 4; index++)
- {
- try
- {
- short n = Short.parseShort(st.nextToken());
-
- if ((n < 0) || (n > 255))
- break;
-
- address[index] = (byte) n;
- }
- catch (NumberFormatException e)
- {
- break;
- }
- }
-
- if (index == 4)
- return address;
- }
-
- return null;
- }
-
- /**
- * 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.
- *
- * @param hostname The name of the desired host, or null for the local
- * loopback address.
- *
- * @return The address of the host as an InetAddress object.
- *
- * @exception UnknownHostException If no IP address for the host could
- * be found
- * @exception SecurityException If a security manager exists and its
- * checkConnect method doesn't allow the operation
- */
- public static InetAddress getByName(String hostname)
- throws UnknownHostException
- {
- InetAddress[] addresses = getAllByName(hostname);
- return addresses[0];
- }
-
- /**
- * 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.
- *
- * @param hostname The name of the desired host, or null for the
- * local loopback address.
- *
- * @return All addresses of the host as an array of InetAddress objects.
- *
- * @exception UnknownHostException If no IP address for the host could
- * be found
- * @exception SecurityException If a security manager exists and its
- * checkConnect method doesn't allow the operation
- */
- public static InetAddress[] getAllByName(String hostname)
- throws UnknownHostException
- {
- return getAllByName0(hostname, true);
- }
-
- //jnode
- static InetAddress[] getAllByName0(String hostname, boolean check)
- throws UnknownHostException
- {
- if(check){
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkConnect(hostname, -1);
- }
-
- InetAddress[] addresses;
-
- if (hostname != null)
- hostname = hostname.trim();
-
- // Default to current host if necessary
- if (hostname == null || hostname.equals(""))
- {
- addresses = new InetAddress[1];
- addresses[0] = LOCALHOST;
- return addresses;
- }
-
- // Not in cache, try the lookup
- byte[][] iplist = VMInetAddress.getHostByName(hostname);
-
- if (iplist.length == 0)
- throw new UnknownHostException(hostname);
-
- addresses = new InetAddress[iplist.length];
-
- for (int i = 0; i < iplist.length; i++)
- {
- if (iplist[i].length != 4)
- throw new UnknownHostException(hostname);
-
- addresses[i] = new Inet4Address(iplist[i], hostname);
- }
-
- return addresses;
- }
-
- /**
- * Returns the special address INADDR_ANY used for binding to a local
- * port on all IP addresses hosted by a the local host.
- *
- * @return An InetAddress object representing INDADDR_ANY
- *
- * @exception UnknownHostException If an error occurs
- */
- static InetAddress getInaddrAny() throws UnknownHostException
- {
- if (inaddr_any == null)
- {
- byte[] tmp = VMInetAddress.lookupInaddrAny();
- inaddr_any = new Inet4Address(tmp, null);
- inaddr_any.hostName = inaddr_any.getHostName();
- }
-
- return inaddr_any;
- }
-
- /**
- * Returns an InetAddress object representing the address of the current
- * host.
- *
- * @return The local host's address
- *
- * @exception UnknownHostException If no IP address for the host could
- * be found
- */
- public static InetAddress getLocalHost() throws UnknownHostException
- {
- String hostname = VMInetAddress.getLocalHostname();
- return getByName(hostname);
- }
-
- /*
- * Needed for serialization
- */
- private Object readResolve() throws ObjectStreamException
- {
- return new Inet4Address(addr, hostName);
- }
-
- private void readObject(ObjectInputStream ois)
- throws IOException, ClassNotFoundException
- {
- ois.defaultReadObject();
- addr = new byte[4];
- addr[3] = (byte) address;
-
- for (int i = 2; i >= 0; --i)
- addr[i] = (byte) (address >>= 8);
-
- family = 2; /* AF_INET */
- }
-
- private void writeObject(ObjectOutputStream oos) throws IOException
- {
- // Build a 32 bit address from the last 4 bytes of a 4 byte IPv4 address
- // or a 16 byte IPv6 address.
- int len = addr.length;
- int i = len - 4;
-
- for (; i < len; i++)
- address = address << 8 | (addr[i] & 0xff);
-
- oos.defaultWriteObject();
- }
-}
Deleted: trunk/core/src/classpath/java/java/net/InetSocketAddress.java
===================================================================
--- trunk/core/src/classpath/java/java/net/InetSocketAddress.java 2009-03-17 13:25:49 UTC (rev 5113)
+++ trunk/core/src/classpath/java/java/net/InetSocketAddress.java 2009-03-18 21:02:34 UTC (rev 5114)
@@ -1,261 +0,0 @@
-/* InetSocketAddress.java --
- Copyright (C) 2002, 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. */
-
-package java.net;
-
-
-/**
- * InetSocketAddress instances represent socket addresses
- * in the java.nio package. They encapsulate a InetAddress and
- * a port number.
- *
- * @since 1.4
- */
-public class InetSocketAddress extends SocketAddress
-{
- /**
- * Compatible with JDK 1.4+
- */
- private static final long serialVersionUID = 5076001401234631237L;
-
- /**
- * Name of host.
- */
- private String hostname;
-
- /**
- * Address of host.
- */
- private InetAddress addr;
-
- /**
- * Port of host.
- */
- private int port;
-
- /**
- * Constructs an InetSocketAddress instance.
- *
- * @param addr Address of the socket
- * @param port Port if the socket
- *
- * @exception IllegalArgumentException If the port number is illegel
- */
- public InetSocketAddress(InetAddress addr, int port)
- throws IllegalArgumentException
- {
- if (port < 0 || port > 65535)
- throw new IllegalArgumentException("Bad port number: " + port);
-
- if (addr == null)
- addr = InetAddress.ANY_IF;
-
- this.addr = addr;
- this.port = port;
- }
-
- /**
- * Constructs an InetSocketAddress instance.
- *
- * @param port Port if the socket
- *
- * @exception IllegalArgumentException If the port number is illegal
- */
- public InetSocketAddress(int port) throws IllegalArgumentException
- {
- this((InetAddress) null, port);
- }
-
- /**
- * Constructs an InetSocketAddress instance.
- *
- * @param hostname The hostname for the socket address
- * @param port The port for the socket address
- *
- * @exception IllegalArgumentException If the port number is illegal or
- * the hostname argument is null
- */
- public InetSocketAddress(String hostname, int port)
- {
- this(hostname, port, true);
- }
-
- /**
- * Constructs an InetSocketAddress instance.
- *
- * @param hostname The hostname for the socket address
- * @param port The port for the socket address
- * @param resolve <code>true</code> if the address has to be resolved,
- * <code>false</code> otherwise
- *
- * @exception IllegalArgumentException If the port number is illegal or
- * the hostname argument is null
- */
- private InetSocketAddress(String hostname, int port, boolean resolve)
- {
- if (hostname == null)
- throw new IllegalArgumentException("Null host name value");
-
- if (port < 0 || port > 65535)
- throw new IllegalArgumentException("Bad port number: " + port);
-
- this.port = port;
- this.hostname = hostname;
- this.addr = null;
-
- if (resolve)
- {
- try
- {
- this.addr = InetAddress.getByName(hostname);
- }
- catch (Exception e) // UnknownHostException, SecurityException
- {
- // Do nothing here. this.addr is already set to null.
- }
- }
-
- }
-
- /**
- * Creates an unresolved <code>InetSocketAddress</code> object.
- *
- * @param hostname The hostname for the socket address
- * @param port The port for the socket address
- *
- * @exception IllegalArgumentException If the port number is illegal or
- * the hostname argument is null
- *
- * @since 1.5
- */
- public static InetSocketAddress createUnresolved(String hostname, int port)
- {
- return new InetSocketAddress(hostname, port, false);
- }
-
- /**
- * Test if obj is a <code>InetSocketAddress</code> and
- * has the same address and port
- *
- * @param obj The obj to compare this address with.
- *
- * @return True if obj is equal.
- */
- public final boolean equals(Object obj)
- {
- // InetSocketAddress objects are equal when addr and port are equal.
- // The hostname may differ.
- if (obj instanceof InetSocketAddress)
- {
- InetSocketAddress sa = (InetSocketAddress) obj;
-
- if (addr == null && sa.addr != null)
- return false;
- else if (addr == null && sa.addr == null) // we know hostname != null
- return hostname.equals(sa.hostname) && sa.port == port;
- else
- return addr.equals(sa.addr) && sa.port == port;
- }
-
- return false;
- }
-
- /**
- * Returns the <code>InetAddress</code> or
- * <code>null</code> if its unresolved
- *
- * @return The IP address of this address.
- */
- public final InetAddress getAddress()
- {
- return addr;
- }
-
- /**
- * Returns <code>hostname</code>
- *
- * @return The hostname of this address.
- */
- public final String getHostName()
- {
- if (hostname == null) // we know addr != null
- hostname = addr.getHostName();
-
- return hostname;
- }
-
- /**
- * Returns the <code>port</code>
- *
- * @return The port of this address.
- */
- public final int getPort()
- {
- return port;
- }
-
- /**
- * Returns the hashcode of the <code>InetSocketAddress</code>
- *
- * @return The hashcode for this address.
- */
- public final int hashCode()
- {
- return port + addr.hashCode();
- }
-
- /**
- * Checks wether the address has been resolved or not
- *
- * @return True if address is unresolved.
- */
- public final boolean isUnresolved()
- {
- return addr == null;
- }
-
- /**
- * Returns the <code>InetSocketAddress</code> as string
- *
- * @return A string representation of this address.
- */
- public String toString()
- {
- // Note: if addr is null, then hostname != null.
- return (addr == null ? hostname : addr.toString()) + ":" + port;
- }
-}
Modified: trunk/core/src/classpath/java/java/net/ServerSocket.java
===================================================================
--- trunk/core/src/classpath/java/java/net/ServerSocket.java 2009-03-17 13:25:49 UTC (rev 5113)
+++ trunk/core/src/classpath/java/java/net/ServerSocket.java 2009-03-18 21:02:34 UTC (rev 5114)
@@ -233,7 +233,7 @@
// Initialize addr with 0.0.0.0.
if (addr == null)
- addr = InetAddress.ANY_IF;
+ addr = NativeInetAddress.ANY_IF;
try
{
Modified: trunk/core/src/classpath/java/java/net/Socket.java
===================================================================
--- trunk/core/src/classpath/java/java/net/Socket.java 2009-03-17 13:25:49 UTC (rev 5113)
+++ trunk/core/src/classpath/java/java/net/Socket.java 2009-03-18 21:02:34 UTC (rev 5114)
@@ -354,7 +354,7 @@
// XXX: JDK 1.4.1 API documentation says that if bindpoint is null the
// socket will be bound to an ephemeral port and a valid local address.
if (bindpoint == null)
- bindpoint = new InetSocketAddress(InetAddress.ANY_IF, 0);
+ bindpoint = new InetSocketAddress(NativeInetAddress.ANY_IF, 0);
if (! (bindpoint instanceof InetSocketAddress))
throw new IllegalArgumentException();
@@ -479,7 +479,7 @@
public InetAddress getLocalAddress()
{
if (! isBound())
- return InetAddress.ANY_IF;
+ return NativeInetAddress.ANY_IF;
InetAddress addr = null;
Added: trunk/core/src/openjdk/java/java/net/Inet4Address.java
===================================================================
--- trunk/core/src/openjdk/java/java/net/Inet4Address.java (rev 0)
+++ trunk/core/src/openjdk/java/java/net/Inet4Address.java 2009-03-18 21:02:34 UTC (rev 5114)
@@ -0,0 +1,374 @@
+/*
+ * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.net;
+
+import java.security.AccessController;
+import java.io.ObjectStreamException;
+import sun.security.action.*;
+
+/**
+ * This class represents an Internet Protocol version 4 (IPv4) address.
+ * Defined by <a href="http://www.ietf.org/rfc/rfc790.txt">
+ * <i>RFC 790: Assigned Numbers</i></a>,
+ * <a href="http://www.ietf.org/rfc/rfc1918.txt">
+ * <i>RFC 1918: Address Allocation for Private Internets</i></a>,
+ * and <a href="http://www.ietf.org/rfc/rfc2365.txt"><i>RFC 2365:
+ * Administratively Scoped IP Multicast</i></a>
+ *
+ * <h4> <A NAME="format">Textual representation of IP addresses</a> </h4>
+ *
+ * Textual representation of IPv4 address used as input to methods
+ * takes one of the following forms:
+ *
+ * <blockquote><table cellpadding=0 cellspacing=0 summary="layout">
+ * <tr><td><tt>d.d.d.d</tt></td></tr>
+ * <tr><td><tt>d.d.d</tt></td></tr>
+ * <tr><td><tt>d.d</tt></td></tr>
+ * <tr><td><tt>d</tt></td></tr>
+ * </table></blockquote>
+ *
+ * <p> When four parts are specified, each is interpreted as a byte of
+ * data and assigned, from left to right, to the four bytes of an IPv4
+ * address.
+
+ * <p> When a three part address is specified, the last part is
+ * interpreted as a 16-bit quantity and placed in the right most two
+ * bytes of the network address. This makes the three part address
+ * format convenient for specifying Class B net- work addresses as
+ * 128.net.host.
+ *
+ * <p> When a two part address is supplied, the last part is
+ * interpreted as a 24-bit quantity and placed in the right most three
+ * bytes of the network address. This makes the two part address
+ * format convenient for specifying Class A network addresses as
+ * net.host.
+ *
+ * <p> When only one part is given, the value is stored directly in
+ * the network address without any byte rearrangement.
+ *
+ * <p> For methods that return a textual representation as output
+ * value, the first form, i.e. a dotted-quad string, is used.
+ *
+ * <h4> The Scope of a Multicast Address </h4>
+ *
+ * Historically the IPv4 TTL field in the IP header has doubled as a
+ * multicast scope field: a TTL of 0 means node-local, 1 means
+ * link-local, up through 32 means site-local, up through 64 means
+ * region-local, up through 128 means continent-local, and up through
+ * 255 are global. However, the administrative scoping is preferred.
+ * Please refer to <a href="http://www.ietf.org/rfc/rfc2365.txt">
+ * <i>RFC 2365: Administratively Scoped IP Multicast</i></a>
+ * @since 1.4
+ */
+
+public final
+class Inet4Address extends InetAddress {
+ final static int INADDRSZ = 4;
+
+ /** use serialVersionUID from InetAddress, but Inet4Address instance
+ * is always replaced by an InetAddress instance before being
+ * serialized */
+ private static final long serialVersionUID = 3286316764910316507L;
+
+ /*
+ * Perform initializations.
+ */
+ static {
+ init();
+ }
+
+ Inet4Address() {
+ super();
+ hostName = null;
+ address = 0;
+ family = IPv4;
+ }
+
+ Inet4Address(String hostName, byte addr[]) {
+ this.hostName = hostName;
+ this.family = IPv4;
+ if (addr != null) {
+ if (addr.length == INADDRSZ) {
+ address = addr[3] & 0xFF;
+ address |= ((addr[2] << 8) & 0xFF00);
+ address |= ((addr[1] << 16) & 0xFF0000);
+ address |= ((addr[0] << 24) & 0xFF000000);
+ }
+ }
+ }
+ Inet4Address(String hostName, int address) {
+ this.hostName = hostName;
+ this.family = IPv4;
+ this.address = address;
+ }
+
+ /**
+ * Replaces the object to be serialized with an InetAddress object.
+ *
+ * @return the alternate object to be serialized.
+ *
+ * @throws ObjectStreamException if a new object replacing this
+ * object could not be created
+ */
+ private Object writeReplace() throws ObjectStreamException {
+ // will replace the to be serialized 'this' object
+ InetAddress inet = new InetAddress();
+ inet.hostName = this.hostName;
+ inet.address = this.address;
+
+ /**
+ * Prior to 1.4 an InetAddress was created with a family
+ * based on the platform AF_INET value (usually 2).
+ * For compatibility reasons we must therefore write the
+ * the InetAddress with this family.
+ */
+ inet.family = 2;
+
+ return inet;
+ }
+
+ /**
+ * Utility routine to check if the InetAddress is an
+ * IP multicast address. IP multicast address is a Class D
+ * address i.e first four bits of the address are 1110.
+ * @return a <code>boolean</code> indicating if the InetAddress is
+ * an IP multicast address
+ * @since JDK1.1
+ */
+ public boolean isMulticastAddress() {
+ return ((address & 0xf0000000) == 0xe0000000);
+ }
+
+ /**
+ * Utility routine to check if the InetAddress in a wildcard address.
+ * @return a <code>boolean</code> indicating if the Inetaddress is
+ * a wildcard address.
+ * @since 1.4
+ */
+ public boolean isAnyLocalAddress() {
+ return address == 0;
+ }
+
+ /**
+ * Utility routine to check if the InetAddress is a loopback address.
+ *
+ * @return a <code>boolean</code> indicating if the InetAddress is
+ * a loopback address; or false otherwise.
+ * @since 1.4
+ */
+ private static final int loopback = 2130706433; /* 127.0.0.1 */
+ public boolean isLoopbackAddress() {
+ /* 127.x.x.x */
+ byte[] byteAddr = getAddress();
+ return byteAddr[0] == 127;
+ }
+
+ /**
+ * Utility routine to check if the InetAddress is an link local address.
+ *
+ * @return a <code>boolean</code> indicating if the InetAddress is
+ * a link local address; or false if address is not a link local unicast address.
+ * @since 1.4
+ */
+ public boolean isLinkLocalAddress() {
+ // link-local unicast in IPv4 (169.254.0.0/16)
+ // defined in "Documenting Special Use IPv4 Address Blocks
+ // that have been Registered with IANA" by Bill Manning
+ // draft-manning-dsua-06.txt
+ return (((address >>> 24) & 0xFF) == 169)
+ && (((address >>> 16) & 0xFF) == 254);
+ }
+
+ /**
+ * Utility routine to check if the InetAddress is a site local address.
+ *
+ * @return a <code>boolean</code> indicating if the InetAddress is
+ * a site local address; or false if address is not a site local unicast address.
+ * @since 1.4
+ */
+ public boolean isSiteLocalAddress() {
+ // refer to RFC 1918
+ // 10/8 prefix
+ // 172.16/12 prefix
+ // 192.168/16 prefix
+ return (((address >>> 24) & 0xFF) == 10)
+ || ((((address >>> 24) & 0xFF) == 172)
+ && (((address >>> 16) & 0xF0) == 16))
+ || ((((address >>> 24) & 0xFF) == 192)
+ && (((address >>> 16) & 0xFF) == 168));
+ }
+
+ /**
+ * Utility routine to check if the multicast address has global scope.
+ *
+ * @return a <code>boolean</code> indicating if the address has
+ * is a multicast address of global scope, false if it is not
+ * of global scope or it is not a multicast address
+ * @since 1.4
+ */
+ public boolean isMCGlobal() {
+ // 224.0.1.0 to 238.255.255.255
+ byte[] byteAddr = getAddress();
+ return ((byteAddr[0] & 0xff) >= 224 && (byteAddr[0] & 0xff) <= 238 ) &&
+ !((byteAddr[0] & 0xff) == 224 && byteAddr[1] == 0 &&
+ byteAddr[2] == 0);
+ }
+
+ /**
+ * Utility routine to check if the multicast address has node scope.
+ *
+ * @return a <code>boolean</code> indicating if the address has
+ * is a multicast address of node-local scope, false if it is not
+ * of node-local scope or it is not a multicast address
+ * @since 1.4
+ */
+ public boolean isMCNodeLocal() {
+ // unless ttl == 0
+ return false;
+ }
+
+ /**
+ * Utility routine to check if the multicast address has link scope.
+ *
+ * @return a <code>boolean</code> indicating if the address has
+ * is a multicast address of link-local scope, false if it is not
+ * of link-local scope or it is not a multicast address
+ * @since 1.4
+ */
+ public boolean isMCLinkLocal() {
+ // 224.0.0/24 prefix and ttl == 1
+ return (((address >>> 24) & 0xFF) == 224)
+ && (((address >>> 16) & 0xFF) == 0)
+ && (((address >>> 8) & 0xFF) == 0);
+ }
+
+ /**
+ * Utility routine to check if the multicast address has site scope.
+ *
+ * @return a <code>boolean</code> indicating if the address has
+ * is a multicast address of site-local scope, false if it is not
+ * of site-local scope or it is not a multicast address
+ * @since 1.4
+ */
+ public boolean isMCSiteLocal() {
+ // 239.255/16 prefix or ttl < 32
+ return (((address >>> 24) & 0xFF) == 239)
+ && (((address >>> 16) & 0xFF) == 255);
+ }
+
+ /**
+ * Utility routine to check if the multicast address has organization scope.
+ *
+ * @return a <code>boolean</code> indicating if the address has
+ * is a multicast address of organization-local scope,
+ * false if it is not of organization-local scope
+ * or it is not a multicast address
+ * @since 1.4
+ */
+ public boolean isMCOrgLocal() {
+ // 239.192 - 239.195
+ return (((address >>> 24) & 0xFF) == 239)
+ && (((address >>> 16) & 0xFF) >= 192)
+ && (((address >>> 16) & 0xFF) <= 195);
+ }
+
+ /**
+ * Returns the raw IP address of this <code>InetAddress</code>
+ * object. The resul...
[truncated message content] |