This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
FYI: Patch: java.net.InetAddress
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Mon, 22 Sep 2003 09:58:45 +0200
- Subject: FYI: Patch: java.net.InetAddress
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I commited the appended patch to trunk to make java/net/InetAddress a
little bit more similar to classpath's version. No functional
changes, just moving around and working on the documentation.
Michael
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQE/bqu2WSOgCCdjSDsRAuDwAJ4trnmwfHxswFtfJCaMrfeD1hbfcACgj1im
kYwbvqJ2sXcef8/epO3uvDI=
=SjvZ
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2165
diff -u -b -B -r1.2165 ChangeLog
--- ChangeLog 22 Sep 2003 05:48:31 -0000 1.2165
+++ ChangeLog 22 Sep 2003 07:54:53 -0000
@@ -1,5 +1,11 @@
2003-09-22 Michael Koch <konqueror@gmx.de>
+ * java/net/InetAddress.java:
+ Moves around some code, reformats and adds documentation.
+ No functional changes.
+
+2003-09-22 Michael Koch <konqueror@gmx.de>
+
* java/net/JarURLConnection.java
(JarURLConnection): Modifed code to match classpath more, fixed comment.
(getCertificates): Made it more error prone.
Index: java/net/InetAddress.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/InetAddress.java,v
retrieving revision 1.17
diff -u -b -B -r1.17 InetAddress.java
--- java/net/InetAddress.java 19 Jun 2003 15:08:22 -0000 1.17
+++ java/net/InetAddress.java 22 Sep 2003 07:54:53 -0000
@@ -70,61 +70,63 @@
{
private static final long serialVersionUID = 3286316764910316507L;
- // 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;
- transient byte[] addr;
- 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;
+ static final byte[] zeros = { 0, 0, 0, 0 };
/**
- * Needed for serialization
+ * Dummy InetAddress, used to bind socket to any (all) network interfaces.
*/
- private void readResolve () throws ObjectStreamException
- {
- // FIXME: implement this
- }
+ static final InetAddress ANY_IF = new InetAddress (zeros, null);
- private void readObject (ObjectInputStream ois)
- throws IOException, ClassNotFoundException
- {
- ois.defaultReadObject ();
- addr = new byte [4];
- addr [3] = (byte) address;
+ private static final byte[] localhostAddress = { 127, 0, 0, 1 };
- for (int i = 2; i >= 0; --i)
- addr [i] = (byte) (address >>= 8);
+ private static InetAddress localhost = null;
- // Ignore family from serialized data. Since the saved address is 32 bits
- // the deserialized object will have an IPv4 address i.e. AF_INET family.
- // FIXME: An alternative is to call the aton method on the deserialized
- // hostname to get a new address. The Serialized Form doc is silent
- // on how these fields are used.
- family = getFamily (addr);
- }
+ /**
+ * 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;
- 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;
+ /**
+ * An array of octets representing an IP address.
+ */
+ transient byte[] addr;
- for (; i < len; i++)
- address = address << 8 | (((int) addr [i]) & 0xFF);
+ /**
+ * The name of the host for this address.
+ */
+ String hostName;
- oos.defaultWriteObject ();
- }
+ /**
+ * 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;
- private static native int getFamily (byte[] address);
+ /**
+ * Initializes this object's addr instance variable from the passed in
+ * int 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
+ */
+ InetAddress (byte[] address)
+ {
+ this (address, null);
+ }
+ /**
+ * Initializes this object's addr instance variable from the passed in
+ * int 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[] address, String hostname)
{
addr = address;
@@ -530,6 +532,8 @@
private static native InetAddress[] lookup (String hostname,
InetAddress addr, boolean all);
+ private static native int getFamily (byte[] address);
+
/**
* Determines the IP address of a host, given the host's name.
*
@@ -606,17 +610,8 @@
return lookup (hostname, null, true);
}
- static final byte[] zeros = { 0, 0, 0, 0 };
-
- /* dummy InetAddress, used to bind socket to any (all) network interfaces */
- static final InetAddress ANY_IF = new InetAddress (zeros, null);
-
- private static final byte[] localhostAddress = { 127, 0, 0, 1 };
-
private static native String getLocalHostname ();
- private static InetAddress localhost = null;
-
/**
* Returns the local host
*
@@ -680,5 +675,44 @@
if (localhost == null)
localhost = new InetAddress (localhostAddress, "localhost");
+ }
+
+ /**
+ * Needed for serialization
+ */
+ private void readResolve () throws ObjectStreamException
+ {
+ // FIXME: implement this
+ }
+
+ 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);
+
+ // Ignore family from serialized data. Since the saved address is 32 bits
+ // the deserialized object will have an IPv4 address i.e. AF_INET family.
+ // FIXME: An alternative is to call the aton method on the deserialized
+ // hostname to get a new address. The Serialized Form doc is silent
+ // on how these fields are used.
+ family = getFamily (addr);
+ }
+
+ 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 | (((int) addr [i]) & 0xFF);
+
+ oos.defaultWriteObject ();
}
}