diff options
Diffstat (limited to 'x11vnc/inet.c')
-rw-r--r-- | x11vnc/inet.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/x11vnc/inet.c b/x11vnc/inet.c index 12f4fee..6a3921b 100644 --- a/x11vnc/inet.c +++ b/x11vnc/inet.c @@ -16,6 +16,7 @@ int get_local_port(int sock); char *get_remote_host(int sock); char *get_local_host(int sock); char *ident_username(rfbClientPtr client); +int find_free_port(int start, int end); static int get_port(int sock, int remote); @@ -295,4 +296,21 @@ char *ident_username(rfbClientPtr client) { return str; } +int find_free_port(int start, int end) { + int port; + if (start <= 0) { + start = 1024; + } + if (end <= 0) { + end = 65530; + } + for (port = start; port <= end; port++) { + int sock = rfbListenOnTCPPort(port, htonl(INADDR_ANY)); + if (sock >= 0) { + close(sock); + return port; + } + } + return 0; +} |