aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Benson <gbenson@redhat.com>2006-08-29 08:15:29 +0000
committerGary Benson <gbenson@redhat.com>2006-08-29 08:15:29 +0000
commit6b0da91d258d1659ec89cecef53de7dc356b991c (patch)
tree53e7c80e941e421f65a1991199d5d89539682c2a
parentb03c6bd9fee4e17840a69963fd92bbadfe3ff974 (diff)
2006-08-29 Gary Benson <gbenson@redhat.com>
* java/net/SocketPermission.java (maybeBracketIPv6Address): New method. (<init>): Pass the hostport argument through the above. * java/net/NetworkInterface.java (getInetAddresses): Revert the previous change. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@116557 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libjava/classpath/ChangeLog.gcj9
-rw-r--r--libjava/classpath/java/net/NetworkInterface.java5
-rw-r--r--libjava/classpath/java/net/SocketPermission.java48
3 files changed, 56 insertions, 6 deletions
diff --git a/libjava/classpath/ChangeLog.gcj b/libjava/classpath/ChangeLog.gcj
index fda8d79d45f..adac6b7f02b 100644
--- a/libjava/classpath/ChangeLog.gcj
+++ b/libjava/classpath/ChangeLog.gcj
@@ -1,3 +1,12 @@
+2006-08-29 Gary Benson <gbenson@redhat.com>
+
+ * java/net/SocketPermission.java
+ (maybeBracketIPv6Address): New method.
+ (<init>): Pass the hostport argument through the above.
+
+ * java/net/NetworkInterface.java (getInetAddresses):
+ Revert the previous change.
+
2006-08-24 Gary Benson <gbenson@redhat.com>
* java/net/NetworkInterface.java (getInetAddresses): Bracket IPv6
diff --git a/libjava/classpath/java/net/NetworkInterface.java b/libjava/classpath/java/net/NetworkInterface.java
index f6db01b7182..47b1c67cae7 100644
--- a/libjava/classpath/java/net/NetworkInterface.java
+++ b/libjava/classpath/java/net/NetworkInterface.java
@@ -112,10 +112,7 @@ public final class NetworkInterface
InetAddress addr = (InetAddress) addresses.nextElement();
try
{
- String hostAddress = addr.getHostAddress();
- if (addr instanceof Inet6Address)
- hostAddress = "[" + hostAddress + "]";
- s.checkConnect(hostAddress, 58000);
+ s.checkConnect(addr.getHostAddress(), 58000);
tmpInetAddresses.add(addr);
}
catch (SecurityException e)
diff --git a/libjava/classpath/java/net/SocketPermission.java b/libjava/classpath/java/net/SocketPermission.java
index 723ccc7a5b5..a722fcad4e5 100644
--- a/libjava/classpath/java/net/SocketPermission.java
+++ b/libjava/classpath/java/net/SocketPermission.java
@@ -164,13 +164,57 @@ public final class SocketPermission extends Permission implements Serializable
*/
public SocketPermission(String hostport, String actions)
{
- super(hostport);
+ super(maybeBracketIPv6Address(hostport));
- setHostPort(hostport);
+ setHostPort(getName());
setActions(actions);
}
/**
+ * IPv6 addresses in the hostport must either be enclosed by
+ * "[" and "]" or be specified in the full uncompressed form.
+ * In the latter case proprietary JVMs will quote the address
+ * with "[" and "]", so we do to.
+ */
+ private static String maybeBracketIPv6Address(String hostport)
+ {
+ if (hostport.length() == 0 || hostport.charAt(0) == '[')
+ return hostport;
+
+ int colons = 0, last_colon = 0;
+ for (int i = 0; i < hostport.length(); i++)
+ {
+ if (hostport.charAt(i) == ':')
+ {
+ if (i - last_colon == 1)
+ throw new IllegalArgumentException("Ambiguous hostport part");
+ colons++;
+ last_colon = i;
+ }
+ }
+
+ switch (colons)
+ {
+ case 0:
+ case 1:
+ // a hostname or IPv4 address
+ return hostport;
+
+ case 7:
+ // an IPv6 address with no ports
+ return "[" + hostport + "]";
+
+ case 8:
+ // an IPv6 address with ports
+ return "[" + hostport.substring(0, last_colon) + "]"
+ + hostport.substring(last_colon);
+
+ default:
+ throw new IllegalArgumentException("Ambiguous hostport part");
+ }
+ }
+
+ /**
* Parse the hostport argument to the constructor.
*/
private void setHostPort(String hostport)