jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java
changeset 18212 22f8c33b0690
parent 18192 fa6bd0992104
child 19607 bee007586d06
equal deleted inserted replaced
18211:74aeb4741e3d 18212:22f8c33b0690
    83     private static final int ST_CONNECTED = 1;
    83     private static final int ST_CONNECTED = 1;
    84     private static final int ST_KILLED = 2;
    84     private static final int ST_KILLED = 2;
    85     private int state = ST_UNINITIALIZED;
    85     private int state = ST_UNINITIALIZED;
    86 
    86 
    87     // Binding
    87     // Binding
    88     private SocketAddress localAddress;
    88     private InetSocketAddress localAddress;
    89     private SocketAddress remoteAddress;
    89     private InetSocketAddress remoteAddress;
    90 
    90 
    91     // Our socket adaptor, if any
    91     // Our socket adaptor, if any
    92     private DatagramSocket socket;
    92     private DatagramSocket socket;
    93 
    93 
    94     // Multicast support
    94     // Multicast support
   166     @Override
   166     @Override
   167     public SocketAddress getLocalAddress() throws IOException {
   167     public SocketAddress getLocalAddress() throws IOException {
   168         synchronized (stateLock) {
   168         synchronized (stateLock) {
   169             if (!isOpen())
   169             if (!isOpen())
   170                 throw new ClosedChannelException();
   170                 throw new ClosedChannelException();
   171             return localAddress;
   171             // Perform security check before returning address
       
   172             return Net.getRevealedLocalAddress(localAddress);
   172         }
   173         }
   173     }
   174     }
   174 
   175 
   175     @Override
   176     @Override
   176     public SocketAddress getRemoteAddress() throws IOException {
   177     public SocketAddress getRemoteAddress() throws IOException {
   719             if (state != ST_UNCONNECTED)
   720             if (state != ST_UNCONNECTED)
   720                 throw new IllegalStateException("Connect already invoked");
   721                 throw new IllegalStateException("Connect already invoked");
   721         }
   722         }
   722     }
   723     }
   723 
   724 
       
   725     @Override
   724     public DatagramChannel connect(SocketAddress sa) throws IOException {
   726     public DatagramChannel connect(SocketAddress sa) throws IOException {
   725         int localPort = 0;
   727         int localPort = 0;
   726 
   728 
   727         synchronized(readLock) {
   729         synchronized(readLock) {
   728             synchronized(writeLock) {
   730             synchronized(writeLock) {
   740                     if (n <= 0)
   742                     if (n <= 0)
   741                         throw new Error();      // Can't happen
   743                         throw new Error();      // Can't happen
   742 
   744 
   743                     // Connection succeeded; disallow further invocation
   745                     // Connection succeeded; disallow further invocation
   744                     state = ST_CONNECTED;
   746                     state = ST_CONNECTED;
   745                     remoteAddress = sa;
   747                     remoteAddress = isa;
   746                     sender = isa;
   748                     sender = isa;
   747                     cachedSenderInetAddress = isa.getAddress();
   749                     cachedSenderInetAddress = isa.getAddress();
   748                     cachedSenderPort = isa.getPort();
   750                     cachedSenderPort = isa.getPort();
   749 
   751 
   750                     // set or refresh local address
   752                     // set or refresh local address
   759         synchronized(readLock) {
   761         synchronized(readLock) {
   760             synchronized(writeLock) {
   762             synchronized(writeLock) {
   761                 synchronized (stateLock) {
   763                 synchronized (stateLock) {
   762                     if (!isConnected() || !isOpen())
   764                     if (!isConnected() || !isOpen())
   763                         return this;
   765                         return this;
   764                     InetSocketAddress isa = (InetSocketAddress)remoteAddress;
   766                     InetSocketAddress isa = remoteAddress;
   765                     SecurityManager sm = System.getSecurityManager();
   767                     SecurityManager sm = System.getSecurityManager();
   766                     if (sm != null)
   768                     if (sm != null)
   767                         sm.checkConnect(isa.getAddress().getHostAddress(),
   769                         sm.checkConnect(isa.getAddress().getHostAddress(),
   768                                         isa.getPort());
   770                                         isa.getPort());
   769                     boolean isIPv6 = (family == StandardProtocolFamily.INET6);
   771                     boolean isIPv6 = (family == StandardProtocolFamily.INET6);