summaryrefslogtreecommitdiff
path: root/libjava/java/net/DatagramSocket.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/net/DatagramSocket.java')
-rw-r--r--libjava/java/net/DatagramSocket.java44
1 files changed, 19 insertions, 25 deletions
diff --git a/libjava/java/net/DatagramSocket.java b/libjava/java/net/DatagramSocket.java
index 57f3da70862..401bcb82697 100644
--- a/libjava/java/net/DatagramSocket.java
+++ b/libjava/java/net/DatagramSocket.java
@@ -35,8 +35,10 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
+
package java.net;
+import gnu.java.net.PlainDatagramSocketImpl;
import java.io.IOException;
import java.nio.channels.DatagramChannel;
import java.nio.channels.IllegalBlockingModeException;
@@ -266,38 +268,30 @@ public class DatagramSocket
*/
public InetAddress getLocalAddress()
{
- // FIXME: JCL p. 510 says this should call checkConnect. But what
- // string should be used as the hostname? Maybe this is just a side
- // effect of calling InetAddress.getLocalHost.
- //
- // And is getOption with SO_BINDADDR the right way to get the address?
- // Doesn't seem to be since this method doesn't throw a SocketException
- // and SO_BINADDR can throw one.
- //
- // Also see RETURNS section in JCL p. 510 about returning any local
- // addr "if the current execution context is not allowed to connect to
- // the network interface that is actually bound to this datagram socket."
- // How is that done? via InetAddress.getLocalHost? But that throws
- // an UnknownHostException and this method doesn't.
- //
- // if (s != null)
- // s.checkConnect("localhost", -1);
+ if (impl == null
+ || closed)
+ return null;
+
+ InetAddress result;
+
try
{
- return (InetAddress)impl.getOption(SocketOptions.SO_BINDADDR);
- }
- catch (SocketException ex)
- {
- }
+ result = (InetAddress) impl.getOption (SocketOptions.SO_BINDADDR);
- try
+ SecurityManager s = System.getSecurityManager();
+ if (s != null)
+ s.checkConnect (result.getHostName(), -1);
+ }
+ catch (SecurityException e)
{
- return InetAddress.getLocalHost();
+ result = InetAddress.ANY_IF;
}
- catch (UnknownHostException ex)
+ catch (SocketException e)
{
- return null;
+ result = InetAddress.ANY_IF;
}
+
+ return result;
}
/**