From bb230db0a6c6d9e374fbfc81cd0d7884ff862621 Mon Sep 17 00:00:00 2001 From: mkoch Date: Mon, 22 Sep 2003 07:56:44 +0000 Subject: [PATCH] 2003-09-22 Michael Koch * java/net/InetAddress.java: Moves around some code, reformats and adds documentation. No functional changes. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@71649 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/ChangeLog | 6 ++ libjava/java/net/InetAddress.java | 140 +++++++++++++++++++++++--------------- 2 files changed, 93 insertions(+), 53 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index da74f18..a2b7450 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,11 @@ 2003-09-22 Michael Koch + * java/net/InetAddress.java: + Moves around some code, reformats and adds documentation. + No functional changes. + +2003-09-22 Michael Koch + * java/net/JarURLConnection.java (JarURLConnection): Modifed code to match classpath more, fixed comment. (getCertificates): Made it more error prone. diff --git a/libjava/java/net/InetAddress.java b/libjava/java/net/InetAddress.java index 8ef6366..6a841d0 100644 --- a/libjava/java/net/InetAddress.java +++ b/libjava/java/net/InetAddress.java @@ -70,61 +70,63 @@ public class InetAddress implements Serializable { 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. + 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 InetAddress localhost = null; + + /** + * 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. + /** + * 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; /** - * Needed for serialization + * 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 */ - private void readResolve () throws ObjectStreamException + InetAddress (byte[] address) { - // 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 (); + this (address, null); } - 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 + * @param hostname The hostname of this IP address. + */ InetAddress (byte[] address, String hostname) { addr = address; @@ -530,6 +532,8 @@ public class InetAddress implements Serializable 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 @@ public class InetAddress implements Serializable 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 * @@ -681,4 +676,43 @@ public class InetAddress implements Serializable 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 (); + } } -- 2.7.4