4141package org .jline .builtins .telnet ;
4242
4343import java .io .IOException ;
44+ import java .net .InetAddress ;
4445import java .net .ServerSocket ;
4546import java .net .Socket ;
4647import 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 ));
0 commit comments