I am sorry to just drop this to the mailing list but here goes... Hopefully what I have done is useful for someone else too...
I have added (trivial) support for specifying the 'local' host to bind the socket to. This is useful (for example) when debugging traffic to an 'active' server which happens to use a fully wildcard listen. In this case if the tunnel listens on the active host-ip or localhost then all requests will go through the tunnel which can then forward them to the 'real' server (listen on host-ip:80 forward to localhost:80 is what I commonly do). If you needed to forward both localhost and host-ip at the same time you would need a 'back-door' or an alias-ip address to pass requests to the real server. Anyhow, here are the code changes as a context diff and the new source file. I did not put any entries in the properties file for the new strings (not really knowing what I should do there - I am sure someone else will). The diffs are against the version dated mid september from the axis 1.0 release, let me know if they do not take and I can send the original. David Cooper Wmode Inc. email: [EMAIL PROTECTED]
*** tcpmon.java Thu Oct 17 01:02:24 2002
--- tcpmon-src.java Thu Oct 17 09:05:56 2002
***************
*** 99,105 ****
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
- import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URL;
--- 99,104 ----
***************
*** 122,134 ****
private static int INHOST_COLUMN = 2 ;
private static int OUTHOST_COLUMN = 3 ;
private static int REQ_COLUMN = 4 ;
-
- static int backlog=50;
class AdminPage extends JPanel {
public JRadioButton listenerButton, proxyButton ;
public JLabel hostLabel, tportLabel;
! public JTextField port, lHost, host, tport ;
public JTabbedPane noteb ;
public JCheckBox HTTPProxyBox ;
public JTextField HTTPProxyHost, HTTPProxyPort ;
--- 121,131 ----
private static int INHOST_COLUMN = 2 ;
private static int OUTHOST_COLUMN = 3 ;
private static int REQ_COLUMN = 4 ;
class AdminPage extends JPanel {
public JRadioButton listenerButton, proxyButton ;
public JLabel hostLabel, tportLabel;
! public JTextField port, host, tport ;
public JTabbedPane noteb ;
public JCheckBox HTTPProxyBox ;
public JTextField HTTPProxyHost, HTTPProxyPort ;
***************
*** 165,178 ****
c.gridwidth = GridBagConstraints.REMAINDER ;
tmpPanel.add( port = new JTextField(4), c );
- c.anchor = GridBagConstraints.WEST ;
- c.gridwidth = 1 ;
- tmpPanel.add( new JLabel(getMessage("listenHost00", "Listen Host ") + "
"), c );
-
- c.anchor = GridBagConstraints.WEST ;
- c.gridwidth = GridBagConstraints.REMAINDER ;
- tmpPanel.add( lHost = new JTextField(30), c );
-
mainPane.add( tmpPanel, c );
mainPane.add( Box.createRigidArea(new Dimension(1, 5)), c );
--- 162,167 ----
***************
*** 352,358 ****
String text ;
Listener l = null ;
int lPort = Integer.parseInt(port.getText());
- String lhost = lHost.getText();
String tHost = host.getText();
int tPort = 0 ;
--- 341,346 ----
***************
*** 359,365 ****
text = tport.getText();
if ( text != null && !text.equals("") )
tPort = Integer.parseInt(text);
! l = new Listener( noteb, null, lPort, lhost, tHost,
tPort,
proxyButton.isSelected() );
// Pick-up the HTTP Proxy settings
--- 347,353 ----
text = tport.getText();
if ( text != null && !text.equals("") )
tPort = Integer.parseInt(text);
! l = new Listener( noteb, null, lPort, tHost, tPort,
proxyButton.isSelected() );
// Pick-up the HTTP Proxy settings
***************
*** 373,379 ****
l.HTTPProxyPort = Integer.parseInt(text);
port.setText(null);
- lHost.setText(null);
host.setText(null);
tport.setText(null);
}
--- 361,366 ----
***************
*** 392,426 ****
ServerSocket sSocket = null ;
Listener listener ;
int port ;
- String host ;
boolean pleaseStop = false ;
! public SocketWaiter(Listener l, int p, String h) {
listener = l ;
port = p ;
- if ( h.indexOf('*') >= 0 || h.length() <= 0 )
- { host = null; }
- else
- { host = h ; }
start();
}
public void run() {
- InetAddress bindAddr;
try {
listener.setLeft( new JLabel(getMessage("wait00", " Waiting for
Connection...") ) );
listener.repaint();
! if ( host == null )
! {
! // allow any host address
! sSocket = new ServerSocket( port, backlog );
! }
! else
! {
! // allow specific address
! bindAddr = InetAddress.getByName( host );
! sSocket = new ServerSocket( port, backlog, bindAddr );
! }
for (; ; ) {
Socket inSocket = sSocket.accept();
--- 379,397 ----
ServerSocket sSocket = null ;
Listener listener ;
int port ;
boolean pleaseStop = false ;
! public SocketWaiter(Listener l, int p) {
listener = l ;
port = p ;
start();
}
public void run() {
try {
listener.setLeft( new JLabel(getMessage("wait00", " Waiting for
Connection...") ) );
listener.repaint();
! sSocket = new ServerSocket( port );
for (; ; ) {
Socket inSocket = sSocket.accept();
***************
*** 444,466 ****
public void halt() {
try {
pleaseStop = true ;
! if (host != null)
! {
! try
! {
! InetAddress hostaddr;
! hostaddr = InetAddress.getByName( host );
! new Socket( hostaddr, port );
! }
! catch ( Exception c )
! {
! new Socket( InetAddress.getLocalHost(), port );
! }
! }
! else
! {
! new Socket( "127.0.0.1", port );
! }
if ( sSocket != null ) sSocket.close();
}
catch ( Exception e ) {
--- 415,421 ----
public void halt() {
try {
pleaseStop = true ;
! new Socket( "127.0.0.1", port );
if ( sSocket != null ) sSocket.close();
}
catch ( Exception e ) {
***************
*** 788,794 ****
listener.outPane.setVisible( true );
}
- String localHost = listener.LhostField.getText();
String targetHost = listener.hostField.getText();
int targetPort = Integer.parseInt(listener.tPortField.getText());
--- 743,748 ----
***************
*** 896,906 ****
// check to see if we have found Host: header
if (line.startsWith("Host: ")) {
// we need to update the hostname to target host
! String newHost = null;
! if (localHost.indexOf('*') >= 0)
! { newHost = "Host: " + targetHost + "\r\n"; }
! else
! { newHost = "Host: " + localHost + "\r\n"; }
bufferedData = bufferedData.concat(newHost);
break ;
--- 850,856 ----
// check to see if we have found Host: header
if (line.startsWith("Host: ")) {
// we need to update the hostname to target host
! String newHost = "Host: " + targetHost + "\r\n";
bufferedData = bufferedData.concat(newHost);
break ;
***************
*** 1054,1060 ****
public Socket inputSocket = null ;
public Socket outputSocket = null ;
public JTextField portField = null ;
- public JTextField LhostField = null ;
public JTextField hostField = null ;
public JTextField tPortField = null ;
public JCheckBox isProxyBox = null ;
--- 1004,1009 ----
***************
*** 1080,1086 ****
final public Vector connections = new Vector();
public Listener(JTabbedPane _notebook, String name,
! int listenPort, String lHost, String host, int targetPort,
boolean isProxy) {
notebook = _notebook ;
if ( name == null ) name = getMessage("port01", "Port") + " " +
listenPort ;
--- 1029,1035 ----
final public Vector connections = new Vector();
public Listener(JTabbedPane _notebook, String name,
! int listenPort, String host, int targetPort,
boolean isProxy) {
notebook = _notebook ;
if ( name == null ) name = getMessage("port01", "Port") + " " +
listenPort ;
***************
*** 1094,1107 ****
top.setLayout( new BoxLayout(top, BoxLayout.X_AXIS) );
top.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
final String start = getMessage("start00", "Start");
top.add( stopButton = new JButton( start ) );
top.add( Box.createRigidArea(new Dimension(5, 0)) );
top.add( new JLabel( " " + getMessage("listenPort01", "Listen Port:") +
" ", SwingConstants.RIGHT ) );
top.add( portField = new JTextField( "" + listenPort, 4 ) );
- top.add( new JLabel( " " + getMessage("listenHost01", "Listen Host:") +
" ", SwingConstants.RIGHT ) );
- top.add( LhostField = new JTextField( "" + lHost, 20 ) );
top.add( new JLabel( " " + getMessage("host00", "Host:"),
SwingConstants.RIGHT ) );
! top.add( hostField = new JTextField( host, 20 ) );
top.add( new JLabel( " " + getMessage("port02", "Port:") + " ",
SwingConstants.RIGHT ) );
top.add( tPortField = new JTextField( "" + targetPort, 4 ) );
top.add( Box.createRigidArea(new Dimension(5, 0)) );
--- 1043,1055 ----
top.setLayout( new BoxLayout(top, BoxLayout.X_AXIS) );
top.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
final String start = getMessage("start00", "Start");
+
top.add( stopButton = new JButton( start ) );
top.add( Box.createRigidArea(new Dimension(5, 0)) );
top.add( new JLabel( " " + getMessage("listenPort01", "Listen Port:") +
" ", SwingConstants.RIGHT ) );
top.add( portField = new JTextField( "" + listenPort, 4 ) );
top.add( new JLabel( " " + getMessage("host00", "Host:"),
SwingConstants.RIGHT ) );
! top.add( hostField = new JTextField( host, 30 ) );
top.add( new JLabel( " " + getMessage("port02", "Port:") + " ",
SwingConstants.RIGHT ) );
top.add( tPortField = new JTextField( "" + targetPort, 4 ) );
top.add( Box.createRigidArea(new Dimension(5, 0)) );
***************
*** 1112,1118 ****
JCheckBox box = (JCheckBox) event.getSource();
boolean state = box.isSelected();
- LhostField.setEnabled( !state );
tPortField.setEnabled( !state );
hostField.setEnabled( !state );
}
--- 1060,1065 ----
***************
*** 1123,1130 ****
portField.setEditable(false);
portField.setMaximumSize(new Dimension(50, Short.MAX_VALUE) );
- LhostField.setEditable(false);
- LhostField.setMaximumSize(new Dimension(85,Short.MAX_VALUE) );
hostField.setEditable(false);
hostField.setMaximumSize(new Dimension(85, Short.MAX_VALUE) );
tPortField.setEditable(false);
--- 1070,1075 ----
***************
*** 1377,1394 ****
notebook.setTitleAt( i, getMessage("port01", "Port") + " " + port );
int tmp = Integer.parseInt( tPortField.getText() );
tPortField.setText( "" + tmp );
! String host = LhostField.getText().trim();
! if ( host.indexOf('*') >= 0 || host.length() <= 0 )
! { host = "*"; }
! LhostField.setText(host);
!
! sw = new SocketWaiter( this, port, host );
stopButton.setText( getMessage("stop00", "Stop") );
portField.setEditable(false);
- LhostField.setEditable(false);
hostField.setEditable(false);
tPortField.setEditable(false);
isProxyBox.setEnabled(false);
--- 1322,1334 ----
notebook.setTitleAt( i, getMessage("port01", "Port") + " " + port );
int tmp = Integer.parseInt( tPortField.getText() );
+
tPortField.setText( "" + tmp );
! sw = new SocketWaiter( this, port );
stopButton.setText( getMessage("stop00", "Stop") );
portField.setEditable(false);
hostField.setEditable(false);
tPortField.setEditable(false);
isProxyBox.setEnabled(false);
***************
*** 1409,1415 ****
sw.halt();
stopButton.setText( getMessage("start00", "Start") );
portField.setEditable(true);
- LhostField.setEditable(true);
hostField.setEditable(true);
tPortField.setEditable(true);
isProxyBox.setEnabled(true);
--- 1349,1354 ----
***************
*** 1457,1463 ****
rc = Integer.parseInt( portField.getText() );
out.write( (new String(getMessage("listenPort01", "Listen
Port:") + " " + rc + "\n" )).getBytes() );
- out.write( (new String(getMessage("listenHost01", "Listen
Host:") + " " + LhostField.getText() + "\n" )).getBytes() );
out.write( (new String(getMessage("targetHost01", "Target
Host:") + " " + hostField.getText() +
"\n" )).getBytes() );
rc = Integer.parseInt( tPortField.getText() );
--- 1396,1401 ----
***************
*** 1553,1562 ****
Listener l = null ;
if ( targetHost == null )
! l = new Listener( notebook, null, listenPort, null,
targetHost, targetPort, true );
else
! l = new Listener( notebook, null, listenPort, null,
targetHost, targetPort, false );
notebook.setSelectedIndex( 1 );
--- 1491,1500 ----
Listener l = null ;
if ( targetHost == null )
! l = new Listener( notebook, null, listenPort,
targetHost, targetPort, true );
else
! l = new Listener( notebook, null, listenPort,
targetHost, targetPort, false );
notebook.setSelectedIndex( 1 );
tcpmon.java
Description: Binary data
