Subversion Repositories general

Rev

Rev 1194 | Rev 1197 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1194 dev 1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Net;
7
using System.Text;
8
using System.Windows.Forms;
9
 
10
namespace TCPproxy
11
{
1196 dev 12
    public class ListenForm : Form
1194 dev 13
    {
14
		private int       listenPort;
15
		private string    resendHost;
16
		private IPAddress resendIp;
17
		private int       resendPort;
18
 
1196 dev 19
        /// <summary>
20
        /// Required designer variable.
21
        /// </summary>
22
        private System.ComponentModel.IContainer components = null;
23
        private System.Windows.Forms.Button startButton;
24
        private System.Windows.Forms.Label label2;
25
        private System.Windows.Forms.Label label1;
26
        private System.Windows.Forms.TextBox resendPortBox;
27
        private System.Windows.Forms.TextBox resendHostBox;
28
        private System.Windows.Forms.TextBox listenPortBox;
29
		private System.Windows.Forms.Button cancelButton;
30
 
31
        #region Windows Form Designer generated code
32
 
33
        /// <summary>
34
        /// Required method for Designer support - do not modify
35
        /// the contents of this method with the code editor.
36
        /// </summary>
37
        private void InitializeComponent()
38
        {
39
			this.startButton = new System.Windows.Forms.Button();
40
			this.label2 = new System.Windows.Forms.Label();
41
			this.label1 = new System.Windows.Forms.Label();
42
			this.resendPortBox = new System.Windows.Forms.TextBox();
43
			this.resendHostBox = new System.Windows.Forms.TextBox();
44
			this.listenPortBox = new System.Windows.Forms.TextBox();
45
			this.cancelButton = new System.Windows.Forms.Button();
46
			this.SuspendLayout();
47
			//
48
			// startButton
49
			//
50
			this.startButton.Location = new System.Drawing.Point(136, 62);
51
			this.startButton.Name = "startButton";
52
			this.startButton.Size = new System.Drawing.Size(75, 23);
53
			this.startButton.TabIndex = 12;
54
			this.startButton.Text = "Listen";
55
			this.startButton.Click += new System.EventHandler(this.startButton_Click);
56
			//
57
			// label2
58
			//
59
			this.label2.AutoSize = true;
60
			this.label2.Location = new System.Drawing.Point(12, 35);
61
			this.label2.Name = "label2";
62
			this.label2.Size = new System.Drawing.Size(56, 13);
63
			this.label2.TabIndex = 10;
64
			this.label2.Text = "Resend to";
65
			//
66
			// label1
67
			//
68
			this.label1.AutoSize = true;
69
			this.label1.Location = new System.Drawing.Point(12, 9);
70
			this.label1.Name = "label1";
71
			this.label1.Size = new System.Drawing.Size(71, 13);
72
			this.label1.TabIndex = 7;
73
			this.label1.Text = "Listen on port";
74
			//
75
			// resendPortBox
76
			//
77
			this.resendPortBox.Location = new System.Drawing.Point(220, 32);
78
			this.resendPortBox.Name = "resendPortBox";
79
			this.resendPortBox.Size = new System.Drawing.Size(72, 20);
80
			this.resendPortBox.TabIndex = 9;
81
			//
82
			// resendHostBox
83
			//
84
			this.resendHostBox.Location = new System.Drawing.Point(114, 32);
85
			this.resendHostBox.Name = "resendHostBox";
86
			this.resendHostBox.Size = new System.Drawing.Size(100, 20);
87
			this.resendHostBox.TabIndex = 8;
88
			//
89
			// listenPortBox
90
			//
91
			this.listenPortBox.Location = new System.Drawing.Point(114, 6);
92
			this.listenPortBox.Name = "listenPortBox";
93
			this.listenPortBox.Size = new System.Drawing.Size(100, 20);
94
			this.listenPortBox.TabIndex = 6;
95
			//
96
			// cancelButton
97
			//
98
			this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
99
			this.cancelButton.Location = new System.Drawing.Point(217, 62);
100
			this.cancelButton.Name = "cancelButton";
101
			this.cancelButton.Size = new System.Drawing.Size(75, 23);
102
			this.cancelButton.TabIndex = 13;
103
			this.cancelButton.Text = "Cancel";
104
			this.cancelButton.UseVisualStyleBackColor = true;
105
			//
106
			// ListenForm
107
			//
108
			this.AcceptButton = this.startButton;
109
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
110
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
111
			this.CancelButton = this.cancelButton;
112
			this.ClientSize = new System.Drawing.Size(301, 91);
113
			this.Controls.Add(this.cancelButton);
114
			this.Controls.Add(this.startButton);
115
			this.Controls.Add(this.label2);
116
			this.Controls.Add(this.label1);
117
			this.Controls.Add(this.resendPortBox);
118
			this.Controls.Add(this.resendHostBox);
119
			this.Controls.Add(this.listenPortBox);
120
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
121
			this.MaximizeBox = false;
122
			this.MinimizeBox = false;
123
			this.Name = "ListenForm";
124
			this.ShowIcon = false;
125
			this.ShowInTaskbar = false;
126
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
127
			this.Text = "TCPproxy - Start Listening";
128
			this.ResumeLayout(false);
129
			this.PerformLayout();
130
 
131
        }
132
 
133
        #endregion
134
 
1194 dev 135
        public ListenForm()
136
        {
137
            InitializeComponent();
138
        }
139
 
1196 dev 140
        protected override void Dispose(bool disposing)
141
        {
142
            if (disposing && (components != null))
143
            {
144
                components.Dispose();
145
            }
146
            base.Dispose(disposing);
147
        }
148
 
149
		public bool Execute(Form owner,
1194 dev 150
			ref int listenPort, ref string resendHost, out IPAddress resendIp, ref int resendPort)
151
		{
152
			listenPortBox.Text = (listenPort == 0) ? "" : listenPort.ToString();
153
			resendHostBox.Text = resendHost;
154
			resendPortBox.Text = (resendPort == 0) ? "" : resendPort.ToString();
155
 
156
			if(this.ShowDialog(owner) != DialogResult.OK) {
157
				resendIp = null;
158
				return false;
159
			}
160
 
161
			listenPort = this.listenPort;
162
			resendHost = this.resendHost;
163
			resendIp   = this.resendIp;
164
			resendPort = this.resendPort;
165
 
166
			return true;
167
		}
168
 
169
		private void startButton_Click(object sender, EventArgs e)
170
		{
171
			// parse listen port
172
			try
173
			{
174
				listenPort = int.Parse(listenPortBox.Text);
175
			}
176
			catch(FormatException)
177
			{
178
				MessageBox.Show("Listen port must be an integer number");
179
				return;
180
			}
181
 
182
			// get resend host
183
			try
184
			{
185
				resendIp = HostUtils.ResendHostToIp(resendHostBox.Text);
186
			}
187
			catch(Exception ex)
188
			{
189
				MessageBox.Show(ex.Message);
190
				return;
191
			}
192
			resendHost = resendHostBox.Text;
1196 dev 193
 
1194 dev 194
			// parse resend port
195
			try
196
			{
197
				resendPort = int.Parse(resendPortBox.Text);
198
			}
199
			catch(FormatException)
200
			{
201
				MessageBox.Show("Resend port must be an integer number");
202
				return;
203
			}
204
 
205
			this.DialogResult = DialogResult.OK;
206
			this.Close();
207
		}
208
    }
209
}