aboutsummaryrefslogtreecommitdiffstats
path: root/java/com/tigervnc/network/TcpSocket.java
diff options
context:
space:
mode:
authorBrian Hinz <bphinz@users.sourceforge.net>2012-04-05 03:37:50 +0000
committerBrian Hinz <bphinz@users.sourceforge.net>2012-04-05 03:37:50 +0000
commitcf0e312b59e1c0afb4996188afafc8835eec191d (patch)
tree4a644800acad93b144100955d380991efa3faf1e /java/com/tigervnc/network/TcpSocket.java
parentb3ea375488ddb5ca8f9e90f7be95a269571262ad (diff)
downloadtigervnc-cf0e312b59e1c0afb4996188afafc8835eec191d.tar.gz
tigervnc-cf0e312b59e1c0afb4996188afafc8835eec191d.zip
adds experimental support for SSH tunneling to the Java client. Has not been tested with large desktop sizes yet. CMakeLists.txt needs some rework.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4882 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'java/com/tigervnc/network/TcpSocket.java')
-rw-r--r--java/com/tigervnc/network/TcpSocket.java34
1 files changed, 14 insertions, 20 deletions
diff --git a/java/com/tigervnc/network/TcpSocket.java b/java/com/tigervnc/network/TcpSocket.java
index 9277dd14..1d127f50 100644
--- a/java/com/tigervnc/network/TcpSocket.java
+++ b/java/com/tigervnc/network/TcpSocket.java
@@ -171,29 +171,23 @@ public class TcpSocket extends Socket {
return ((InetSocketAddress)((SocketDescriptor)getFd()).socket().getRemoteSocketAddress()).getPort();
}
+ /* Tunnelling support. */
+ public static int findFreeTcpPort() {
+ java.net.ServerSocket sock;
+ int port;
+ try {
+ sock = new java.net.ServerSocket(0);
+ port = sock.getLocalPort();
+ sock.close();
+ } catch (java.io.IOException e) {
+ throw new SocketException("unable to create socket: "+e.toString());
+ }
+ return port;
+ }
+
private boolean closeFd;
static LogWriter vlog = new LogWriter("TcpSocket");
}
-/* Tunnelling support. */
-/*
-public int findFreeTcpPort() {
- int sock;
-
- if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- throw SocketException("unable to create socket", errorNumber);
-
- int port = 0;
- if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) < 0)
- throw SocketException("unable to find free port", errorNumber);
-
- socklen_t n = sizeof(addr);
- if (getsockname (sock, (struct sockaddr *)&addr, &n) < 0)
- throw SocketException("unable to get port number", errorNumber);
-
- closesocket(sock);
- return ntohs(addr.sin_port);
-}
-*/