Skip to content

Commit d774f6f

Browse files
authored
Fix telnet bind address, fixes #611 (#723)
1 parent eac455e commit d774f6f

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

remote-telnet/src/main/java/org/jline/builtins/telnet/PortListener.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
package org.jline.builtins.telnet;
4242

4343
import java.io.IOException;
44+
import java.net.InetAddress;
4445
import java.net.ServerSocket;
4546
import java.net.Socket;
4647
import java.net.SocketException;
@@ -64,24 +65,27 @@ public class PortListener
6465
private static final String logmsg =
6566
"Listening to Port {0,number,integer} with a connectivity queue size of {1,number,integer}.";
6667
private String name;
67-
private int port; //port number running on
68-
private int floodProtection; //flooding protection
69-
private ServerSocket serverSocket = null; //server socket
68+
private String ip; // ip address
69+
private int port; // port number running on
70+
private int floodProtection; // flooding protection
71+
private ServerSocket serverSocket = null; // server socket
7072
private Thread thread;
71-
private ConnectionManager connectionManager; //connection management thread
73+
private ConnectionManager connectionManager; // connection management thread
7274
private boolean stopping = false;
73-
private boolean available; //Flag for availability
75+
private boolean available; // Flag for availability
7476

7577
/**
7678
* Constructs a PortListener instance.<br>
7779
*
7880
* @param name the name
81+
* @param ip the ip address to bind to
7982
* @param port int that specifies the port number of the server socket.
8083
* @param floodprot that specifies the server socket queue size.
8184
*/
82-
public PortListener(String name, int port, int floodprot) {
85+
public PortListener(String name, String ip, int port, int floodprot) {
8386
this.name = name;
8487
available = false;
88+
this.ip = ip;
8589
this.port = port;
8690
floodProtection = floodprot;
8791
}//constructor
@@ -166,7 +170,7 @@ public void run() {
166170
should be handled properly, but denial of service attacks via massive parallel
167171
program logins should be prevented with this.
168172
*/
169-
serverSocket = new ServerSocket(port, floodProtection);
173+
serverSocket = new ServerSocket(port, floodProtection, ip != null ? InetAddress.getByName(ip) : null);
170174

171175
//log entry
172176
LOG.info(MessageFormat.format(logmsg, port, floodProtection));

remote-telnet/src/main/java/org/jline/builtins/telnet/Telnet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ protected void doClose() throws Exception {
164164
}
165165
};
166166
connectionManager.start();
167-
portListener = new PortListener("gogo", port, 10);
167+
portListener = new PortListener("gogo", ip, port, 10);
168168
portListener.setConnectionManager(connectionManager);
169169
portListener.start();
170170
}

0 commit comments

Comments
 (0)