diff options
| author | Michael Koch <konqueror@gmx.de> | 2002-10-03 11:23:33 +0000 |
|---|---|---|
| committer | Michael Koch <mkoch@gcc.gnu.org> | 2002-10-03 11:23:33 +0000 |
| commit | e832ab3c91f01cdb1bd618ffe4a8e00505264d22 (patch) | |
| tree | aff5f3ab2e4d52928ed330a39300502da4fdce8b /libjava/java/net/DatagramSocket.java | |
| parent | 3eacc81d00aa85d20a95069177f608edb4f8104c (diff) | |
2002-09-30 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java
(receive): Check with SecurityManager AFTER the packet is received,
check if connected to multicast address, documentation added.
(send): Only check SecurityManager if connected, check address of
packet to send.
(connect): Implemented, documentation added.
* java/net/Inet6Address.java: New file (not added yet to Makefile.am).
* java/net/InetSocketAddress.java
(whole file): Reindented.
(hostname): New attribute.
(InetSocketAddress): Initialize new attribute.
(getAddress): Documentation added.
(getHostName): Documentation added.
(getPort): Documentation added.
(hashCode): Documentation added.
(isUnresolved): Documentation added.
(toString): Conform to output of JDK 1.4.1, documentation added.
* java/net/MulticastSocket.java
(joinGroup): Removed FIXME, documentation added.
(leaveGroup): Removed FIXME, documentation added.
(send): Documentation added.
* java/net/Socket.java
(inputShutdown): New variable.
(outputShutdown): New variable.
(Socket): Initialize new variables.
(getRemoteSocketAddress): Check if connected.
(shutdownInput): Set new variable.
(shutdownOutput): Set new variable.
(isConnected): New method.
(isClosed): New method.
(isInputShutdown): New method.
(isOutputShutdown): New method.
* java/net/URLStreamHandler.java
(URLStreamHandler): New method.
(openConnection): Added documentation.
(parseURL): Added documentation.
(getHostAddress): New method.
(getDefaultPort): New method.
From-SVN: r57772
Diffstat (limited to 'libjava/java/net/DatagramSocket.java')
| -rw-r--r-- | libjava/java/net/DatagramSocket.java | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/libjava/java/net/DatagramSocket.java b/libjava/java/net/DatagramSocket.java index dfbce3bcf7d..b2f2ca11ce3 100644 --- a/libjava/java/net/DatagramSocket.java +++ b/libjava/java/net/DatagramSocket.java @@ -290,20 +290,26 @@ public class DatagramSocket * exception will be thrown * @exception IllegalBlockingModeException If this socket has an associated * channel, and the channel is in non-blocking mode + * @exception SecurityException If a security manager exists and its + * checkAccept ethod doesn't allow the receive */ public synchronized void receive(DatagramPacket p) throws IOException { - SecurityManager s = System.getSecurityManager(); - if (s != null) - s.checkAccept (p.getAddress().getHostName (), p.getPort ()); - if (impl == null) throw new IOException ("Cannot initialize Socket implementation"); + if (remoteAddress != null && remoteAddress.isMulticastAddress ()) + throw new IOException ( + "Socket connected to a multicast address my not receive"); + if (ch != null && !ch.isBlocking ()) throw new IllegalBlockingModeException (); impl.receive(p); + + SecurityManager s = System.getSecurityManager(); + if (s != null && isConnected ()) + s.checkAccept (p.getAddress().getHostName (), p.getPort ()); } /** @@ -324,7 +330,7 @@ public class DatagramSocket { // JDK1.2: Don't do security checks if socket is connected; see jdk1.2 api. SecurityManager s = System.getSecurityManager(); - if (s != null) + if (s != null && !isConnected ()) { InetAddress addr = p.getAddress(); if (addr.isMulticastAddress()) @@ -332,6 +338,14 @@ public class DatagramSocket else s.checkConnect(addr.getHostAddress(), p.getPort()); } + + if (isConnected ()) + { + if (p.getAddress () != null && (remoteAddress != p.getAddress () || + remotePort != p.getPort ())) + throw new IllegalArgumentException ( + "DatagramPacket address does not match remote address" ); + } // FIXME: if this is a subclass of MulticastSocket, // use getTimeToLive for TTL val. @@ -376,7 +390,20 @@ public class DatagramSocket public void connect(InetAddress address, int port) throws SocketException { - //impl.connect(address, port); + if (address == null) + throw new IllegalArgumentException ("Address may not be null"); + + if (port < 1 || port > 65535) + throw new IllegalArgumentException ("Port number is illegal"); + + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkAccept(address.getHostName (), port); + + impl.connect (address, port); + + remoteAddress = address; + remotePort = port; } /** |
