Rev 1197 | Rev 1201 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net;
using System.Text;
using System.Windows.Forms;
namespace TCPproxy
{
public class ListenForm : Form
{
private int listenPort;
private string resendHost;
private IPAddress resendIp;
private int resendPort;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
private Button startButton;
private Label label2;
private Label label1;
private TextBox resendPortBox;
private TextBox resendHostBox;
private TextBox listenPortBox;
private Button cancelButton;
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.startButton = new Button();
this.label2 = new Label();
this.label1 = new Label();
this.resendPortBox = new TextBox();
this.resendHostBox = new TextBox();
this.listenPortBox = new TextBox();
this.cancelButton = new Button();
this.SuspendLayout();
//
// startButton
//
this.startButton.Location = new System.Drawing.Point(136, 62);
this.startButton.Name = "startButton";
this.startButton.Size = new System.Drawing.Size(75, 23);
this.startButton.TabIndex = 12;
this.startButton.Text = "Listen";
this.startButton.Click += new System.EventHandler(this.startButton_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 35);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 13);
this.label2.TabIndex = 10;
this.label2.Text = "Resend to";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(71, 13);
this.label1.TabIndex = 7;
this.label1.Text = "Listen on port";
//
// resendPortBox
//
this.resendPortBox.Location = new System.Drawing.Point(220, 32);
this.resendPortBox.Name = "resendPortBox";
this.resendPortBox.Size = new System.Drawing.Size(72, 20);
this.resendPortBox.TabIndex = 9;
//
// resendHostBox
//
this.resendHostBox.Location = new System.Drawing.Point(114, 32);
this.resendHostBox.Name = "resendHostBox";
this.resendHostBox.Size = new System.Drawing.Size(100, 20);
this.resendHostBox.TabIndex = 8;
//
// listenPortBox
//
this.listenPortBox.Location = new System.Drawing.Point(114, 6);
this.listenPortBox.Name = "listenPortBox";
this.listenPortBox.Size = new System.Drawing.Size(100, 20);
this.listenPortBox.TabIndex = 6;
//
// cancelButton
//
this.cancelButton.DialogResult = DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(217, 62);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 13;
this.cancelButton.Text = "Cancel";
//
// ListenForm
//
this.AcceptButton = this.startButton;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(301, 91);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.startButton);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.resendPortBox);
this.Controls.Add(this.resendHostBox);
this.Controls.Add(this.listenPortBox);
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ListenForm";
this.ShowInTaskbar = false;
this.StartPosition = FormStartPosition.CenterParent;
this.Text = "TCPproxy - Start Listening";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public ListenForm()
{
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
public bool Execute(Form owner,
ref int listenPort, ref string resendHost, out IPAddress resendIp, ref int resendPort)
{
listenPortBox.Text = (listenPort == 0) ? "" : listenPort.ToString();
resendHostBox.Text = resendHost;
resendPortBox.Text = (resendPort == 0) ? "" : resendPort.ToString();
if(this.ShowDialog(owner) != DialogResult.OK) {
resendIp = null;
return false;
}
listenPort = this.listenPort;
resendHost = this.resendHost;
resendIp = this.resendIp;
resendPort = this.resendPort;
return true;
}
private void startButton_Click(object sender, EventArgs e)
{
// parse listen port
try
{
listenPort = int.Parse(listenPortBox.Text);
}
catch(FormatException)
{
MessageBox.Show("Listen port must be an integer number");
return;
}
// get resend host
try
{
resendIp = HostUtils.ResendHostToIp(resendHostBox.Text);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
resendHost = resendHostBox.Text;
// parse resend port
try
{
resendPort = int.Parse(resendPortBox.Text);
}
catch(FormatException)
{
MessageBox.Show("Resend port must be an integer number");
return;
}
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}