From d5147453f7337792ac59a20a3db25abf9c4adf19 Mon Sep 17 00:00:00 2001 From: "Brian P. Hinz" Date: Thu, 13 Nov 2014 21:30:27 -0500 Subject: [PATCH] Fix getSockPort methods in java TcpSocket Although not actually used anywhere, the getSockPort method was actually returning the the remote socket's port number. Also simplified some of the other socket methods. --- java/com/tigervnc/network/TcpListener.java | 6 +++--- java/com/tigervnc/network/TcpSocket.java | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/java/com/tigervnc/network/TcpListener.java b/java/com/tigervnc/network/TcpListener.java index 6170a602..45ee8a4d 100644 --- a/java/com/tigervnc/network/TcpListener.java +++ b/java/com/tigervnc/network/TcpListener.java @@ -144,9 +144,9 @@ public class TcpListener extends SocketListener { return s; } - //public int getMyPort() { - // return TcpSocket.getSockPort(); - //} + public int getMyPort() { + return ((SocketDescriptor)getFd()).socket().getLocalPort(); + } private boolean closeFd; private ServerSocketChannel channel; diff --git a/java/com/tigervnc/network/TcpSocket.java b/java/com/tigervnc/network/TcpSocket.java index 051a9d82..43787e4d 100644 --- a/java/com/tigervnc/network/TcpSocket.java +++ b/java/com/tigervnc/network/TcpSocket.java @@ -113,8 +113,7 @@ public class TcpSocket extends Socket { } public int getMyPort() { - SocketAddress address = ((SocketDescriptor)getFd()).socket().getLocalSocketAddress(); - return ((InetSocketAddress)address).getPort(); + return getSockPort(); } public String getPeerAddress() { @@ -184,7 +183,7 @@ public class TcpSocket extends Socket { } public int getSockPort() { - return ((InetSocketAddress)((SocketDescriptor)getFd()).socket().getRemoteSocketAddress()).getPort(); + return ((SocketDescriptor)getFd()).socket().getLocalPort(); } /* Tunnelling support. */ -- 2.39.5