jdk/src/solaris/classes/sun/nio/ch/sctp/SctpNet.java
changeset 18212 22f8c33b0690
parent 14342 8435a30053c1
child 23010 6dadb192ad81
--- a/jdk/src/solaris/classes/sun/nio/ch/sctp/SctpNet.java	Thu Mar 28 06:55:42 2013 -0400
+++ b/jdk/src/solaris/classes/sun/nio/ch/sctp/SctpNet.java	Thu Mar 28 14:34:18 2013 -0700
@@ -94,18 +94,44 @@
 
     static Set<SocketAddress> getLocalAddresses(int fd)
             throws IOException {
-        HashSet<SocketAddress> set = null;
+        Set<SocketAddress> set = null;
         SocketAddress[] saa = getLocalAddresses0(fd);
 
         if (saa != null) {
-            set = new HashSet<SocketAddress>(saa.length);
-            for (SocketAddress sa : saa)
-                set.add(sa);
+            set = getRevealedLocalAddressSet(saa);
         }
 
         return set;
     }
 
+    private static Set<SocketAddress> getRevealedLocalAddressSet(
+            SocketAddress[] saa)
+    {
+         SecurityManager sm = System.getSecurityManager();
+         Set<SocketAddress> set = new HashSet<>(saa.length);
+         for (SocketAddress sa : saa) {
+             set.add(getRevealedLocalAddress(sa, sm));
+         }
+         return set;
+    }
+
+    private static SocketAddress getRevealedLocalAddress(SocketAddress sa,
+                                                         SecurityManager sm)
+    {
+        if (sm == null || sa == null)
+            return sa;
+        InetSocketAddress ia = (InetSocketAddress)sa;
+        try{
+            sm.checkConnect(ia.getAddress().getHostAddress(), -1);
+            // Security check passed
+        } catch (SecurityException e) {
+            // Return loopback address
+            return new InetSocketAddress(InetAddress.getLoopbackAddress(),
+                                         ia.getPort());
+        }
+        return sa;
+    }
+
     static Set<SocketAddress> getRemoteAddresses(int fd, int assocId)
             throws IOException {
         HashSet<SocketAddress> set = null;