Skip to content

Commit

Permalink
Fix telnet bind address, fixes #611 (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet authored Oct 18, 2021
1 parent eac455e commit d774f6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
package org.jline.builtins.telnet;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
Expand All @@ -64,24 +65,27 @@ public class PortListener
private static final String logmsg =
"Listening to Port {0,number,integer} with a connectivity queue size of {1,number,integer}.";
private String name;
private int port; //port number running on
private int floodProtection; //flooding protection
private ServerSocket serverSocket = null; //server socket
private String ip; // ip address
private int port; // port number running on
private int floodProtection; // flooding protection
private ServerSocket serverSocket = null; // server socket
private Thread thread;
private ConnectionManager connectionManager; //connection management thread
private ConnectionManager connectionManager; // connection management thread
private boolean stopping = false;
private boolean available; //Flag for availability
private boolean available; // Flag for availability

/**
* Constructs a PortListener instance.<br>
*
* @param name the name
* @param ip the ip address to bind to
* @param port int that specifies the port number of the server socket.
* @param floodprot that specifies the server socket queue size.
*/
public PortListener(String name, int port, int floodprot) {
public PortListener(String name, String ip, int port, int floodprot) {
this.name = name;
available = false;
this.ip = ip;
this.port = port;
floodProtection = floodprot;
}//constructor
Expand Down Expand Up @@ -166,7 +170,7 @@ public void run() {
should be handled properly, but denial of service attacks via massive parallel
program logins should be prevented with this.
*/
serverSocket = new ServerSocket(port, floodProtection);
serverSocket = new ServerSocket(port, floodProtection, ip != null ? InetAddress.getByName(ip) : null);

//log entry
LOG.info(MessageFormat.format(logmsg, port, floodProtection));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected void doClose() throws Exception {
}
};
connectionManager.start();
portListener = new PortListener("gogo", port, 10);
portListener = new PortListener("gogo", ip, port, 10);
portListener.setConnectionManager(connectionManager);
portListener.start();
}
Expand Down

0 comments on commit d774f6f

Please sign in to comment.