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