--- a/jdk/src/share/classes/java/net/DatagramSocket.java Tue Dec 01 08:55:15 2009 -0800
+++ b/jdk/src/share/classes/java/net/DatagramSocket.java Wed Dec 02 12:17:42 2009 +0000
@@ -118,6 +118,7 @@
if (address == null) {
throw new IllegalArgumentException("connect: null address");
}
+ checkAddress (address, "connect");
if (isClosed())
return;
SecurityManager security = System.getSecurityManager();
@@ -363,13 +364,15 @@
InetSocketAddress epoint = (InetSocketAddress) addr;
if (epoint.isUnresolved())
throw new SocketException("Unresolved address");
+ InetAddress iaddr = epoint.getAddress();
+ int port = epoint.getPort();
+ checkAddress(iaddr, "bind");
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
- sec.checkListen(epoint.getPort());
+ sec.checkListen(port);
}
try {
- getImpl().bind(epoint.getPort(),
- epoint.getAddress());
+ getImpl().bind(port, iaddr);
} catch (SocketException e) {
getImpl().close();
throw e;
@@ -377,6 +380,15 @@
bound = true;
}
+ void checkAddress (InetAddress addr, String op) {
+ if (addr == null) {
+ return;
+ }
+ if (!(addr instanceof Inet4Address || addr instanceof Inet6Address)) {
+ throw new IllegalArgumentException(op + ": invalid address type");
+ }
+ }
+
/**
* Connects the socket to a remote address for this socket. When a
* socket is connected to a remote address, packets may only be
@@ -603,6 +615,7 @@
synchronized (p) {
if (isClosed())
throw new SocketException("Socket is closed");
+ checkAddress (p.getAddress(), "send");
if (connectState == ST_NOT_CONNECTED) {
// check the address is ok wiht the security manager on every send.
SecurityManager security = System.getSecurityManager();