Rev 1201 | 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 System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.resendPortBox = new System.Windows.Forms.TextBox();
this.resendHostBox = new System.Windows.Forms.TextBox();
this.listenPortBox = new System.Windows.Forms.TextBox();
this.cancelButton = new System.Windows.Forms.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 = 60;
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 = 30;
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 = 10;
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 = 50;
//
// 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 = 40;
//
// 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 = 20;
//
// cancelButton
//
this.cancelButton.DialogResult = System.Windows.Forms.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 = 70;
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 = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ListenForm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.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", "TCPproxy",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// get resend host
try
{
resendIp = HostUtils.ResendHostToIp(resendHostBox.Text);
}
catch(Exception ex)
{
MessageBox.Show("Cannot get host IP: " + ex.Message, "TCPproxy",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
resendHost = resendHostBox.Text;
// parse resend port
try
{
resendPort = int.Parse(resendPortBox.Text);
}
catch(FormatException)
{
MessageBox.Show("Resend port must be an integer number", "TCPproxy",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}