Rev 1197 | Rev 1201 | 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.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 | { |
||
1200 | dev | 38 | this.startButton = new Button(); |
39 | this.label2 = new Label(); |
||
40 | this.label1 = new Label(); |
||
41 | this.resendPortBox = new TextBox(); |
||
42 | this.resendHostBox = new TextBox(); |
||
43 | this.listenPortBox = new TextBox(); |
||
44 | this.cancelButton = new Button(); |
||
1196 | dev | 45 | this.SuspendLayout(); |
46 | // |
||
47 | // startButton |
||
48 | // |
||
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); |
||
52 | this.startButton.TabIndex = 12; |
||
53 | this.startButton.Text = "Listen"; |
||
54 | this.startButton.Click += new System.EventHandler(this.startButton_Click); |
||
55 | // |
||
56 | // label2 |
||
57 | // |
||
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); |
||
62 | this.label2.TabIndex = 10; |
||
63 | this.label2.Text = "Resend to"; |
||
64 | // |
||
65 | // label1 |
||
66 | // |
||
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); |
||
71 | this.label1.TabIndex = 7; |
||
72 | this.label1.Text = "Listen on port"; |
||
73 | // |
||
74 | // resendPortBox |
||
75 | // |
||
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); |
||
79 | this.resendPortBox.TabIndex = 9; |
||
80 | // |
||
81 | // resendHostBox |
||
82 | // |
||
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); |
||
86 | this.resendHostBox.TabIndex = 8; |
||
87 | // |
||
88 | // listenPortBox |
||
89 | // |
||
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); |
||
93 | this.listenPortBox.TabIndex = 6; |
||
94 | // |
||
95 | // cancelButton |
||
96 | // |
||
1200 | dev | 97 | this.cancelButton.DialogResult = 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); |
||
101 | this.cancelButton.TabIndex = 13; |
||
102 | this.cancelButton.Text = "Cancel"; |
||
103 | // |
||
104 | // ListenForm |
||
105 | // |
||
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); |
||
1200 | dev | 116 | this.FormBorderStyle = FormBorderStyle.FixedDialog; |
1196 | dev | 117 | this.MaximizeBox = false; |
118 | this.MinimizeBox = false; |
||
119 | this.Name = "ListenForm"; |
||
120 | this.ShowInTaskbar = false; |
||
1200 | dev | 121 | this.StartPosition = FormStartPosition.CenterParent; |
1196 | dev | 122 | this.Text = "TCPproxy - Start Listening"; |
123 | this.ResumeLayout(false); |
||
124 | this.PerformLayout(); |
||
125 | } |
||
126 | |||
127 | #endregion |
||
128 | |||
1194 | dev | 129 | public ListenForm() |
130 | { |
||
131 | InitializeComponent(); |
||
132 | } |
||
133 | |||
1196 | dev | 134 | protected override void Dispose(bool disposing) |
135 | { |
||
136 | if (disposing && (components != null)) |
||
137 | { |
||
138 | components.Dispose(); |
||
139 | } |
||
140 | base.Dispose(disposing); |
||
141 | } |
||
142 | |||
143 | public bool Execute(Form owner, |
||
1194 | dev | 144 | ref int listenPort, ref string resendHost, out IPAddress resendIp, ref int resendPort) |
145 | { |
||
146 | listenPortBox.Text = (listenPort == 0) ? "" : listenPort.ToString(); |
||
147 | resendHostBox.Text = resendHost; |
||
148 | resendPortBox.Text = (resendPort == 0) ? "" : resendPort.ToString(); |
||
149 | |||
150 | if(this.ShowDialog(owner) != DialogResult.OK) { |
||
151 | resendIp = null; |
||
152 | return false; |
||
153 | } |
||
154 | |||
155 | listenPort = this.listenPort; |
||
156 | resendHost = this.resendHost; |
||
157 | resendIp = this.resendIp; |
||
158 | resendPort = this.resendPort; |
||
159 | |||
160 | return true; |
||
161 | } |
||
162 | |||
163 | private void startButton_Click(object sender, EventArgs e) |
||
164 | { |
||
165 | // parse listen port |
||
166 | try |
||
167 | { |
||
168 | listenPort = int.Parse(listenPortBox.Text); |
||
169 | } |
||
170 | catch(FormatException) |
||
171 | { |
||
172 | MessageBox.Show("Listen port must be an integer number"); |
||
173 | return; |
||
174 | } |
||
175 | |||
176 | // get resend host |
||
177 | try |
||
178 | { |
||
179 | resendIp = HostUtils.ResendHostToIp(resendHostBox.Text); |
||
180 | } |
||
181 | catch(Exception ex) |
||
182 | { |
||
183 | MessageBox.Show(ex.Message); |
||
184 | return; |
||
185 | } |
||
186 | resendHost = resendHostBox.Text; |
||
1196 | dev | 187 | |
1194 | dev | 188 | // parse resend port |
189 | try |
||
190 | { |
||
191 | resendPort = int.Parse(resendPortBox.Text); |
||
192 | } |
||
193 | catch(FormatException) |
||
194 | { |
||
195 | MessageBox.Show("Resend port must be an integer number"); |
||
196 | return; |
||
197 | } |
||
198 | |||
199 | this.DialogResult = DialogResult.OK; |
||
200 | this.Close(); |
||
201 | } |
||
202 | } |
||
203 | } |