├── .gitattributes
├── LICENSE
├── MarsNATRP.sln
├── MarsNATRP_Client
├── MarsNATRP_Client.vbproj
├── MarsNATRP_Client.vbproj.user
├── My Project
│ └── PublishProfiles
│ │ ├── ClientLinux64.pubxml
│ │ ├── ClientLinux64.pubxml.user
│ │ ├── ClientMac64.pubxml
│ │ ├── ClientMac64.pubxml.user
│ │ ├── ClientPortable.pubxml
│ │ ├── ClientPortable.pubxml.user
│ │ ├── ClientWin64.pubxml
│ │ ├── ClientWin64.pubxml.user
│ │ ├── ClientWin86.pubxml
│ │ └── ClientWin86.pubxml.user
├── NATRP_ClientCore
│ ├── Core.vb
│ ├── MarsNATRPConnection.vb
│ └── SocketUtils.vb
├── Program.vb
└── obj
│ ├── MarsNATRP_Client.vbproj.nuget.cache
│ ├── MarsNATRP_Client.vbproj.nuget.g.props
│ ├── MarsNATRP_Client.vbproj.nuget.g.targets
│ └── project.assets.json
├── MarsNATRP_Server
├── Core
│ ├── MarsNATRPServerConnection.cs
│ ├── MarsNATRPServerCore.cs
│ └── SocketUtils.cs
├── MarsNATRP_Server.csproj
├── MarsNATRP_Server.csproj.user
├── Program.cs
├── Properties
│ └── PublishProfiles
│ │ ├── ServerLinux64.pubxml
│ │ ├── ServerLinux64.pubxml.user
│ │ ├── ServerPortable.pubxml
│ │ ├── ServerPortable.pubxml.user
│ │ ├── ServerWin64.pubxml
│ │ └── ServerWin64.pubxml.user
└── obj
│ ├── MarsNATRP_Server.csproj.nuget.cache
│ ├── MarsNATRP_Server.csproj.nuget.g.props
│ ├── MarsNATRP_Server.csproj.nuget.g.targets
│ └── project.assets.json
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 | *.json linguist-language=C#
4 | *.targets linguist-language=C#
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Mozilla Public License Version 2.0
2 | ==================================
3 |
4 | 1. Definitions
5 | --------------
6 |
7 | 1.1. "Contributor"
8 | means each individual or legal entity that creates, contributes to
9 | the creation of, or owns Covered Software.
10 |
11 | 1.2. "Contributor Version"
12 | means the combination of the Contributions of others (if any) used
13 | by a Contributor and that particular Contributor's Contribution.
14 |
15 | 1.3. "Contribution"
16 | means Covered Software of a particular Contributor.
17 |
18 | 1.4. "Covered Software"
19 | means Source Code Form to which the initial Contributor has attached
20 | the notice in Exhibit A, the Executable Form of such Source Code
21 | Form, and Modifications of such Source Code Form, in each case
22 | including portions thereof.
23 |
24 | 1.5. "Incompatible With Secondary Licenses"
25 | means
26 |
27 | (a) that the initial Contributor has attached the notice described
28 | in Exhibit B to the Covered Software; or
29 |
30 | (b) that the Covered Software was made available under the terms of
31 | version 1.1 or earlier of the License, but not also under the
32 | terms of a Secondary License.
33 |
34 | 1.6. "Executable Form"
35 | means any form of the work other than Source Code Form.
36 |
37 | 1.7. "Larger Work"
38 | means a work that combines Covered Software with other material, in
39 | a separate file or files, that is not Covered Software.
40 |
41 | 1.8. "License"
42 | means this document.
43 |
44 | 1.9. "Licensable"
45 | means having the right to grant, to the maximum extent possible,
46 | whether at the time of the initial grant or subsequently, any and
47 | all of the rights conveyed by this License.
48 |
49 | 1.10. "Modifications"
50 | means any of the following:
51 |
52 | (a) any file in Source Code Form that results from an addition to,
53 | deletion from, or modification of the contents of Covered
54 | Software; or
55 |
56 | (b) any new file in Source Code Form that contains any Covered
57 | Software.
58 |
59 | 1.11. "Patent Claims" of a Contributor
60 | means any patent claim(s), including without limitation, method,
61 | process, and apparatus claims, in any patent Licensable by such
62 | Contributor that would be infringed, but for the grant of the
63 | License, by the making, using, selling, offering for sale, having
64 | made, import, or transfer of either its Contributions or its
65 | Contributor Version.
66 |
67 | 1.12. "Secondary License"
68 | means either the GNU General Public License, Version 2.0, the GNU
69 | Lesser General Public License, Version 2.1, the GNU Affero General
70 | Public License, Version 3.0, or any later versions of those
71 | licenses.
72 |
73 | 1.13. "Source Code Form"
74 | means the form of the work preferred for making modifications.
75 |
76 | 1.14. "You" (or "Your")
77 | means an individual or a legal entity exercising rights under this
78 | License. For legal entities, "You" includes any entity that
79 | controls, is controlled by, or is under common control with You. For
80 | purposes of this definition, "control" means (a) the power, direct
81 | or indirect, to cause the direction or management of such entity,
82 | whether by contract or otherwise, or (b) ownership of more than
83 | fifty percent (50%) of the outstanding shares or beneficial
84 | ownership of such entity.
85 |
86 | 2. License Grants and Conditions
87 | --------------------------------
88 |
89 | 2.1. Grants
90 |
91 | Each Contributor hereby grants You a world-wide, royalty-free,
92 | non-exclusive license:
93 |
94 | (a) under intellectual property rights (other than patent or trademark)
95 | Licensable by such Contributor to use, reproduce, make available,
96 | modify, display, perform, distribute, and otherwise exploit its
97 | Contributions, either on an unmodified basis, with Modifications, or
98 | as part of a Larger Work; and
99 |
100 | (b) under Patent Claims of such Contributor to make, use, sell, offer
101 | for sale, have made, import, and otherwise transfer either its
102 | Contributions or its Contributor Version.
103 |
104 | 2.2. Effective Date
105 |
106 | The licenses granted in Section 2.1 with respect to any Contribution
107 | become effective for each Contribution on the date the Contributor first
108 | distributes such Contribution.
109 |
110 | 2.3. Limitations on Grant Scope
111 |
112 | The licenses granted in this Section 2 are the only rights granted under
113 | this License. No additional rights or licenses will be implied from the
114 | distribution or licensing of Covered Software under this License.
115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a
116 | Contributor:
117 |
118 | (a) for any code that a Contributor has removed from Covered Software;
119 | or
120 |
121 | (b) for infringements caused by: (i) Your and any other third party's
122 | modifications of Covered Software, or (ii) the combination of its
123 | Contributions with other software (except as part of its Contributor
124 | Version); or
125 |
126 | (c) under Patent Claims infringed by Covered Software in the absence of
127 | its Contributions.
128 |
129 | This License does not grant any rights in the trademarks, service marks,
130 | or logos of any Contributor (except as may be necessary to comply with
131 | the notice requirements in Section 3.4).
132 |
133 | 2.4. Subsequent Licenses
134 |
135 | No Contributor makes additional grants as a result of Your choice to
136 | distribute the Covered Software under a subsequent version of this
137 | License (see Section 10.2) or under the terms of a Secondary License (if
138 | permitted under the terms of Section 3.3).
139 |
140 | 2.5. Representation
141 |
142 | Each Contributor represents that the Contributor believes its
143 | Contributions are its original creation(s) or it has sufficient rights
144 | to grant the rights to its Contributions conveyed by this License.
145 |
146 | 2.6. Fair Use
147 |
148 | This License is not intended to limit any rights You have under
149 | applicable copyright doctrines of fair use, fair dealing, or other
150 | equivalents.
151 |
152 | 2.7. Conditions
153 |
154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155 | in Section 2.1.
156 |
157 | 3. Responsibilities
158 | -------------------
159 |
160 | 3.1. Distribution of Source Form
161 |
162 | All distribution of Covered Software in Source Code Form, including any
163 | Modifications that You create or to which You contribute, must be under
164 | the terms of this License. You must inform recipients that the Source
165 | Code Form of the Covered Software is governed by the terms of this
166 | License, and how they can obtain a copy of this License. You may not
167 | attempt to alter or restrict the recipients' rights in the Source Code
168 | Form.
169 |
170 | 3.2. Distribution of Executable Form
171 |
172 | If You distribute Covered Software in Executable Form then:
173 |
174 | (a) such Covered Software must also be made available in Source Code
175 | Form, as described in Section 3.1, and You must inform recipients of
176 | the Executable Form how they can obtain a copy of such Source Code
177 | Form by reasonable means in a timely manner, at a charge no more
178 | than the cost of distribution to the recipient; and
179 |
180 | (b) You may distribute such Executable Form under the terms of this
181 | License, or sublicense it under different terms, provided that the
182 | license for the Executable Form does not attempt to limit or alter
183 | the recipients' rights in the Source Code Form under this License.
184 |
185 | 3.3. Distribution of a Larger Work
186 |
187 | You may create and distribute a Larger Work under terms of Your choice,
188 | provided that You also comply with the requirements of this License for
189 | the Covered Software. If the Larger Work is a combination of Covered
190 | Software with a work governed by one or more Secondary Licenses, and the
191 | Covered Software is not Incompatible With Secondary Licenses, this
192 | License permits You to additionally distribute such Covered Software
193 | under the terms of such Secondary License(s), so that the recipient of
194 | the Larger Work may, at their option, further distribute the Covered
195 | Software under the terms of either this License or such Secondary
196 | License(s).
197 |
198 | 3.4. Notices
199 |
200 | You may not remove or alter the substance of any license notices
201 | (including copyright notices, patent notices, disclaimers of warranty,
202 | or limitations of liability) contained within the Source Code Form of
203 | the Covered Software, except that You may alter any license notices to
204 | the extent required to remedy known factual inaccuracies.
205 |
206 | 3.5. Application of Additional Terms
207 |
208 | You may choose to offer, and to charge a fee for, warranty, support,
209 | indemnity or liability obligations to one or more recipients of Covered
210 | Software. However, You may do so only on Your own behalf, and not on
211 | behalf of any Contributor. You must make it absolutely clear that any
212 | such warranty, support, indemnity, or liability obligation is offered by
213 | You alone, and You hereby agree to indemnify every Contributor for any
214 | liability incurred by such Contributor as a result of warranty, support,
215 | indemnity or liability terms You offer. You may include additional
216 | disclaimers of warranty and limitations of liability specific to any
217 | jurisdiction.
218 |
219 | 4. Inability to Comply Due to Statute or Regulation
220 | ---------------------------------------------------
221 |
222 | If it is impossible for You to comply with any of the terms of this
223 | License with respect to some or all of the Covered Software due to
224 | statute, judicial order, or regulation then You must: (a) comply with
225 | the terms of this License to the maximum extent possible; and (b)
226 | describe the limitations and the code they affect. Such description must
227 | be placed in a text file included with all distributions of the Covered
228 | Software under this License. Except to the extent prohibited by statute
229 | or regulation, such description must be sufficiently detailed for a
230 | recipient of ordinary skill to be able to understand it.
231 |
232 | 5. Termination
233 | --------------
234 |
235 | 5.1. The rights granted under this License will terminate automatically
236 | if You fail to comply with any of its terms. However, if You become
237 | compliant, then the rights granted under this License from a particular
238 | Contributor are reinstated (a) provisionally, unless and until such
239 | Contributor explicitly and finally terminates Your grants, and (b) on an
240 | ongoing basis, if such Contributor fails to notify You of the
241 | non-compliance by some reasonable means prior to 60 days after You have
242 | come back into compliance. Moreover, Your grants from a particular
243 | Contributor are reinstated on an ongoing basis if such Contributor
244 | notifies You of the non-compliance by some reasonable means, this is the
245 | first time You have received notice of non-compliance with this License
246 | from such Contributor, and You become compliant prior to 30 days after
247 | Your receipt of the notice.
248 |
249 | 5.2. If You initiate litigation against any entity by asserting a patent
250 | infringement claim (excluding declaratory judgment actions,
251 | counter-claims, and cross-claims) alleging that a Contributor Version
252 | directly or indirectly infringes any patent, then the rights granted to
253 | You by any and all Contributors for the Covered Software under Section
254 | 2.1 of this License shall terminate.
255 |
256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257 | end user license agreements (excluding distributors and resellers) which
258 | have been validly granted by You or Your distributors under this License
259 | prior to termination shall survive termination.
260 |
261 | ************************************************************************
262 | * *
263 | * 6. Disclaimer of Warranty *
264 | * ------------------------- *
265 | * *
266 | * Covered Software is provided under this License on an "as is" *
267 | * basis, without warranty of any kind, either expressed, implied, or *
268 | * statutory, including, without limitation, warranties that the *
269 | * Covered Software is free of defects, merchantable, fit for a *
270 | * particular purpose or non-infringing. The entire risk as to the *
271 | * quality and performance of the Covered Software is with You. *
272 | * Should any Covered Software prove defective in any respect, You *
273 | * (not any Contributor) assume the cost of any necessary servicing, *
274 | * repair, or correction. This disclaimer of warranty constitutes an *
275 | * essential part of this License. No use of any Covered Software is *
276 | * authorized under this License except under this disclaimer. *
277 | * *
278 | ************************************************************************
279 |
280 | ************************************************************************
281 | * *
282 | * 7. Limitation of Liability *
283 | * -------------------------- *
284 | * *
285 | * Under no circumstances and under no legal theory, whether tort *
286 | * (including negligence), contract, or otherwise, shall any *
287 | * Contributor, or anyone who distributes Covered Software as *
288 | * permitted above, be liable to You for any direct, indirect, *
289 | * special, incidental, or consequential damages of any character *
290 | * including, without limitation, damages for lost profits, loss of *
291 | * goodwill, work stoppage, computer failure or malfunction, or any *
292 | * and all other commercial damages or losses, even if such party *
293 | * shall have been informed of the possibility of such damages. This *
294 | * limitation of liability shall not apply to liability for death or *
295 | * personal injury resulting from such party's negligence to the *
296 | * extent applicable law prohibits such limitation. Some *
297 | * jurisdictions do not allow the exclusion or limitation of *
298 | * incidental or consequential damages, so this exclusion and *
299 | * limitation may not apply to You. *
300 | * *
301 | ************************************************************************
302 |
303 | 8. Litigation
304 | -------------
305 |
306 | Any litigation relating to this License may be brought only in the
307 | courts of a jurisdiction where the defendant maintains its principal
308 | place of business and such litigation shall be governed by laws of that
309 | jurisdiction, without reference to its conflict-of-law provisions.
310 | Nothing in this Section shall prevent a party's ability to bring
311 | cross-claims or counter-claims.
312 |
313 | 9. Miscellaneous
314 | ----------------
315 |
316 | This License represents the complete agreement concerning the subject
317 | matter hereof. If any provision of this License is held to be
318 | unenforceable, such provision shall be reformed only to the extent
319 | necessary to make it enforceable. Any law or regulation which provides
320 | that the language of a contract shall be construed against the drafter
321 | shall not be used to construe this License against a Contributor.
322 |
323 | 10. Versions of the License
324 | ---------------------------
325 |
326 | 10.1. New Versions
327 |
328 | Mozilla Foundation is the license steward. Except as provided in Section
329 | 10.3, no one other than the license steward has the right to modify or
330 | publish new versions of this License. Each version will be given a
331 | distinguishing version number.
332 |
333 | 10.2. Effect of New Versions
334 |
335 | You may distribute the Covered Software under the terms of the version
336 | of the License under which You originally received the Covered Software,
337 | or under the terms of any subsequent version published by the license
338 | steward.
339 |
340 | 10.3. Modified Versions
341 |
342 | If you create software not governed by this License, and you want to
343 | create a new license for such software, you may create and use a
344 | modified version of this License if you rename the license and remove
345 | any references to the name of the license steward (except to note that
346 | such modified license differs from this License).
347 |
348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary
349 | Licenses
350 |
351 | If You choose to distribute Source Code Form that is Incompatible With
352 | Secondary Licenses under the terms of this version of the License, the
353 | notice described in Exhibit B of this License must be attached.
354 |
355 | Exhibit A - Source Code Form License Notice
356 | -------------------------------------------
357 |
358 | This Source Code Form is subject to the terms of the Mozilla Public
359 | License, v. 2.0. If a copy of the MPL was not distributed with this
360 | file, You can obtain one at http://mozilla.org/MPL/2.0/.
361 |
362 | If it is not possible or desirable to put the notice in a particular
363 | file, then You may include the notice in a location (such as a LICENSE
364 | file in a relevant directory) where a recipient would be likely to look
365 | for such a notice.
366 |
367 | You may add additional accurate notices of copyright ownership.
368 |
369 | Exhibit B - "Incompatible With Secondary Licenses" Notice
370 | ---------------------------------------------------------
371 |
372 | This Source Code Form is "Incompatible With Secondary Licenses", as
373 | defined by the Mozilla Public License, v. 2.0.
374 |
--------------------------------------------------------------------------------
/MarsNATRP.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.28010.2026
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "MarsNATRP_Client", "MarsNATRP_Client\MarsNATRP_Client.vbproj", "{84595133-2DD4-4C62-AEEB-387A88A20056}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MarsNATRP_Server", "MarsNATRP_Server\MarsNATRP_Server.csproj", "{6F47D3A9-39B6-4913-A7F4-DF51677046CB}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {84595133-2DD4-4C62-AEEB-387A88A20056}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {84595133-2DD4-4C62-AEEB-387A88A20056}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {84595133-2DD4-4C62-AEEB-387A88A20056}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {84595133-2DD4-4C62-AEEB-387A88A20056}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {6F47D3A9-39B6-4913-A7F4-DF51677046CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {6F47D3A9-39B6-4913-A7F4-DF51677046CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {6F47D3A9-39B6-4913-A7F4-DF51677046CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {6F47D3A9-39B6-4913-A7F4-DF51677046CB}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {260E20EB-154A-43E1-ADCE-0DFB0B75C73C}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/MarsNATRP_Client.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | MarsNATRP_Client
6 | netcoreapp2.1
7 | 1.0.1
8 | SmartGhost
9 | GhostFamilyStudio
10 | false
11 | 2018 GhostFamilyStudio all rights reserved.
12 | http://ghofamily.sctstu.com
13 |
14 |
15 |
16 | 1
17 |
18 |
19 |
20 | 1
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/MarsNATRP_Client.vbproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | <_LastSelectedProfileId>C:\Users\Administrator\Desktop\Temporary Projects\MarsNATRP\MarsNATRP_Client\My Project\PublishProfiles\ClientLinux64.pubxml
5 |
6 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/My Project/PublishProfiles/ClientLinux64.pubxml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | FileSystem
8 | Release
9 | Any CPU
10 | netcoreapp2.1
11 | Release\Linux64\
12 | linux-x64
13 | true
14 | <_IsPortable>false
15 |
16 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/My Project/PublishProfiles/ClientLinux64.pubxml.user:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/My Project/PublishProfiles/ClientMac64.pubxml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | FileSystem
8 | Release
9 | Any CPU
10 | netcoreapp2.1
11 | Release\Mac64
12 | osx-x64
13 | true
14 | <_IsPortable>false
15 |
16 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/My Project/PublishProfiles/ClientMac64.pubxml.user:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/My Project/PublishProfiles/ClientPortable.pubxml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | FileSystem
8 | Release
9 | Any CPU
10 | netcoreapp2.1
11 | Release\Portable\
12 | false
13 | <_IsPortable>true
14 |
15 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/My Project/PublishProfiles/ClientPortable.pubxml.user:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/My Project/PublishProfiles/ClientWin64.pubxml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | FileSystem
8 | Release
9 | Any CPU
10 | netcoreapp2.1
11 | Release\Win64\
12 | win-x64
13 | true
14 | <_IsPortable>false
15 |
16 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/My Project/PublishProfiles/ClientWin64.pubxml.user:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/My Project/PublishProfiles/ClientWin86.pubxml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | FileSystem
8 | Release
9 | Any CPU
10 | netcoreapp2.1
11 | Release\Win86\
12 | win-x86
13 | true
14 | <_IsPortable>false
15 |
16 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/My Project/PublishProfiles/ClientWin86.pubxml.user:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/NATRP_ClientCore/Core.vb:
--------------------------------------------------------------------------------
1 | ' Mozilla Public License Version 2.0
2 | ' =================
3 | '
4 | ' 1. Definitions
5 | ' --------------
6 | '
7 | ' 1.1. "Contributor"
8 | ' means each individual or legal entity that creates, contributes to
9 | ' the creation of, or owns Covered Software.
10 | '
11 | ' 1.2. "Contributor Version"
12 | ' means the combination of the Contributions of others (if any) used
13 | ' by a Contributor and that particular Contributor's Contribution.
14 | '
15 | ' 1.3. "Contribution"
16 | ' means Covered Software of a particular Contributor.
17 | '
18 | ' 1.4. "Covered Software"
19 | ' means Source Code Form to which the initial Contributor has attached
20 | ' the notice in Exhibit A, the Executable Form of such Source Code
21 | ' Form, and Modifications of such Source Code Form, in each case
22 | ' including portions thereof.
23 | '
24 | ' 1.5. "Incompatible With Secondary Licenses"
25 | ' means
26 | '
27 | ' (a) that the initial Contributor has attached the notice described
28 | ' in Exhibit B to the Covered Software or
29 | '
30 | ' (b) that the Covered Software was made available under the terms of
31 | ' version 1.1 or earlier of the License, but not also under the
32 | ' terms of a Secondary License.
33 | '
34 | ' 1.6. "Executable Form"
35 | ' means any form of the work other than Source Code Form.
36 | '
37 | ' 1.7. "Larger Work"
38 | ' means a work that combines Covered Software with other material, in
39 | ' a separate file or files, that is not Covered Software.
40 | '
41 | ' 1.8. "License"
42 | ' means Me document.
43 | '
44 | ' 1.9. "Licensable"
45 | ' means having the right to grant, to the maximum extent possible,
46 | ' whether at the time of the initial grant or subsequently, any and
47 | ' all of the rights conveyed by Me License.
48 | '
49 | ' 1.10. "Modifications"
50 | ' means any of the following:
51 | '
52 | ' (a) any file in Source Code Form that results from an addition to,
53 | ' deletion from, or modification of the contents of Covered
54 | ' Software or
55 | '
56 | ' (b) any New file in Source Code Form that contains any Covered
57 | ' Software.
58 | '
59 | ' 1.11. "Patent Claims" of a Contributor
60 | ' means any patent claim(s), including without limitation, method,
61 | ' process, and apparatus claims, in any patent Licensable by such
62 | ' Contributor that would be infringed, but for the grant of the
63 | ' License, by the making, using, selling, offering for sale, having
64 | ' made, import, or transfer of either its Contributions or its
65 | ' Contributor Version.
66 | '
67 | ' 1.12. "Secondary License"
68 | ' means either the GNU General Public License, Version 2.0, the GNU
69 | ' Lesser General Public License, Version 2.1, the GNU Affero General
70 | ' Public License, Version 3.0, or any later versions of those
71 | ' licenses.
72 | '
73 | ' 1.13. "Source Code Form"
74 | ' means the form of the work preferred for making modifications.
75 | '
76 | ' 1.14. "You" (or "Your")
77 | ' means an individual or a legal entity exercising rights under Me
78 | ' License. For legal entities, "You" includes any entity that
79 | ' controls, is controlled by, or is under common control with You. For
80 | ' purposes of Me definition, "control" means (a) the power, direct
81 | ' or indirect, to cause the direction or management of such entity,
82 | ' whether by contract or otherwise, or (b) ownership of more than
83 | ' fifty percent (50%) of the outstanding shares or beneficial
84 | ' ownership of such entity.
85 | '
86 | ' 2. License Grants and Conditions
87 | ' --------------------------------
88 | '
89 | ' 2.1. Grants
90 | '
91 | ' Each Contributor hereby grants You a world-wide, royalty-free,
92 | ' non-exclusive license:
93 | '
94 | ' (a) under intellectual property rights (other than patent or trademark)
95 | ' Licensable by such Contributor to use, reproduce, make available,
96 | ' modify, display, perform, distribute, and otherwise exploit its
97 | ' Contributions, either on an unmodified basis, with Modifications, or
98 | ' as part of a Larger Work and
99 | '
100 | ' (b) under Patent Claims of such Contributor to make, use, sell, offer
101 | ' for sale, have made, import, and otherwise transfer either its
102 | ' Contributions or its Contributor Version.
103 | '
104 | ' 2.2. Effective Date
105 | '
106 | ' The licenses granted in Section 2.1 with respect to any Contribution
107 | ' become effective for each Contribution on the date the Contributor first
108 | ' distributes such Contribution.
109 | '
110 | ' 2.3. Limitations on Grant Scope
111 | '
112 | ' The licenses granted in Me Section 2 are the only rights granted under
113 | ' Me License. No additional rights or licenses will be implied from the
114 | ' distribution or licensing of Covered Software under Me License.
115 | ' Notwithstanding Section 2.1(b) above, no patent license is granted by a
116 | ' Contributor:
117 | '
118 | ' CType(for any code that a Contributor has removed from Covered Software, a)
119 | ' or
120 | '
121 | ' (b) for infringements caused by: (i) Your and any other third party's
122 | ' modifications of Covered Software, or (ii) the combination of its
123 | ' Contributions with other software (except as part of its Contributor
124 | ' Version) or
125 | '
126 | ' (c) under Patent Claims infringed by Covered Software in the absence of
127 | ' its Contributions.
128 | '
129 | ' This License does not grant any rights in the trademarks, service marks,
130 | ' or logos of any Contributor (except as may be necessary to comply with
131 | ' the notice requirements in Section 3.4).
132 | '
133 | ' 2.4. Subsequent Licenses
134 | '
135 | ' No Contributor makes additional grants as a result of Your choice to
136 | ' distribute the Covered Software under a subsequent version of Me
137 | ' License (see Section 10.2) or under the terms of a Secondary License (if
138 | ' permitted under the terms of Section 3.3).
139 | '
140 | ' 2.5. Representation
141 | '
142 | ' Each Contributor represents that the Contributor believes its
143 | ' Contributions are its original creation(s) or it has sufficient rights
144 | ' to grant the rights to its Contributions conveyed by Me License.
145 | '
146 | ' 2.6. Fair Use
147 | '
148 | ' This License is not intended to limit any rights You have under
149 | ' applicable copyright doctrines of fair use, fair dealing, or other
150 | ' equivalents.
151 | '
152 | ' 2.7. Conditions
153 | '
154 | ' Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155 | ' in Section 2.1.
156 | '
157 | ' 3. Responsibilities
158 | ' -------------------
159 | '
160 | ' 3.1. Distribution of Source Form
161 | '
162 | ' All distribution of Covered Software in Source Code Form, including any
163 | ' Modifications that You create or to which You contribute, must be under
164 | ' the terms of Me License. You must inform recipients that the Source
165 | ' Code Form of the Covered Software is governed by the terms of Me
166 | ' License, and how they can obtain a copy of Me License. You may not
167 | ' attempt to alter or restrict the recipients' rights in the Source Code
168 | ' Form.
169 | '
170 | ' 3.2. Distribution of Executable Form
171 | '
172 | ' If You distribute Covered Software in Executable Form then:
173 | '
174 | ' (a) such Covered Software must also be made available in Source Code
175 | ' Form, as described in Section 3.1, and You must inform recipients of
176 | ' the Executable Form how they can obtain a copy of such Source Code
177 | ' Form by reasonable means in a timely manner, at a charge no more
178 | ' than the cost of distribution to the recipient and
179 | '
180 | ' (b) You may distribute such Executable Form under the terms of Me
181 | ' License, or sublicense it under different terms, provided that the
182 | ' license for the Executable Form does not attempt to limit or alter
183 | ' the recipients' rights in the Source Code Form under Me License.
184 | '
185 | ' 3.3. Distribution of a Larger Work
186 | '
187 | ' You may create and distribute a Larger Work under terms of Your choice,
188 | ' provided that You also comply with the requirements of Me License for
189 | ' the Covered Software. If the Larger Work is a combination of Covered
190 | ' Software with a work governed by one or more Secondary Licenses, and the
191 | ' Covered Software is not Incompatible With Secondary Licenses, Me
192 | ' License permits You to additionally distribute such Covered Software
193 | ' under the terms of such Secondary License(s), so that the recipient of
194 | ' the Larger Work may, at their option, further distribute the Covered
195 | ' Software under the terms of either Me License or such Secondary
196 | ' License(s).
197 | '
198 | ' 3.4. Notices
199 | '
200 | ' You may not remove or alter the substance of any license notices
201 | ' (including copyright notices, patent notices, disclaimers of warranty,
202 | ' or limitations of liability) contained within the Source Code Form of
203 | ' the Covered Software, except that You may alter any license notices to
204 | ' the extent required to remedy known factual inaccuracies.
205 | '
206 | ' 3.5. Application of Additional Terms
207 | '
208 | ' You may choose to offer, and to charge a fee for, warranty, support,
209 | ' indemnity or liability obligations to one or more recipients of Covered
210 | ' Software. However, You may do so only on Your own behalf, and not on
211 | ' behalf of any Contributor. You must make it absolutely clear that any
212 | ' such warranty, support, indemnity, or liability obligation is offered by
213 | ' You alone, and You hereby agree to indemnify every Contributor for any
214 | ' liability incurred by such Contributor as a result of warranty, support,
215 | ' indemnity or liability terms You offer. You may include additional
216 | ' disclaimers of warranty and limitations of liability specific to any
217 | ' jurisdiction.
218 | '
219 | ' 4. Inability to Comply Due to Statute or Regulation
220 | ' ---------------------------------------------------
221 | '
222 | ' If it is impossible for You to comply with any of the terms of Me
223 | ' License with respect to some or all of the Covered Software due to
224 | ' statute, judicial order, or regulation then You must: (a) comply with
225 | ' the terms of Me License to the maximum extent possible and (b)
226 | ' describe the limitations and the code they affect. Such description must
227 | ' be placed in a text file included with all distributions of the Covered
228 | ' Software under Me License. Except to the extent prohibited by statute
229 | ' or regulation, such description must be sufficiently detailed for a
230 | ' recipient of ordinary skill to be able to understand it.
231 | '
232 | ' 5. Termination
233 | ' --------------
234 | '
235 | ' 5.1. The rights granted under Me License will terminate automatically
236 | ' if You fail to comply with any of its terms. However, if You become
237 | ' compliant, then the rights granted under Me License from a particular
238 | ' Contributor are reinstated (a) provisionally, unless and until such
239 | ' Contributor explicitly and Finally terminates Your grants, and (b) on an
240 | ' ongoing basis, if such Contributor fails to notify You of the
241 | ' non-compliance by some reasonable means prior to 60 days after You have
242 | ' come back into compliance. Moreover, Your grants from a particular
243 | ' Contributor are reinstated on an ongoing basis if such Contributor
244 | ' notifies You of the non-compliance by some reasonable means, Me is the
245 | ' first time You have received notice of non-compliance with Me License
246 | ' from such Contributor, and You become compliant prior to 30 days after
247 | ' Your receipt of the notice.
248 | '
249 | ' 5.2. If You initiate litigation against any entity by asserting a patent
250 | ' infringement claim (excluding declaratory judgment actions,
251 | ' counter-claims, and cross-claims) alleging that a Contributor Version
252 | ' directly or indirectly infringes any patent, then the rights granted to
253 | ' You by any and all Contributors for the Covered Software under Section
254 | ' 2.1 of Me License shall terminate.
255 | '
256 | ' 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257 | ' end user license agreements (excluding distributors and resellers) which
258 | ' have been validly granted by You or Your distributors under Me License
259 | ' prior to termination shall survive termination.
260 | '
261 | ' ************************************************************************
262 | ' * *
263 | ' * 6. Disclaimer of Warranty *
264 | ' * ------------------------- *
265 | ' * *
266 | ' * Covered Software is provided under Me License on an "as is" *
267 | ' * basis, without warranty of any kind, either expressed, implied, or *
268 | ' * statutory, including, without limitation, warranties that the *
269 | ' * Covered Software is free of defects, merchantable, fit for a *
270 | ' * particular purpose or non-infringing. The entire risk as to the *
271 | ' * quality and performance of the Covered Software is with You. *
272 | ' * Should any Covered Software prove defective in any respect, You *
273 | ' * (not any Contributor) assume the cost of any necessary servicing, *
274 | ' * repair, or correction. This disclaimer of warranty constitutes an *
275 | ' * essential part of Me License. No use of any Covered Software is *
276 | ' * authorized under Me License except under Me disclaimer. *
277 | ' * *
278 | ' ************************************************************************
279 | '
280 | ' ************************************************************************
281 | ' * *
282 | ' * 7. Limitation of Liability *
283 | ' * -------------------------- *
284 | ' * *
285 | ' * Under no circumstances and under no legal theory, whether tort *
286 | ' * (including negligence), contract, or otherwise, shall any *
287 | ' * Contributor, or anyone who distributes Covered Software as *
288 | ' * permitted above, be liable to You for any direct, indirect, *
289 | ' * special, incidental, or consequential damages of any character *
290 | ' * including, without limitation, damages for lost profits, loss of *
291 | ' * goodwill, work stoppage, computer failure or malfunction, or any *
292 | ' * and all other commercial damages or losses, even if such party *
293 | ' * shall have been informed of the possibility of such damages. This *
294 | ' * limitation of liability shall not apply to liability for death or *
295 | ' * personal injury resulting from such party's negligence to the *
296 | ' * extent applicable law prohibits such limitation. Some *
297 | ' * jurisdictions do not allow the exclusion or limitation of *
298 | ' * incidental or consequential damages, so Me exclusion and *
299 | ' * limitation may not apply to You. *
300 | ' * *
301 | ' ************************************************************************
302 | '
303 | ' 8. Litigation
304 | ' -------------
305 | '
306 | ' Any litigation relating to Me License may be brought only in the
307 | ' courts of a jurisdiction where the defendant maintains its principal
308 | ' place of business and such litigation shall be governed by laws of that
309 | ' jurisdiction, without reference to its conflict-of-law provisions.
310 | ' Nothing in Me Section shall prevent a party's ability to bring
311 | ' cross-claims or counter-claims.
312 | '
313 | ' 9. Miscellaneous
314 | ' ----------------
315 | '
316 | ' This License represents the complete agreement concerning the subject
317 | ' matter hereof. If any provision of Me License is held to be
318 | ' unenforceable, such provision shall be reformed only to the extent
319 | ' necessary to make it enforceable. Any law or regulation which provides
320 | ' that the language of a contract shall be consTrued against the drafter
321 | ' shall not be used to consTrue Me License against a Contributor.
322 | '
323 | ' 10. Versions of the License
324 | ' ---------------------------
325 | '
326 | ' 10.1. New Versions
327 | '
328 | ' Mozilla Foundation is the license steward. Except as provided in Section
329 | ' 10.3, no one other than the license steward has the right to modify or
330 | ' publish New versions of Me License. Each version will be given a
331 | ' distinguishing version number.
332 | '
333 | ' 10.2. Effect of New Versions
334 | '
335 | ' You may distribute the Covered Software under the terms of the version
336 | ' of the License under which You originally received the Covered Software,
337 | ' or under the terms of any subsequent version published by the license
338 | ' steward.
339 | '
340 | ' 10.3. Modified Versions
341 | '
342 | ' If you create software not governed by Me License, and you want to
343 | ' create a New license for such software, you may create and use a
344 | ' modified version of Me License if you rename the license and remove
345 | ' any references to the name of the license steward (except to note that
346 | ' such modified license differs from Me License).
347 | '
348 | ' 10.4. Distributing Source Code Form that is Incompatible With Secondary
349 | ' Licenses
350 | '
351 | ' If You choose to distribute Source Code Form that is Incompatible With
352 | ' Secondary Licenses under the terms of Me version of the License, the
353 | ' notice described in Exhibit B of Me License must be attached.
354 | '
355 | ' Exhibit A - Source Code Form License Notice
356 | ' -------------------------------------------
357 | '
358 | ' This Source Code Form is subject to the terms of the Mozilla Public
359 | ' License, v. 2.0. If a copy of the MPL was not distributed with Me
360 | ' file, You can obtain one at http:'mozilla.org/MPL/2.0/.
361 | '
362 | ' If it is not possible or desirable to put the notice in a particular
363 | ' file, then You may include the notice in a location (such as a LICENSE
364 | ' file in a relevant directory) where a recipient would be likely to look
365 | ' for such a notice.
366 | '
367 | ' You may add additional accurate notices of copyright ownership.
368 | '
369 | ' Exhibit B - "Incompatible With Secondary Licenses" Notice
370 | ' ---------------------------------------------------------
371 | '
372 | ' This Source Code Form is "Incompatible With Secondary Licenses", as
373 | ' defined by the Mozilla Public License, v. 2.0.
374 |
375 | Imports System.IO
376 | Imports System.Net
377 | Imports System.Net.Sockets
378 | Imports System.Threading
379 |
380 | Public Class Core
381 | Public Property Sip As String
382 | Public Property Sport As UShort
383 | Public Property Tip As String
384 | Public Property Tport As UShort
385 | Public Property Myipendpoint As IPEndPoint
386 | Public Property LogWatcher As TextWriter
387 |
388 | Public Sub New(sip As String, sport As UShort, tip As String, tport As UShort)
389 | Me.sip = sip
390 | Me.sport = sport
391 | Me.tip = tip
392 | Me.tport = tport
393 | End Sub
394 | Friend Sub WriteLineLog(ByVal message As String)
395 | If Me.LogWatcher IsNot Nothing Then Me.LogWatcher.WriteLine(message)
396 | End Sub
397 |
398 | Private _TcpClient As TcpClient
399 | Friend Property IsStarting As Boolean = False
400 |
401 | Public Sub StartClient()
402 | If Not Me.IsStarting Then
403 | Try
404 | myipendpoint = New IPEndPoint(IPAddress.Parse(sip), sport)
405 | Dim workthread As New Thread(AddressOf work)
406 | workthread.Start(_TcpClient)
407 | Me.IsStarting = True
408 | Me.WriteLineLog(String.Format("MarsNATRP_Client has started at {0}....", DateTime.Now))
409 | Catch ex As Exception
410 | Console.WriteLine(ex.Message)
411 | System.Environment.Exit(0)
412 | End Try
413 | End If
414 | End Sub
415 |
416 | Private Sub Work(mytcp As TcpClient)
417 | If (Me.IsStarting) Then
418 | mytcp = New TcpClient()
419 | Try
420 | mytcp.Connect(Myipendpoint)
421 | Catch ex As Exception
422 | If (DirectCast(ex, System.Net.Sockets.SocketException).ErrorCode <> 10061) Then
423 | WriteLineLog("An error occurred : " & ex.Message)
424 | End If
425 | End Try
426 | If (mytcp.Connected) Then
427 | WriteLineLog(String.Format("MarsNATRP_Server allow to connect at {0}.", DateTime.Now))
428 | MarsNATRP_Client.MarsNATRPConnection.Create(Me, mytcp, Me.Tip, Me.Tport)
429 | End If
430 | Dim workthread As New Thread(AddressOf Work)
431 | workthread.Start(mytcp)
432 | End If
433 | End Sub
434 |
435 | Public Sub StopClient()
436 | If Me.IsStarting Then
437 | Me.IsStarting = False
438 | Me._TcpClient.Dispose()
439 | Me._TcpClient = Nothing
440 | Me.WriteLineLog(String.Format("Service closed at {0}.", DateTime.Now))
441 | End If
442 | End Sub
443 | End Class
444 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/NATRP_ClientCore/MarsNATRPConnection.vb:
--------------------------------------------------------------------------------
1 | ' Mozilla Public License Version 2.0
2 | ' =================
3 | '
4 | ' 1. Definitions
5 | ' --------------
6 | '
7 | ' 1.1. "Contributor"
8 | ' means each individual or legal entity that creates, contributes to
9 | ' the creation of, or owns Covered Software.
10 | '
11 | ' 1.2. "Contributor Version"
12 | ' means the combination of the Contributions of others (if any) used
13 | ' by a Contributor and that particular Contributor's Contribution.
14 | '
15 | ' 1.3. "Contribution"
16 | ' means Covered Software of a particular Contributor.
17 | '
18 | ' 1.4. "Covered Software"
19 | ' means Source Code Form to which the initial Contributor has attached
20 | ' the notice in Exhibit A, the Executable Form of such Source Code
21 | ' Form, and Modifications of such Source Code Form, in each case
22 | ' including portions thereof.
23 | '
24 | ' 1.5. "Incompatible With Secondary Licenses"
25 | ' means
26 | '
27 | ' (a) that the initial Contributor has attached the notice described
28 | ' in Exhibit B to the Covered Software or
29 | '
30 | ' (b) that the Covered Software was made available under the terms of
31 | ' version 1.1 or earlier of the License, but not also under the
32 | ' terms of a Secondary License.
33 | '
34 | ' 1.6. "Executable Form"
35 | ' means any form of the work other than Source Code Form.
36 | '
37 | ' 1.7. "Larger Work"
38 | ' means a work that combines Covered Software with other material, in
39 | ' a separate file or files, that is not Covered Software.
40 | '
41 | ' 1.8. "License"
42 | ' means Me document.
43 | '
44 | ' 1.9. "Licensable"
45 | ' means having the right to grant, to the maximum extent possible,
46 | ' whether at the time of the initial grant or subsequently, any and
47 | ' all of the rights conveyed by Me License.
48 | '
49 | ' 1.10. "Modifications"
50 | ' means any of the following:
51 | '
52 | ' (a) any file in Source Code Form that results from an addition to,
53 | ' deletion from, or modification of the contents of Covered
54 | ' Software or
55 | '
56 | ' (b) any New file in Source Code Form that contains any Covered
57 | ' Software.
58 | '
59 | ' 1.11. "Patent Claims" of a Contributor
60 | ' means any patent claim(s), including without limitation, method,
61 | ' process, and apparatus claims, in any patent Licensable by such
62 | ' Contributor that would be infringed, but for the grant of the
63 | ' License, by the making, using, selling, offering for sale, having
64 | ' made, import, or transfer of either its Contributions or its
65 | ' Contributor Version.
66 | '
67 | ' 1.12. "Secondary License"
68 | ' means either the GNU General Public License, Version 2.0, the GNU
69 | ' Lesser General Public License, Version 2.1, the GNU Affero General
70 | ' Public License, Version 3.0, or any later versions of those
71 | ' licenses.
72 | '
73 | ' 1.13. "Source Code Form"
74 | ' means the form of the work preferred for making modifications.
75 | '
76 | ' 1.14. "You" (or "Your")
77 | ' means an individual or a legal entity exercising rights under Me
78 | ' License. For legal entities, "You" includes any entity that
79 | ' controls, is controlled by, or is under common control with You. For
80 | ' purposes of Me definition, "control" means (a) the power, direct
81 | ' or indirect, to cause the direction or management of such entity,
82 | ' whether by contract or otherwise, or (b) ownership of more than
83 | ' fifty percent (50%) of the outstanding shares or beneficial
84 | ' ownership of such entity.
85 | '
86 | ' 2. License Grants and Conditions
87 | ' --------------------------------
88 | '
89 | ' 2.1. Grants
90 | '
91 | ' Each Contributor hereby grants You a world-wide, royalty-free,
92 | ' non-exclusive license:
93 | '
94 | ' (a) under intellectual property rights (other than patent or trademark)
95 | ' Licensable by such Contributor to use, reproduce, make available,
96 | ' modify, display, perform, distribute, and otherwise exploit its
97 | ' Contributions, either on an unmodified basis, with Modifications, or
98 | ' as part of a Larger Work and
99 | '
100 | ' (b) under Patent Claims of such Contributor to make, use, sell, offer
101 | ' for sale, have made, import, and otherwise transfer either its
102 | ' Contributions or its Contributor Version.
103 | '
104 | ' 2.2. Effective Date
105 | '
106 | ' The licenses granted in Section 2.1 with respect to any Contribution
107 | ' become effective for each Contribution on the date the Contributor first
108 | ' distributes such Contribution.
109 | '
110 | ' 2.3. Limitations on Grant Scope
111 | '
112 | ' The licenses granted in Me Section 2 are the only rights granted under
113 | ' Me License. No additional rights or licenses will be implied from the
114 | ' distribution or licensing of Covered Software under Me License.
115 | ' Notwithstanding Section 2.1(b) above, no patent license is granted by a
116 | ' Contributor:
117 | '
118 | ' CType(for any code that a Contributor has removed from Covered Software, a)
119 | ' or
120 | '
121 | ' (b) for infringements caused by: (i) Your and any other third party's
122 | ' modifications of Covered Software, or (ii) the combination of its
123 | ' Contributions with other software (except as part of its Contributor
124 | ' Version) or
125 | '
126 | ' (c) under Patent Claims infringed by Covered Software in the absence of
127 | ' its Contributions.
128 | '
129 | ' This License does not grant any rights in the trademarks, service marks,
130 | ' or logos of any Contributor (except as may be necessary to comply with
131 | ' the notice requirements in Section 3.4).
132 | '
133 | ' 2.4. Subsequent Licenses
134 | '
135 | ' No Contributor makes additional grants as a result of Your choice to
136 | ' distribute the Covered Software under a subsequent version of Me
137 | ' License (see Section 10.2) or under the terms of a Secondary License (if
138 | ' permitted under the terms of Section 3.3).
139 | '
140 | ' 2.5. Representation
141 | '
142 | ' Each Contributor represents that the Contributor believes its
143 | ' Contributions are its original creation(s) or it has sufficient rights
144 | ' to grant the rights to its Contributions conveyed by Me License.
145 | '
146 | ' 2.6. Fair Use
147 | '
148 | ' This License is not intended to limit any rights You have under
149 | ' applicable copyright doctrines of fair use, fair dealing, or other
150 | ' equivalents.
151 | '
152 | ' 2.7. Conditions
153 | '
154 | ' Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155 | ' in Section 2.1.
156 | '
157 | ' 3. Responsibilities
158 | ' -------------------
159 | '
160 | ' 3.1. Distribution of Source Form
161 | '
162 | ' All distribution of Covered Software in Source Code Form, including any
163 | ' Modifications that You create or to which You contribute, must be under
164 | ' the terms of Me License. You must inform recipients that the Source
165 | ' Code Form of the Covered Software is governed by the terms of Me
166 | ' License, and how they can obtain a copy of Me License. You may not
167 | ' attempt to alter or restrict the recipients' rights in the Source Code
168 | ' Form.
169 | '
170 | ' 3.2. Distribution of Executable Form
171 | '
172 | ' If You distribute Covered Software in Executable Form then:
173 | '
174 | ' (a) such Covered Software must also be made available in Source Code
175 | ' Form, as described in Section 3.1, and You must inform recipients of
176 | ' the Executable Form how they can obtain a copy of such Source Code
177 | ' Form by reasonable means in a timely manner, at a charge no more
178 | ' than the cost of distribution to the recipient and
179 | '
180 | ' (b) You may distribute such Executable Form under the terms of Me
181 | ' License, or sublicense it under different terms, provided that the
182 | ' license for the Executable Form does not attempt to limit or alter
183 | ' the recipients' rights in the Source Code Form under Me License.
184 | '
185 | ' 3.3. Distribution of a Larger Work
186 | '
187 | ' You may create and distribute a Larger Work under terms of Your choice,
188 | ' provided that You also comply with the requirements of Me License for
189 | ' the Covered Software. If the Larger Work is a combination of Covered
190 | ' Software with a work governed by one or more Secondary Licenses, and the
191 | ' Covered Software is not Incompatible With Secondary Licenses, Me
192 | ' License permits You to additionally distribute such Covered Software
193 | ' under the terms of such Secondary License(s), so that the recipient of
194 | ' the Larger Work may, at their option, further distribute the Covered
195 | ' Software under the terms of either Me License or such Secondary
196 | ' License(s).
197 | '
198 | ' 3.4. Notices
199 | '
200 | ' You may not remove or alter the substance of any license notices
201 | ' (including copyright notices, patent notices, disclaimers of warranty,
202 | ' or limitations of liability) contained within the Source Code Form of
203 | ' the Covered Software, except that You may alter any license notices to
204 | ' the extent required to remedy known factual inaccuracies.
205 | '
206 | ' 3.5. Application of Additional Terms
207 | '
208 | ' You may choose to offer, and to charge a fee for, warranty, support,
209 | ' indemnity or liability obligations to one or more recipients of Covered
210 | ' Software. However, You may do so only on Your own behalf, and not on
211 | ' behalf of any Contributor. You must make it absolutely clear that any
212 | ' such warranty, support, indemnity, or liability obligation is offered by
213 | ' You alone, and You hereby agree to indemnify every Contributor for any
214 | ' liability incurred by such Contributor as a result of warranty, support,
215 | ' indemnity or liability terms You offer. You may include additional
216 | ' disclaimers of warranty and limitations of liability specific to any
217 | ' jurisdiction.
218 | '
219 | ' 4. Inability to Comply Due to Statute or Regulation
220 | ' ---------------------------------------------------
221 | '
222 | ' If it is impossible for You to comply with any of the terms of Me
223 | ' License with respect to some or all of the Covered Software due to
224 | ' statute, judicial order, or regulation then You must: (a) comply with
225 | ' the terms of Me License to the maximum extent possible and (b)
226 | ' describe the limitations and the code they affect. Such description must
227 | ' be placed in a text file included with all distributions of the Covered
228 | ' Software under Me License. Except to the extent prohibited by statute
229 | ' or regulation, such description must be sufficiently detailed for a
230 | ' recipient of ordinary skill to be able to understand it.
231 | '
232 | ' 5. Termination
233 | ' --------------
234 | '
235 | ' 5.1. The rights granted under Me License will terminate automatically
236 | ' if You fail to comply with any of its terms. However, if You become
237 | ' compliant, then the rights granted under Me License from a particular
238 | ' Contributor are reinstated (a) provisionally, unless and until such
239 | ' Contributor explicitly and Finally terminates Your grants, and (b) on an
240 | ' ongoing basis, if such Contributor fails to notify You of the
241 | ' non-compliance by some reasonable means prior to 60 days after You have
242 | ' come back into compliance. Moreover, Your grants from a particular
243 | ' Contributor are reinstated on an ongoing basis if such Contributor
244 | ' notifies You of the non-compliance by some reasonable means, Me is the
245 | ' first time You have received notice of non-compliance with Me License
246 | ' from such Contributor, and You become compliant prior to 30 days after
247 | ' Your receipt of the notice.
248 | '
249 | ' 5.2. If You initiate litigation against any entity by asserting a patent
250 | ' infringement claim (excluding declaratory judgment actions,
251 | ' counter-claims, and cross-claims) alleging that a Contributor Version
252 | ' directly or indirectly infringes any patent, then the rights granted to
253 | ' You by any and all Contributors for the Covered Software under Section
254 | ' 2.1 of Me License shall terminate.
255 | '
256 | ' 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257 | ' end user license agreements (excluding distributors and resellers) which
258 | ' have been validly granted by You or Your distributors under Me License
259 | ' prior to termination shall survive termination.
260 | '
261 | ' ************************************************************************
262 | ' * *
263 | ' * 6. Disclaimer of Warranty *
264 | ' * ------------------------- *
265 | ' * *
266 | ' * Covered Software is provided under Me License on an "as is" *
267 | ' * basis, without warranty of any kind, either expressed, implied, or *
268 | ' * statutory, including, without limitation, warranties that the *
269 | ' * Covered Software is free of defects, merchantable, fit for a *
270 | ' * particular purpose or non-infringing. The entire risk as to the *
271 | ' * quality and performance of the Covered Software is with You. *
272 | ' * Should any Covered Software prove defective in any respect, You *
273 | ' * (not any Contributor) assume the cost of any necessary servicing, *
274 | ' * repair, or correction. This disclaimer of warranty constitutes an *
275 | ' * essential part of Me License. No use of any Covered Software is *
276 | ' * authorized under Me License except under Me disclaimer. *
277 | ' * *
278 | ' ************************************************************************
279 | '
280 | ' ************************************************************************
281 | ' * *
282 | ' * 7. Limitation of Liability *
283 | ' * -------------------------- *
284 | ' * *
285 | ' * Under no circumstances and under no legal theory, whether tort *
286 | ' * (including negligence), contract, or otherwise, shall any *
287 | ' * Contributor, or anyone who distributes Covered Software as *
288 | ' * permitted above, be liable to You for any direct, indirect, *
289 | ' * special, incidental, or consequential damages of any character *
290 | ' * including, without limitation, damages for lost profits, loss of *
291 | ' * goodwill, work stoppage, computer failure or malfunction, or any *
292 | ' * and all other commercial damages or losses, even if such party *
293 | ' * shall have been informed of the possibility of such damages. This *
294 | ' * limitation of liability shall not apply to liability for death or *
295 | ' * personal injury resulting from such party's negligence to the *
296 | ' * extent applicable law prohibits such limitation. Some *
297 | ' * jurisdictions do not allow the exclusion or limitation of *
298 | ' * incidental or consequential damages, so Me exclusion and *
299 | ' * limitation may not apply to You. *
300 | ' * *
301 | ' ************************************************************************
302 | '
303 | ' 8. Litigation
304 | ' -------------
305 | '
306 | ' Any litigation relating to Me License may be brought only in the
307 | ' courts of a jurisdiction where the defendant maintains its principal
308 | ' place of business and such litigation shall be governed by laws of that
309 | ' jurisdiction, without reference to its conflict-of-law provisions.
310 | ' Nothing in Me Section shall prevent a party's ability to bring
311 | ' cross-claims or counter-claims.
312 | '
313 | ' 9. Miscellaneous
314 | ' ----------------
315 | '
316 | ' This License represents the complete agreement concerning the subject
317 | ' matter hereof. If any provision of Me License is held to be
318 | ' unenforceable, such provision shall be reformed only to the extent
319 | ' necessary to make it enforceable. Any law or regulation which provides
320 | ' that the language of a contract shall be consTrued against the drafter
321 | ' shall not be used to consTrue Me License against a Contributor.
322 | '
323 | ' 10. Versions of the License
324 | ' ---------------------------
325 | '
326 | ' 10.1. New Versions
327 | '
328 | ' Mozilla Foundation is the license steward. Except as provided in Section
329 | ' 10.3, no one other than the license steward has the right to modify or
330 | ' publish New versions of Me License. Each version will be given a
331 | ' distinguishing version number.
332 | '
333 | ' 10.2. Effect of New Versions
334 | '
335 | ' You may distribute the Covered Software under the terms of the version
336 | ' of the License under which You originally received the Covered Software,
337 | ' or under the terms of any subsequent version published by the license
338 | ' steward.
339 | '
340 | ' 10.3. Modified Versions
341 | '
342 | ' If you create software not governed by Me License, and you want to
343 | ' create a New license for such software, you may create and use a
344 | ' modified version of Me License if you rename the license and remove
345 | ' any references to the name of the license steward (except to note that
346 | ' such modified license differs from Me License).
347 | '
348 | ' 10.4. Distributing Source Code Form that is Incompatible With Secondary
349 | ' Licenses
350 | '
351 | ' If You choose to distribute Source Code Form that is Incompatible With
352 | ' Secondary Licenses under the terms of Me version of the License, the
353 | ' notice described in Exhibit B of Me License must be attached.
354 | '
355 | ' Exhibit A - Source Code Form License Notice
356 | ' -------------------------------------------
357 | '
358 | ' This Source Code Form is subject to the terms of the Mozilla Public
359 | ' License, v. 2.0. If a copy of the MPL was not distributed with Me
360 | ' file, You can obtain one at http:'mozilla.org/MPL/2.0/.
361 | '
362 | ' If it is not possible or desirable to put the notice in a particular
363 | ' file, then You may include the notice in a location (such as a LICENSE
364 | ' file in a relevant directory) where a recipient would be likely to look
365 | ' for such a notice.
366 | '
367 | ' You may add additional accurate notices of copyright ownership.
368 | '
369 | ' Exhibit B - "Incompatible With Secondary Licenses" Notice
370 | ' ---------------------------------------------------------
371 | '
372 | ' This Source Code Form is "Incompatible With Secondary Licenses", as
373 | ' defined by the Mozilla Public License, v. 2.0.
374 |
375 | Imports System.Net
376 | Imports System.Net.Sockets
377 | Imports System.Threading
378 |
379 | Public Class MarsNATRPConnection
380 | Public toip As String
381 | Private core As MarsNATRP_Client.Core
382 | Private client As TcpClient
383 | Public tport As UShort
384 | Public rem_localaddr As IPEndPoint
385 |
386 | Public Sub New(core As MarsNATRP_Client.Core, mytcp As TcpClient, tip As String, tport As UShort)
387 | Me.core = core
388 | Me.toip = tip
389 | Me.tport = tport
390 | Me.client = mytcp
391 | Me.rem_localaddr = New IPEndPoint(IPAddress.Parse(tip), tport)
392 | End Sub
393 | Private Sub Create(ByVal state As Object)
394 | If Me.core.IsStarting Then
395 | Me.CreateConnectionBridge()
396 | GoTo __EXIT
397 | End If
398 | Me.Close()
399 | __EXIT:
400 | Return
401 | End Sub
402 |
403 | Private _ClientBuffer As Byte()
404 | Private _ProxyBuffer As Byte()
405 | Private Property Proxy As TcpClient
406 |
407 | Private Sub CreateConnectionBridge()
408 | If Me.client.Connected Then
409 | Me.Proxy = New TcpClient()
410 | Try
411 | Proxy.Connect(rem_localaddr)
412 | If Me.Proxy.Connected Then
413 | Me.core.WriteLineLog(String.Format("MarsNATRP_server and forward client connected at {0} .", DateTime.Now))
414 | _ClientBuffer = New Byte(Me.client.ReceiveBufferSize - 1) {}
415 | _ProxyBuffer = New Byte(Me.Proxy.ReceiveBufferSize - 1) {}
416 | Me.client.Client.BeginReceive(_ClientBuffer, 0, _ClientBuffer.Length, SocketFlags.None, AddressOf Me.OnClientReceive, Me.client.Client)
417 | Me.Proxy.Client.BeginReceive(_ProxyBuffer, 0, _ProxyBuffer.Length, SocketFlags.None, AddressOf Me.OnProxyReceive, Me.Proxy.Client)
418 | Else
419 | Me.Close()
420 | End If
421 | Catch ex As Exception
422 | core.WriteLineLog("An error occurred : " & ex.Message)
423 | Me.Close()
424 | End Try
425 | Else
426 | Me.Close()
427 | End If
428 | End Sub
429 |
430 |
431 | Private Sub OnClientReceive(ByVal result As IAsyncResult)
432 | If Me.core.IsStarting Then
433 |
434 | Try
435 | Dim socket As Socket = TryCast(result.AsyncState, Socket)
436 | Dim [error] As SocketError
437 | Dim size As Integer = socket.EndReceive(result, [error])
438 |
439 | If size > 0 Then
440 | SocketUtils.Send(Me.Proxy.Client, _ClientBuffer, 0, size)
441 | If Me.core.IsStarting Then Me.client.Client.BeginReceive(_ClientBuffer, 0, _ClientBuffer.Length, SocketFlags.None, AddressOf Me.OnClientReceive, Me.client.Client)
442 | Else
443 | Me.Close()
444 | End If
445 |
446 | Catch ex As Exception
447 | core.WriteLineLog("An error occurred : " & ex.Message)
448 | End Try
449 | End If
450 | End Sub
451 |
452 | Private Sub OnProxyReceive(ByVal result As IAsyncResult)
453 | If Me.core.IsStarting Then
454 |
455 | Try
456 | Dim socket As Socket = TryCast(result.AsyncState, Socket)
457 | Dim [error] As SocketError
458 | Dim size As Integer = socket.EndReceive(result, [error])
459 |
460 | If size > 0 Then
461 | SocketUtils.Send(Me.client.Client, _ProxyBuffer, 0, size)
462 | If Me.core.IsStarting Then socket.BeginReceive(_ProxyBuffer, 0, _ProxyBuffer.Length, SocketFlags.None, AddressOf Me.OnProxyReceive, socket)
463 | Else
464 | Me.Close()
465 | End If
466 |
467 | Catch ex As Exception
468 | core.WriteLineLog("An error occurred : " & ex.Message)
469 | End Try
470 | End If
471 | End Sub
472 |
473 |
474 | Private Sub Close()
475 | Try
476 | If Me.client IsNot Nothing Then
477 | Me.core.WriteLineLog(String.Format("MarsNATRP_Client has closed the connection with {1} at {0}..", DateTime.Now, Me.client.Client.RemoteEndPoint))
478 | Me.client.Dispose()
479 | Me.client = Nothing
480 | End If
481 |
482 | If Me.Proxy IsNot Nothing Then
483 | Me.core.WriteLineLog(String.Format("MarsNATRP_Client has closed the connection with {1} at {0}.", DateTime.Now, Me.Proxy.Client.RemoteEndPoint))
484 | Me.Proxy.Close()
485 | Me.Proxy = Nothing
486 | End If
487 |
488 | Catch ex As Exception
489 | core.WriteLineLog("An error occurred : " & ex.Message)
490 | End Try
491 | End Sub
492 |
493 | Public Shared Sub Create(core As Core, mytcp As TcpClient, tip As String, tport As UShort)
494 | Dim connection As MarsNATRPConnection = New MarsNATRPConnection(core, mytcp, tip, tport)
495 | ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf connection.Create))
496 | End Sub
497 | End Class
498 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/NATRP_ClientCore/SocketUtils.vb:
--------------------------------------------------------------------------------
1 | ' Mozilla Public License Version 2.0
2 | ' =================
3 | '
4 | ' 1. Definitions
5 | ' --------------
6 | '
7 | ' 1.1. "Contributor"
8 | ' means each individual or legal entity that creates, contributes to
9 | ' the creation of, or owns Covered Software.
10 | '
11 | ' 1.2. "Contributor Version"
12 | ' means the combination of the Contributions of others (if any) used
13 | ' by a Contributor and that particular Contributor's Contribution.
14 | '
15 | ' 1.3. "Contribution"
16 | ' means Covered Software of a particular Contributor.
17 | '
18 | ' 1.4. "Covered Software"
19 | ' means Source Code Form to which the initial Contributor has attached
20 | ' the notice in Exhibit A, the Executable Form of such Source Code
21 | ' Form, and Modifications of such Source Code Form, in each case
22 | ' including portions thereof.
23 | '
24 | ' 1.5. "Incompatible With Secondary Licenses"
25 | ' means
26 | '
27 | ' (a) that the initial Contributor has attached the notice described
28 | ' in Exhibit B to the Covered Software or
29 | '
30 | ' (b) that the Covered Software was made available under the terms of
31 | ' version 1.1 or earlier of the License, but not also under the
32 | ' terms of a Secondary License.
33 | '
34 | ' 1.6. "Executable Form"
35 | ' means any form of the work other than Source Code Form.
36 | '
37 | ' 1.7. "Larger Work"
38 | ' means a work that combines Covered Software with other material, in
39 | ' a separate file or files, that is not Covered Software.
40 | '
41 | ' 1.8. "License"
42 | ' means Me document.
43 | '
44 | ' 1.9. "Licensable"
45 | ' means having the right to grant, to the maximum extent possible,
46 | ' whether at the time of the initial grant or subsequently, any and
47 | ' all of the rights conveyed by Me License.
48 | '
49 | ' 1.10. "Modifications"
50 | ' means any of the following:
51 | '
52 | ' (a) any file in Source Code Form that results from an addition to,
53 | ' deletion from, or modification of the contents of Covered
54 | ' Software or
55 | '
56 | ' (b) any New file in Source Code Form that contains any Covered
57 | ' Software.
58 | '
59 | ' 1.11. "Patent Claims" of a Contributor
60 | ' means any patent claim(s), including without limitation, method,
61 | ' process, and apparatus claims, in any patent Licensable by such
62 | ' Contributor that would be infringed, but for the grant of the
63 | ' License, by the making, using, selling, offering for sale, having
64 | ' made, import, or transfer of either its Contributions or its
65 | ' Contributor Version.
66 | '
67 | ' 1.12. "Secondary License"
68 | ' means either the GNU General Public License, Version 2.0, the GNU
69 | ' Lesser General Public License, Version 2.1, the GNU Affero General
70 | ' Public License, Version 3.0, or any later versions of those
71 | ' licenses.
72 | '
73 | ' 1.13. "Source Code Form"
74 | ' means the form of the work preferred for making modifications.
75 | '
76 | ' 1.14. "You" (or "Your")
77 | ' means an individual or a legal entity exercising rights under Me
78 | ' License. For legal entities, "You" includes any entity that
79 | ' controls, is controlled by, or is under common control with You. For
80 | ' purposes of Me definition, "control" means (a) the power, direct
81 | ' or indirect, to cause the direction or management of such entity,
82 | ' whether by contract or otherwise, or (b) ownership of more than
83 | ' fifty percent (50%) of the outstanding shares or beneficial
84 | ' ownership of such entity.
85 | '
86 | ' 2. License Grants and Conditions
87 | ' --------------------------------
88 | '
89 | ' 2.1. Grants
90 | '
91 | ' Each Contributor hereby grants You a world-wide, royalty-free,
92 | ' non-exclusive license:
93 | '
94 | ' (a) under intellectual property rights (other than patent or trademark)
95 | ' Licensable by such Contributor to use, reproduce, make available,
96 | ' modify, display, perform, distribute, and otherwise exploit its
97 | ' Contributions, either on an unmodified basis, with Modifications, or
98 | ' as part of a Larger Work and
99 | '
100 | ' (b) under Patent Claims of such Contributor to make, use, sell, offer
101 | ' for sale, have made, import, and otherwise transfer either its
102 | ' Contributions or its Contributor Version.
103 | '
104 | ' 2.2. Effective Date
105 | '
106 | ' The licenses granted in Section 2.1 with respect to any Contribution
107 | ' become effective for each Contribution on the date the Contributor first
108 | ' distributes such Contribution.
109 | '
110 | ' 2.3. Limitations on Grant Scope
111 | '
112 | ' The licenses granted in Me Section 2 are the only rights granted under
113 | ' Me License. No additional rights or licenses will be implied from the
114 | ' distribution or licensing of Covered Software under Me License.
115 | ' Notwithstanding Section 2.1(b) above, no patent license is granted by a
116 | ' Contributor:
117 | '
118 | ' CType(for any code that a Contributor has removed from Covered Software, a)
119 | ' or
120 | '
121 | ' (b) for infringements caused by: (i) Your and any other third party's
122 | ' modifications of Covered Software, or (ii) the combination of its
123 | ' Contributions with other software (except as part of its Contributor
124 | ' Version) or
125 | '
126 | ' (c) under Patent Claims infringed by Covered Software in the absence of
127 | ' its Contributions.
128 | '
129 | ' This License does not grant any rights in the trademarks, service marks,
130 | ' or logos of any Contributor (except as may be necessary to comply with
131 | ' the notice requirements in Section 3.4).
132 | '
133 | ' 2.4. Subsequent Licenses
134 | '
135 | ' No Contributor makes additional grants as a result of Your choice to
136 | ' distribute the Covered Software under a subsequent version of Me
137 | ' License (see Section 10.2) or under the terms of a Secondary License (if
138 | ' permitted under the terms of Section 3.3).
139 | '
140 | ' 2.5. Representation
141 | '
142 | ' Each Contributor represents that the Contributor believes its
143 | ' Contributions are its original creation(s) or it has sufficient rights
144 | ' to grant the rights to its Contributions conveyed by Me License.
145 | '
146 | ' 2.6. Fair Use
147 | '
148 | ' This License is not intended to limit any rights You have under
149 | ' applicable copyright doctrines of fair use, fair dealing, or other
150 | ' equivalents.
151 | '
152 | ' 2.7. Conditions
153 | '
154 | ' Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155 | ' in Section 2.1.
156 | '
157 | ' 3. Responsibilities
158 | ' -------------------
159 | '
160 | ' 3.1. Distribution of Source Form
161 | '
162 | ' All distribution of Covered Software in Source Code Form, including any
163 | ' Modifications that You create or to which You contribute, must be under
164 | ' the terms of Me License. You must inform recipients that the Source
165 | ' Code Form of the Covered Software is governed by the terms of Me
166 | ' License, and how they can obtain a copy of Me License. You may not
167 | ' attempt to alter or restrict the recipients' rights in the Source Code
168 | ' Form.
169 | '
170 | ' 3.2. Distribution of Executable Form
171 | '
172 | ' If You distribute Covered Software in Executable Form then:
173 | '
174 | ' (a) such Covered Software must also be made available in Source Code
175 | ' Form, as described in Section 3.1, and You must inform recipients of
176 | ' the Executable Form how they can obtain a copy of such Source Code
177 | ' Form by reasonable means in a timely manner, at a charge no more
178 | ' than the cost of distribution to the recipient and
179 | '
180 | ' (b) You may distribute such Executable Form under the terms of Me
181 | ' License, or sublicense it under different terms, provided that the
182 | ' license for the Executable Form does not attempt to limit or alter
183 | ' the recipients' rights in the Source Code Form under Me License.
184 | '
185 | ' 3.3. Distribution of a Larger Work
186 | '
187 | ' You may create and distribute a Larger Work under terms of Your choice,
188 | ' provided that You also comply with the requirements of Me License for
189 | ' the Covered Software. If the Larger Work is a combination of Covered
190 | ' Software with a work governed by one or more Secondary Licenses, and the
191 | ' Covered Software is not Incompatible With Secondary Licenses, Me
192 | ' License permits You to additionally distribute such Covered Software
193 | ' under the terms of such Secondary License(s), so that the recipient of
194 | ' the Larger Work may, at their option, further distribute the Covered
195 | ' Software under the terms of either Me License or such Secondary
196 | ' License(s).
197 | '
198 | ' 3.4. Notices
199 | '
200 | ' You may not remove or alter the substance of any license notices
201 | ' (including copyright notices, patent notices, disclaimers of warranty,
202 | ' or limitations of liability) contained within the Source Code Form of
203 | ' the Covered Software, except that You may alter any license notices to
204 | ' the extent required to remedy known factual inaccuracies.
205 | '
206 | ' 3.5. Application of Additional Terms
207 | '
208 | ' You may choose to offer, and to charge a fee for, warranty, support,
209 | ' indemnity or liability obligations to one or more recipients of Covered
210 | ' Software. However, You may do so only on Your own behalf, and not on
211 | ' behalf of any Contributor. You must make it absolutely clear that any
212 | ' such warranty, support, indemnity, or liability obligation is offered by
213 | ' You alone, and You hereby agree to indemnify every Contributor for any
214 | ' liability incurred by such Contributor as a result of warranty, support,
215 | ' indemnity or liability terms You offer. You may include additional
216 | ' disclaimers of warranty and limitations of liability specific to any
217 | ' jurisdiction.
218 | '
219 | ' 4. Inability to Comply Due to Statute or Regulation
220 | ' ---------------------------------------------------
221 | '
222 | ' If it is impossible for You to comply with any of the terms of Me
223 | ' License with respect to some or all of the Covered Software due to
224 | ' statute, judicial order, or regulation then You must: (a) comply with
225 | ' the terms of Me License to the maximum extent possible and (b)
226 | ' describe the limitations and the code they affect. Such description must
227 | ' be placed in a text file included with all distributions of the Covered
228 | ' Software under Me License. Except to the extent prohibited by statute
229 | ' or regulation, such description must be sufficiently detailed for a
230 | ' recipient of ordinary skill to be able to understand it.
231 | '
232 | ' 5. Termination
233 | ' --------------
234 | '
235 | ' 5.1. The rights granted under Me License will terminate automatically
236 | ' if You fail to comply with any of its terms. However, if You become
237 | ' compliant, then the rights granted under Me License from a particular
238 | ' Contributor are reinstated (a) provisionally, unless and until such
239 | ' Contributor explicitly and Finally terminates Your grants, and (b) on an
240 | ' ongoing basis, if such Contributor fails to notify You of the
241 | ' non-compliance by some reasonable means prior to 60 days after You have
242 | ' come back into compliance. Moreover, Your grants from a particular
243 | ' Contributor are reinstated on an ongoing basis if such Contributor
244 | ' notifies You of the non-compliance by some reasonable means, Me is the
245 | ' first time You have received notice of non-compliance with Me License
246 | ' from such Contributor, and You become compliant prior to 30 days after
247 | ' Your receipt of the notice.
248 | '
249 | ' 5.2. If You initiate litigation against any entity by asserting a patent
250 | ' infringement claim (excluding declaratory judgment actions,
251 | ' counter-claims, and cross-claims) alleging that a Contributor Version
252 | ' directly or indirectly infringes any patent, then the rights granted to
253 | ' You by any and all Contributors for the Covered Software under Section
254 | ' 2.1 of Me License shall terminate.
255 | '
256 | ' 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257 | ' end user license agreements (excluding distributors and resellers) which
258 | ' have been validly granted by You or Your distributors under Me License
259 | ' prior to termination shall survive termination.
260 | '
261 | ' ************************************************************************
262 | ' * *
263 | ' * 6. Disclaimer of Warranty *
264 | ' * ------------------------- *
265 | ' * *
266 | ' * Covered Software is provided under Me License on an "as is" *
267 | ' * basis, without warranty of any kind, either expressed, implied, or *
268 | ' * statutory, including, without limitation, warranties that the *
269 | ' * Covered Software is free of defects, merchantable, fit for a *
270 | ' * particular purpose or non-infringing. The entire risk as to the *
271 | ' * quality and performance of the Covered Software is with You. *
272 | ' * Should any Covered Software prove defective in any respect, You *
273 | ' * (not any Contributor) assume the cost of any necessary servicing, *
274 | ' * repair, or correction. This disclaimer of warranty constitutes an *
275 | ' * essential part of Me License. No use of any Covered Software is *
276 | ' * authorized under Me License except under Me disclaimer. *
277 | ' * *
278 | ' ************************************************************************
279 | '
280 | ' ************************************************************************
281 | ' * *
282 | ' * 7. Limitation of Liability *
283 | ' * -------------------------- *
284 | ' * *
285 | ' * Under no circumstances and under no legal theory, whether tort *
286 | ' * (including negligence), contract, or otherwise, shall any *
287 | ' * Contributor, or anyone who distributes Covered Software as *
288 | ' * permitted above, be liable to You for any direct, indirect, *
289 | ' * special, incidental, or consequential damages of any character *
290 | ' * including, without limitation, damages for lost profits, loss of *
291 | ' * goodwill, work stoppage, computer failure or malfunction, or any *
292 | ' * and all other commercial damages or losses, even if such party *
293 | ' * shall have been informed of the possibility of such damages. This *
294 | ' * limitation of liability shall not apply to liability for death or *
295 | ' * personal injury resulting from such party's negligence to the *
296 | ' * extent applicable law prohibits such limitation. Some *
297 | ' * jurisdictions do not allow the exclusion or limitation of *
298 | ' * incidental or consequential damages, so Me exclusion and *
299 | ' * limitation may not apply to You. *
300 | ' * *
301 | ' ************************************************************************
302 | '
303 | ' 8. Litigation
304 | ' -------------
305 | '
306 | ' Any litigation relating to Me License may be brought only in the
307 | ' courts of a jurisdiction where the defendant maintains its principal
308 | ' place of business and such litigation shall be governed by laws of that
309 | ' jurisdiction, without reference to its conflict-of-law provisions.
310 | ' Nothing in Me Section shall prevent a party's ability to bring
311 | ' cross-claims or counter-claims.
312 | '
313 | ' 9. Miscellaneous
314 | ' ----------------
315 | '
316 | ' This License represents the complete agreement concerning the subject
317 | ' matter hereof. If any provision of Me License is held to be
318 | ' unenforceable, such provision shall be reformed only to the extent
319 | ' necessary to make it enforceable. Any law or regulation which provides
320 | ' that the language of a contract shall be consTrued against the drafter
321 | ' shall not be used to consTrue Me License against a Contributor.
322 | '
323 | ' 10. Versions of the License
324 | ' ---------------------------
325 | '
326 | ' 10.1. New Versions
327 | '
328 | ' Mozilla Foundation is the license steward. Except as provided in Section
329 | ' 10.3, no one other than the license steward has the right to modify or
330 | ' publish New versions of Me License. Each version will be given a
331 | ' distinguishing version number.
332 | '
333 | ' 10.2. Effect of New Versions
334 | '
335 | ' You may distribute the Covered Software under the terms of the version
336 | ' of the License under which You originally received the Covered Software,
337 | ' or under the terms of any subsequent version published by the license
338 | ' steward.
339 | '
340 | ' 10.3. Modified Versions
341 | '
342 | ' If you create software not governed by Me License, and you want to
343 | ' create a New license for such software, you may create and use a
344 | ' modified version of Me License if you rename the license and remove
345 | ' any references to the name of the license steward (except to note that
346 | ' such modified license differs from Me License).
347 | '
348 | ' 10.4. Distributing Source Code Form that is Incompatible With Secondary
349 | ' Licenses
350 | '
351 | ' If You choose to distribute Source Code Form that is Incompatible With
352 | ' Secondary Licenses under the terms of Me version of the License, the
353 | ' notice described in Exhibit B of Me License must be attached.
354 | '
355 | ' Exhibit A - Source Code Form License Notice
356 | ' -------------------------------------------
357 | '
358 | ' This Source Code Form is subject to the terms of the Mozilla Public
359 | ' License, v. 2.0. If a copy of the MPL was not distributed with Me
360 | ' file, You can obtain one at http:'mozilla.org/MPL/2.0/.
361 | '
362 | ' If it is not possible or desirable to put the notice in a particular
363 | ' file, then You may include the notice in a location (such as a LICENSE
364 | ' file in a relevant directory) where a recipient would be likely to look
365 | ' for such a notice.
366 | '
367 | ' You may add additional accurate notices of copyright ownership.
368 | '
369 | ' Exhibit B - "Incompatible With Secondary Licenses" Notice
370 | ' ---------------------------------------------------------
371 | '
372 | ' This Source Code Form is "Incompatible With Secondary Licenses", as
373 | ' defined by the Mozilla Public License, v. 2.0.
374 |
375 | Imports System
376 | Imports System.Collections.Generic
377 | Imports System.Net.Sockets
378 | Imports System.Text
379 | Imports System.Runtime.InteropServices
380 |
381 |
382 | Module SocketUtils
383 | Public Const TIMEOUT As Integer = 30000000
384 |
385 | Friend Function Receive(ByVal client As Socket, ByVal maxSize As UInteger, ByRef buffer As Byte()) As Boolean
386 | buffer = New Byte(-1) {}
387 | Dim offset As Integer = 0
388 |
389 | If client.Connected Then
390 |
391 | Try
392 | buffer = New Byte(maxSize - 1) {}
393 |
394 | Do
395 |
396 | If client.Available = 0 Then
397 | If Not client.Poll(TIMEOUT, SelectMode.SelectRead) Then Exit Do
398 | If client.Available = 0 Then Exit Do
399 | End If
400 |
401 | Dim size As Integer = client.Receive(buffer, offset, buffer.Length - offset, SocketFlags.None)
402 | offset += size
403 | Loop While offset < buffer.Length
404 |
405 | If offset > 0 AndAlso offset < buffer.Length Then
406 | Array.Resize(Of Byte)(buffer, offset)
407 | End If
408 |
409 | Catch
410 | offset = 0
411 | End Try
412 | End If
413 |
414 | Return offset <> 0
415 | End Function
416 |
417 | Friend Sub Send(ByVal client As Socket, ByVal data As Byte())
418 | Send(client, data, 0, data.Length)
419 | End Sub
420 |
421 | Friend Sub Send(ByVal client As Socket, ByVal data As Byte(), ByVal offset As Integer, ByVal size As Integer)
422 | If client.Connected Then
423 |
424 | Try
425 |
426 | If client.Poll(TIMEOUT, SelectMode.SelectWrite) Then
427 | client.Send(data, offset, size, SocketFlags.[Partial])
428 | End If
429 | Catch
430 | End Try
431 | End If
432 | End Sub
433 | End Module
434 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/Program.vb:
--------------------------------------------------------------------------------
1 | ' Mozilla Public License Version 2.0
2 | ' =================
3 | '
4 | ' 1. Definitions
5 | ' --------------
6 | '
7 | ' 1.1. "Contributor"
8 | ' means each individual or legal entity that creates, contributes to
9 | ' the creation of, or owns Covered Software.
10 | '
11 | ' 1.2. "Contributor Version"
12 | ' means the combination of the Contributions of others (if any) used
13 | ' by a Contributor and that particular Contributor's Contribution.
14 | '
15 | ' 1.3. "Contribution"
16 | ' means Covered Software of a particular Contributor.
17 | '
18 | ' 1.4. "Covered Software"
19 | ' means Source Code Form to which the initial Contributor has attached
20 | ' the notice in Exhibit A, the Executable Form of such Source Code
21 | ' Form, and Modifications of such Source Code Form, in each case
22 | ' including portions thereof.
23 | '
24 | ' 1.5. "Incompatible With Secondary Licenses"
25 | ' means
26 | '
27 | ' (a) that the initial Contributor has attached the notice described
28 | ' in Exhibit B to the Covered Software or
29 | '
30 | ' (b) that the Covered Software was made available under the terms of
31 | ' version 1.1 or earlier of the License, but not also under the
32 | ' terms of a Secondary License.
33 | '
34 | ' 1.6. "Executable Form"
35 | ' means any form of the work other than Source Code Form.
36 | '
37 | ' 1.7. "Larger Work"
38 | ' means a work that combines Covered Software with other material, in
39 | ' a separate file or files, that is not Covered Software.
40 | '
41 | ' 1.8. "License"
42 | ' means Me document.
43 | '
44 | ' 1.9. "Licensable"
45 | ' means having the right to grant, to the maximum extent possible,
46 | ' whether at the time of the initial grant or subsequently, any and
47 | ' all of the rights conveyed by Me License.
48 | '
49 | ' 1.10. "Modifications"
50 | ' means any of the following:
51 | '
52 | ' (a) any file in Source Code Form that results from an addition to,
53 | ' deletion from, or modification of the contents of Covered
54 | ' Software or
55 | '
56 | ' (b) any New file in Source Code Form that contains any Covered
57 | ' Software.
58 | '
59 | ' 1.11. "Patent Claims" of a Contributor
60 | ' means any patent claim(s), including without limitation, method,
61 | ' process, and apparatus claims, in any patent Licensable by such
62 | ' Contributor that would be infringed, but for the grant of the
63 | ' License, by the making, using, selling, offering for sale, having
64 | ' made, import, or transfer of either its Contributions or its
65 | ' Contributor Version.
66 | '
67 | ' 1.12. "Secondary License"
68 | ' means either the GNU General Public License, Version 2.0, the GNU
69 | ' Lesser General Public License, Version 2.1, the GNU Affero General
70 | ' Public License, Version 3.0, or any later versions of those
71 | ' licenses.
72 | '
73 | ' 1.13. "Source Code Form"
74 | ' means the form of the work preferred for making modifications.
75 | '
76 | ' 1.14. "You" (or "Your")
77 | ' means an individual or a legal entity exercising rights under Me
78 | ' License. For legal entities, "You" includes any entity that
79 | ' controls, is controlled by, or is under common control with You. For
80 | ' purposes of Me definition, "control" means (a) the power, direct
81 | ' or indirect, to cause the direction or management of such entity,
82 | ' whether by contract or otherwise, or (b) ownership of more than
83 | ' fifty percent (50%) of the outstanding shares or beneficial
84 | ' ownership of such entity.
85 | '
86 | ' 2. License Grants and Conditions
87 | ' --------------------------------
88 | '
89 | ' 2.1. Grants
90 | '
91 | ' Each Contributor hereby grants You a world-wide, royalty-free,
92 | ' non-exclusive license:
93 | '
94 | ' (a) under intellectual property rights (other than patent or trademark)
95 | ' Licensable by such Contributor to use, reproduce, make available,
96 | ' modify, display, perform, distribute, and otherwise exploit its
97 | ' Contributions, either on an unmodified basis, with Modifications, or
98 | ' as part of a Larger Work and
99 | '
100 | ' (b) under Patent Claims of such Contributor to make, use, sell, offer
101 | ' for sale, have made, import, and otherwise transfer either its
102 | ' Contributions or its Contributor Version.
103 | '
104 | ' 2.2. Effective Date
105 | '
106 | ' The licenses granted in Section 2.1 with respect to any Contribution
107 | ' become effective for each Contribution on the date the Contributor first
108 | ' distributes such Contribution.
109 | '
110 | ' 2.3. Limitations on Grant Scope
111 | '
112 | ' The licenses granted in Me Section 2 are the only rights granted under
113 | ' Me License. No additional rights or licenses will be implied from the
114 | ' distribution or licensing of Covered Software under Me License.
115 | ' Notwithstanding Section 2.1(b) above, no patent license is granted by a
116 | ' Contributor:
117 | '
118 | ' CType(for any code that a Contributor has removed from Covered Software, a)
119 | ' or
120 | '
121 | ' (b) for infringements caused by: (i) Your and any other third party's
122 | ' modifications of Covered Software, or (ii) the combination of its
123 | ' Contributions with other software (except as part of its Contributor
124 | ' Version) or
125 | '
126 | ' (c) under Patent Claims infringed by Covered Software in the absence of
127 | ' its Contributions.
128 | '
129 | ' This License does not grant any rights in the trademarks, service marks,
130 | ' or logos of any Contributor (except as may be necessary to comply with
131 | ' the notice requirements in Section 3.4).
132 | '
133 | ' 2.4. Subsequent Licenses
134 | '
135 | ' No Contributor makes additional grants as a result of Your choice to
136 | ' distribute the Covered Software under a subsequent version of Me
137 | ' License (see Section 10.2) or under the terms of a Secondary License (if
138 | ' permitted under the terms of Section 3.3).
139 | '
140 | ' 2.5. Representation
141 | '
142 | ' Each Contributor represents that the Contributor believes its
143 | ' Contributions are its original creation(s) or it has sufficient rights
144 | ' to grant the rights to its Contributions conveyed by Me License.
145 | '
146 | ' 2.6. Fair Use
147 | '
148 | ' This License is not intended to limit any rights You have under
149 | ' applicable copyright doctrines of fair use, fair dealing, or other
150 | ' equivalents.
151 | '
152 | ' 2.7. Conditions
153 | '
154 | ' Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155 | ' in Section 2.1.
156 | '
157 | ' 3. Responsibilities
158 | ' -------------------
159 | '
160 | ' 3.1. Distribution of Source Form
161 | '
162 | ' All distribution of Covered Software in Source Code Form, including any
163 | ' Modifications that You create or to which You contribute, must be under
164 | ' the terms of Me License. You must inform recipients that the Source
165 | ' Code Form of the Covered Software is governed by the terms of Me
166 | ' License, and how they can obtain a copy of Me License. You may not
167 | ' attempt to alter or restrict the recipients' rights in the Source Code
168 | ' Form.
169 | '
170 | ' 3.2. Distribution of Executable Form
171 | '
172 | ' If You distribute Covered Software in Executable Form then:
173 | '
174 | ' (a) such Covered Software must also be made available in Source Code
175 | ' Form, as described in Section 3.1, and You must inform recipients of
176 | ' the Executable Form how they can obtain a copy of such Source Code
177 | ' Form by reasonable means in a timely manner, at a charge no more
178 | ' than the cost of distribution to the recipient and
179 | '
180 | ' (b) You may distribute such Executable Form under the terms of Me
181 | ' License, or sublicense it under different terms, provided that the
182 | ' license for the Executable Form does not attempt to limit or alter
183 | ' the recipients' rights in the Source Code Form under Me License.
184 | '
185 | ' 3.3. Distribution of a Larger Work
186 | '
187 | ' You may create and distribute a Larger Work under terms of Your choice,
188 | ' provided that You also comply with the requirements of Me License for
189 | ' the Covered Software. If the Larger Work is a combination of Covered
190 | ' Software with a work governed by one or more Secondary Licenses, and the
191 | ' Covered Software is not Incompatible With Secondary Licenses, Me
192 | ' License permits You to additionally distribute such Covered Software
193 | ' under the terms of such Secondary License(s), so that the recipient of
194 | ' the Larger Work may, at their option, further distribute the Covered
195 | ' Software under the terms of either Me License or such Secondary
196 | ' License(s).
197 | '
198 | ' 3.4. Notices
199 | '
200 | ' You may not remove or alter the substance of any license notices
201 | ' (including copyright notices, patent notices, disclaimers of warranty,
202 | ' or limitations of liability) contained within the Source Code Form of
203 | ' the Covered Software, except that You may alter any license notices to
204 | ' the extent required to remedy known factual inaccuracies.
205 | '
206 | ' 3.5. Application of Additional Terms
207 | '
208 | ' You may choose to offer, and to charge a fee for, warranty, support,
209 | ' indemnity or liability obligations to one or more recipients of Covered
210 | ' Software. However, You may do so only on Your own behalf, and not on
211 | ' behalf of any Contributor. You must make it absolutely clear that any
212 | ' such warranty, support, indemnity, or liability obligation is offered by
213 | ' You alone, and You hereby agree to indemnify every Contributor for any
214 | ' liability incurred by such Contributor as a result of warranty, support,
215 | ' indemnity or liability terms You offer. You may include additional
216 | ' disclaimers of warranty and limitations of liability specific to any
217 | ' jurisdiction.
218 | '
219 | ' 4. Inability to Comply Due to Statute or Regulation
220 | ' ---------------------------------------------------
221 | '
222 | ' If it is impossible for You to comply with any of the terms of Me
223 | ' License with respect to some or all of the Covered Software due to
224 | ' statute, judicial order, or regulation then You must: (a) comply with
225 | ' the terms of Me License to the maximum extent possible and (b)
226 | ' describe the limitations and the code they affect. Such description must
227 | ' be placed in a text file included with all distributions of the Covered
228 | ' Software under Me License. Except to the extent prohibited by statute
229 | ' or regulation, such description must be sufficiently detailed for a
230 | ' recipient of ordinary skill to be able to understand it.
231 | '
232 | ' 5. Termination
233 | ' --------------
234 | '
235 | ' 5.1. The rights granted under Me License will terminate automatically
236 | ' if You fail to comply with any of its terms. However, if You become
237 | ' compliant, then the rights granted under Me License from a particular
238 | ' Contributor are reinstated (a) provisionally, unless and until such
239 | ' Contributor explicitly and Finally terminates Your grants, and (b) on an
240 | ' ongoing basis, if such Contributor fails to notify You of the
241 | ' non-compliance by some reasonable means prior to 60 days after You have
242 | ' come back into compliance. Moreover, Your grants from a particular
243 | ' Contributor are reinstated on an ongoing basis if such Contributor
244 | ' notifies You of the non-compliance by some reasonable means, Me is the
245 | ' first time You have received notice of non-compliance with Me License
246 | ' from such Contributor, and You become compliant prior to 30 days after
247 | ' Your receipt of the notice.
248 | '
249 | ' 5.2. If You initiate litigation against any entity by asserting a patent
250 | ' infringement claim (excluding declaratory judgment actions,
251 | ' counter-claims, and cross-claims) alleging that a Contributor Version
252 | ' directly or indirectly infringes any patent, then the rights granted to
253 | ' You by any and all Contributors for the Covered Software under Section
254 | ' 2.1 of Me License shall terminate.
255 | '
256 | ' 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257 | ' end user license agreements (excluding distributors and resellers) which
258 | ' have been validly granted by You or Your distributors under Me License
259 | ' prior to termination shall survive termination.
260 | '
261 | ' ************************************************************************
262 | ' * *
263 | ' * 6. Disclaimer of Warranty *
264 | ' * ------------------------- *
265 | ' * *
266 | ' * Covered Software is provided under Me License on an "as is" *
267 | ' * basis, without warranty of any kind, either expressed, implied, or *
268 | ' * statutory, including, without limitation, warranties that the *
269 | ' * Covered Software is free of defects, merchantable, fit for a *
270 | ' * particular purpose or non-infringing. The entire risk as to the *
271 | ' * quality and performance of the Covered Software is with You. *
272 | ' * Should any Covered Software prove defective in any respect, You *
273 | ' * (not any Contributor) assume the cost of any necessary servicing, *
274 | ' * repair, or correction. This disclaimer of warranty constitutes an *
275 | ' * essential part of Me License. No use of any Covered Software is *
276 | ' * authorized under Me License except under Me disclaimer. *
277 | ' * *
278 | ' ************************************************************************
279 | '
280 | ' ************************************************************************
281 | ' * *
282 | ' * 7. Limitation of Liability *
283 | ' * -------------------------- *
284 | ' * *
285 | ' * Under no circumstances and under no legal theory, whether tort *
286 | ' * (including negligence), contract, or otherwise, shall any *
287 | ' * Contributor, or anyone who distributes Covered Software as *
288 | ' * permitted above, be liable to You for any direct, indirect, *
289 | ' * special, incidental, or consequential damages of any character *
290 | ' * including, without limitation, damages for lost profits, loss of *
291 | ' * goodwill, work stoppage, computer failure or malfunction, or any *
292 | ' * and all other commercial damages or losses, even if such party *
293 | ' * shall have been informed of the possibility of such damages. This *
294 | ' * limitation of liability shall not apply to liability for death or *
295 | ' * personal injury resulting from such party's negligence to the *
296 | ' * extent applicable law prohibits such limitation. Some *
297 | ' * jurisdictions do not allow the exclusion or limitation of *
298 | ' * incidental or consequential damages, so Me exclusion and *
299 | ' * limitation may not apply to You. *
300 | ' * *
301 | ' ************************************************************************
302 | '
303 | ' 8. Litigation
304 | ' -------------
305 | '
306 | ' Any litigation relating to Me License may be brought only in the
307 | ' courts of a jurisdiction where the defendant maintains its principal
308 | ' place of business and such litigation shall be governed by laws of that
309 | ' jurisdiction, without reference to its conflict-of-law provisions.
310 | ' Nothing in Me Section shall prevent a party's ability to bring
311 | ' cross-claims or counter-claims.
312 | '
313 | ' 9. Miscellaneous
314 | ' ----------------
315 | '
316 | ' This License represents the complete agreement concerning the subject
317 | ' matter hereof. If any provision of Me License is held to be
318 | ' unenforceable, such provision shall be reformed only to the extent
319 | ' necessary to make it enforceable. Any law or regulation which provides
320 | ' that the language of a contract shall be consTrued against the drafter
321 | ' shall not be used to consTrue Me License against a Contributor.
322 | '
323 | ' 10. Versions of the License
324 | ' ---------------------------
325 | '
326 | ' 10.1. New Versions
327 | '
328 | ' Mozilla Foundation is the license steward. Except as provided in Section
329 | ' 10.3, no one other than the license steward has the right to modify or
330 | ' publish New versions of Me License. Each version will be given a
331 | ' distinguishing version number.
332 | '
333 | ' 10.2. Effect of New Versions
334 | '
335 | ' You may distribute the Covered Software under the terms of the version
336 | ' of the License under which You originally received the Covered Software,
337 | ' or under the terms of any subsequent version published by the license
338 | ' steward.
339 | '
340 | ' 10.3. Modified Versions
341 | '
342 | ' If you create software not governed by Me License, and you want to
343 | ' create a New license for such software, you may create and use a
344 | ' modified version of Me License if you rename the license and remove
345 | ' any references to the name of the license steward (except to note that
346 | ' such modified license differs from Me License).
347 | '
348 | ' 10.4. Distributing Source Code Form that is Incompatible With Secondary
349 | ' Licenses
350 | '
351 | ' If You choose to distribute Source Code Form that is Incompatible With
352 | ' Secondary Licenses under the terms of Me version of the License, the
353 | ' notice described in Exhibit B of Me License must be attached.
354 | '
355 | ' Exhibit A - Source Code Form License Notice
356 | ' -------------------------------------------
357 | '
358 | ' This Source Code Form is subject to the terms of the Mozilla Public
359 | ' License, v. 2.0. If a copy of the MPL was not distributed with Me
360 | ' file, You can obtain one at http:'mozilla.org/MPL/2.0/.
361 | '
362 | ' If it is not possible or desirable to put the notice in a particular
363 | ' file, then You may include the notice in a location (such as a LICENSE
364 | ' file in a relevant directory) where a recipient would be likely to look
365 | ' for such a notice.
366 | '
367 | ' You may add additional accurate notices of copyright ownership.
368 | '
369 | ' Exhibit B - "Incompatible With Secondary Licenses" Notice
370 | ' ---------------------------------------------------------
371 | '
372 | ' This Source Code Form is "Incompatible With Secondary Licenses", as
373 | ' defined by the Mozilla Public License, v. 2.0.
374 |
375 | Imports System
376 | Imports System.Threading
377 |
378 | Module Program
379 | Sub Main(args As String())
380 | Dim cfc As ConsoleColor = Console.ForegroundColor
381 | Try
382 | Console.ForegroundColor = ConsoleColor.White
383 | Console.WriteLine("Welcome to use MarsNATRP_Client V1.0.1")
384 | Console.WriteLine("Copyright (c) 2018 GhostFamilyStudio. All rights reserved.")
385 | Console.WriteLine("For more information please visit http://ghofamily.sctstu.com")
386 | Console.ForegroundColor = ConsoleColor.Green
387 | Dim sip As String = args(0)
388 | Dim sport As UShort = args(1)
389 | Dim tip As String = args(2)
390 | Dim tport As UShort = args(3)
391 | Console.WriteLine("Server IP:{0}" + vbCrLf + "Server private port:{1}" + vbCrLf + "Forward IP:{2}" + vbCrLf + "Forward port:{3}", sip, sport, tip, tport)
392 | Dim clientcore As New Core(sip, sport, tip, tport) With {
393 | .LogWatcher = Console.Out
394 | }
395 | clientcore.StartClient()
396 | Console.ReadLine()
397 | Catch ex As Exception
398 | Console.WriteLine(ex.Message)
399 | End Try
400 | Console.ForegroundColor = cfc
401 | End Sub
402 | End Module
403 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/obj/MarsNATRP_Client.vbproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "bZ3obMjgvX6+sp6iBIt3lRDWXFTR0TyrBf0MCL03hPjg9HE3nw8TUcFe0TGX6ip0RySb9MlSWJDa4jTO2Yh9tg==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/MarsNATRP_Client/obj/MarsNATRP_Client.vbproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | C:\Users\Administrator\Desktop\MarsNATRP\MarsNATRP_Client\obj\project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\Administrator\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 4.8.1
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/MarsNATRP_Client/obj/MarsNATRP_Client.vbproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/MarsNATRP_Server/Core/MarsNATRPServerConnection.cs:
--------------------------------------------------------------------------------
1 | /*
2 | Mozilla Public License Version 2.0
3 | ==================================
4 |
5 | 1. Definitions
6 | --------------
7 |
8 | 1.1. "Contributor"
9 | means each individual or legal entity that creates, contributes to
10 | the creation of, or owns Covered Software.
11 |
12 | 1.2. "Contributor Version"
13 | means the combination of the Contributions of others (if any) used
14 | by a Contributor and that particular Contributor's Contribution.
15 |
16 | 1.3. "Contribution"
17 | means Covered Software of a particular Contributor.
18 |
19 | 1.4. "Covered Software"
20 | means Source Code Form to which the initial Contributor has attached
21 | the notice in Exhibit A, the Executable Form of such Source Code
22 | Form, and Modifications of such Source Code Form, in each case
23 | including portions thereof.
24 |
25 | 1.5. "Incompatible With Secondary Licenses"
26 | means
27 |
28 | (a) that the initial Contributor has attached the notice described
29 | in Exhibit B to the Covered Software; or
30 |
31 | (b) that the Covered Software was made available under the terms of
32 | version 1.1 or earlier of the License, but not also under the
33 | terms of a Secondary License.
34 |
35 | 1.6. "Executable Form"
36 | means any form of the work other than Source Code Form.
37 |
38 | 1.7. "Larger Work"
39 | means a work that combines Covered Software with other material, in
40 | a separate file or files, that is not Covered Software.
41 |
42 | 1.8. "License"
43 | means this document.
44 |
45 | 1.9. "Licensable"
46 | means having the right to grant, to the maximum extent possible,
47 | whether at the time of the initial grant or subsequently, any and
48 | all of the rights conveyed by this License.
49 |
50 | 1.10. "Modifications"
51 | means any of the following:
52 |
53 | (a) any file in Source Code Form that results from an addition to,
54 | deletion from, or modification of the contents of Covered
55 | Software; or
56 |
57 | (b) any new file in Source Code Form that contains any Covered
58 | Software.
59 |
60 | 1.11. "Patent Claims" of a Contributor
61 | means any patent claim(s), including without limitation, method,
62 | process, and apparatus claims, in any patent Licensable by such
63 | Contributor that would be infringed, but for the grant of the
64 | License, by the making, using, selling, offering for sale, having
65 | made, import, or transfer of either its Contributions or its
66 | Contributor Version.
67 |
68 | 1.12. "Secondary License"
69 | means either the GNU General Public License, Version 2.0, the GNU
70 | Lesser General Public License, Version 2.1, the GNU Affero General
71 | Public License, Version 3.0, or any later versions of those
72 | licenses.
73 |
74 | 1.13. "Source Code Form"
75 | means the form of the work preferred for making modifications.
76 |
77 | 1.14. "You" (or "Your")
78 | means an individual or a legal entity exercising rights under this
79 | License. For legal entities, "You" includes any entity that
80 | controls, is controlled by, or is under common control with You. For
81 | purposes of this definition, "control" means (a) the power, direct
82 | or indirect, to cause the direction or management of such entity,
83 | whether by contract or otherwise, or (b) ownership of more than
84 | fifty percent (50%) of the outstanding shares or beneficial
85 | ownership of such entity.
86 |
87 | 2. License Grants and Conditions
88 | --------------------------------
89 |
90 | 2.1. Grants
91 |
92 | Each Contributor hereby grants You a world-wide, royalty-free,
93 | non-exclusive license:
94 |
95 | (a) under intellectual property rights (other than patent or trademark)
96 | Licensable by such Contributor to use, reproduce, make available,
97 | modify, display, perform, distribute, and otherwise exploit its
98 | Contributions, either on an unmodified basis, with Modifications, or
99 | as part of a Larger Work; and
100 |
101 | (b) under Patent Claims of such Contributor to make, use, sell, offer
102 | for sale, have made, import, and otherwise transfer either its
103 | Contributions or its Contributor Version.
104 |
105 | 2.2. Effective Date
106 |
107 | The licenses granted in Section 2.1 with respect to any Contribution
108 | become effective for each Contribution on the date the Contributor first
109 | distributes such Contribution.
110 |
111 | 2.3. Limitations on Grant Scope
112 |
113 | The licenses granted in this Section 2 are the only rights granted under
114 | this License. No additional rights or licenses will be implied from the
115 | distribution or licensing of Covered Software under this License.
116 | Notwithstanding Section 2.1(b) above, no patent license is granted by a
117 | Contributor:
118 |
119 | (a) for any code that a Contributor has removed from Covered Software;
120 | or
121 |
122 | (b) for infringements caused by: (i) Your and any other third party's
123 | modifications of Covered Software, or (ii) the combination of its
124 | Contributions with other software (except as part of its Contributor
125 | Version); or
126 |
127 | (c) under Patent Claims infringed by Covered Software in the absence of
128 | its Contributions.
129 |
130 | This License does not grant any rights in the trademarks, service marks,
131 | or logos of any Contributor (except as may be necessary to comply with
132 | the notice requirements in Section 3.4).
133 |
134 | 2.4. Subsequent Licenses
135 |
136 | No Contributor makes additional grants as a result of Your choice to
137 | distribute the Covered Software under a subsequent version of this
138 | License (see Section 10.2) or under the terms of a Secondary License (if
139 | permitted under the terms of Section 3.3).
140 |
141 | 2.5. Representation
142 |
143 | Each Contributor represents that the Contributor believes its
144 | Contributions are its original creation(s) or it has sufficient rights
145 | to grant the rights to its Contributions conveyed by this License.
146 |
147 | 2.6. Fair Use
148 |
149 | This License is not intended to limit any rights You have under
150 | applicable copyright doctrines of fair use, fair dealing, or other
151 | equivalents.
152 |
153 | 2.7. Conditions
154 |
155 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
156 | in Section 2.1.
157 |
158 | 3. Responsibilities
159 | -------------------
160 |
161 | 3.1. Distribution of Source Form
162 |
163 | All distribution of Covered Software in Source Code Form, including any
164 | Modifications that You create or to which You contribute, must be under
165 | the terms of this License. You must inform recipients that the Source
166 | Code Form of the Covered Software is governed by the terms of this
167 | License, and how they can obtain a copy of this License. You may not
168 | attempt to alter or restrict the recipients' rights in the Source Code
169 | Form.
170 |
171 | 3.2. Distribution of Executable Form
172 |
173 | If You distribute Covered Software in Executable Form then:
174 |
175 | (a) such Covered Software must also be made available in Source Code
176 | Form, as described in Section 3.1, and You must inform recipients of
177 | the Executable Form how they can obtain a copy of such Source Code
178 | Form by reasonable means in a timely manner, at a charge no more
179 | than the cost of distribution to the recipient; and
180 |
181 | (b) You may distribute such Executable Form under the terms of this
182 | License, or sublicense it under different terms, provided that the
183 | license for the Executable Form does not attempt to limit or alter
184 | the recipients' rights in the Source Code Form under this License.
185 |
186 | 3.3. Distribution of a Larger Work
187 |
188 | You may create and distribute a Larger Work under terms of Your choice,
189 | provided that You also comply with the requirements of this License for
190 | the Covered Software. If the Larger Work is a combination of Covered
191 | Software with a work governed by one or more Secondary Licenses, and the
192 | Covered Software is not Incompatible With Secondary Licenses, this
193 | License permits You to additionally distribute such Covered Software
194 | under the terms of such Secondary License(s), so that the recipient of
195 | the Larger Work may, at their option, further distribute the Covered
196 | Software under the terms of either this License or such Secondary
197 | License(s).
198 |
199 | 3.4. Notices
200 |
201 | You may not remove or alter the substance of any license notices
202 | (including copyright notices, patent notices, disclaimers of warranty,
203 | or limitations of liability) contained within the Source Code Form of
204 | the Covered Software, except that You may alter any license notices to
205 | the extent required to remedy known factual inaccuracies.
206 |
207 | 3.5. Application of Additional Terms
208 |
209 | You may choose to offer, and to charge a fee for, warranty, support,
210 | indemnity or liability obligations to one or more recipients of Covered
211 | Software. However, You may do so only on Your own behalf, and not on
212 | behalf of any Contributor. You must make it absolutely clear that any
213 | such warranty, support, indemnity, or liability obligation is offered by
214 | You alone, and You hereby agree to indemnify every Contributor for any
215 | liability incurred by such Contributor as a result of warranty, support,
216 | indemnity or liability terms You offer. You may include additional
217 | disclaimers of warranty and limitations of liability specific to any
218 | jurisdiction.
219 |
220 | 4. Inability to Comply Due to Statute or Regulation
221 | ---------------------------------------------------
222 |
223 | If it is impossible for You to comply with any of the terms of this
224 | License with respect to some or all of the Covered Software due to
225 | statute, judicial order, or regulation then You must: (a) comply with
226 | the terms of this License to the maximum extent possible; and (b)
227 | describe the limitations and the code they affect. Such description must
228 | be placed in a text file included with all distributions of the Covered
229 | Software under this License. Except to the extent prohibited by statute
230 | or regulation, such description must be sufficiently detailed for a
231 | recipient of ordinary skill to be able to understand it.
232 |
233 | 5. Termination
234 | --------------
235 |
236 | 5.1. The rights granted under this License will terminate automatically
237 | if You fail to comply with any of its terms. However, if You become
238 | compliant, then the rights granted under this License from a particular
239 | Contributor are reinstated (a) provisionally, unless and until such
240 | Contributor explicitly and finally terminates Your grants, and (b) on an
241 | ongoing basis, if such Contributor fails to notify You of the
242 | non-compliance by some reasonable means prior to 60 days after You have
243 | come back into compliance. Moreover, Your grants from a particular
244 | Contributor are reinstated on an ongoing basis if such Contributor
245 | notifies You of the non-compliance by some reasonable means, this is the
246 | first time You have received notice of non-compliance with this License
247 | from such Contributor, and You become compliant prior to 30 days after
248 | Your receipt of the notice.
249 |
250 | 5.2. If You initiate litigation against any entity by asserting a patent
251 | infringement claim (excluding declaratory judgment actions,
252 | counter-claims, and cross-claims) alleging that a Contributor Version
253 | directly or indirectly infringes any patent, then the rights granted to
254 | You by any and all Contributors for the Covered Software under Section
255 | 2.1 of this License shall terminate.
256 |
257 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
258 | end user license agreements (excluding distributors and resellers) which
259 | have been validly granted by You or Your distributors under this License
260 | prior to termination shall survive termination.
261 |
262 | ************************************************************************
263 | * *
264 | * 6. Disclaimer of Warranty *
265 | * ------------------------- *
266 | * *
267 | * Covered Software is provided under this License on an "as is" *
268 | * basis, without warranty of any kind, either expressed, implied, or *
269 | * statutory, including, without limitation, warranties that the *
270 | * Covered Software is free of defects, merchantable, fit for a *
271 | * particular purpose or non-infringing. The entire risk as to the *
272 | * quality and performance of the Covered Software is with You. *
273 | * Should any Covered Software prove defective in any respect, You *
274 | * (not any Contributor) assume the cost of any necessary servicing, *
275 | * repair, or correction. This disclaimer of warranty constitutes an *
276 | * essential part of this License. No use of any Covered Software is *
277 | * authorized under this License except under this disclaimer. *
278 | * *
279 | ************************************************************************
280 |
281 | ************************************************************************
282 | * *
283 | * 7. Limitation of Liability *
284 | * -------------------------- *
285 | * *
286 | * Under no circumstances and under no legal theory, whether tort *
287 | * (including negligence), contract, or otherwise, shall any *
288 | * Contributor, or anyone who distributes Covered Software as *
289 | * permitted above, be liable to You for any direct, indirect, *
290 | * special, incidental, or consequential damages of any character *
291 | * including, without limitation, damages for lost profits, loss of *
292 | * goodwill, work stoppage, computer failure or malfunction, or any *
293 | * and all other commercial damages or losses, even if such party *
294 | * shall have been informed of the possibility of such damages. This *
295 | * limitation of liability shall not apply to liability for death or *
296 | * personal injury resulting from such party's negligence to the *
297 | * extent applicable law prohibits such limitation. Some *
298 | * jurisdictions do not allow the exclusion or limitation of *
299 | * incidental or consequential damages, so this exclusion and *
300 | * limitation may not apply to You. *
301 | * *
302 | ************************************************************************
303 |
304 | 8. Litigation
305 | -------------
306 |
307 | Any litigation relating to this License may be brought only in the
308 | courts of a jurisdiction where the defendant maintains its principal
309 | place of business and such litigation shall be governed by laws of that
310 | jurisdiction, without reference to its conflict-of-law provisions.
311 | Nothing in this Section shall prevent a party's ability to bring
312 | cross-claims or counter-claims.
313 |
314 | 9. Miscellaneous
315 | ----------------
316 |
317 | This License represents the complete agreement concerning the subject
318 | matter hereof. If any provision of this License is held to be
319 | unenforceable, such provision shall be reformed only to the extent
320 | necessary to make it enforceable. Any law or regulation which provides
321 | that the language of a contract shall be construed against the drafter
322 | shall not be used to construe this License against a Contributor.
323 |
324 | 10. Versions of the License
325 | ---------------------------
326 |
327 | 10.1. New Versions
328 |
329 | Mozilla Foundation is the license steward. Except as provided in Section
330 | 10.3, no one other than the license steward has the right to modify or
331 | publish new versions of this License. Each version will be given a
332 | distinguishing version number.
333 |
334 | 10.2. Effect of New Versions
335 |
336 | You may distribute the Covered Software under the terms of the version
337 | of the License under which You originally received the Covered Software,
338 | or under the terms of any subsequent version published by the license
339 | steward.
340 |
341 | 10.3. Modified Versions
342 |
343 | If you create software not governed by this License, and you want to
344 | create a new license for such software, you may create and use a
345 | modified version of this License if you rename the license and remove
346 | any references to the name of the license steward (except to note that
347 | such modified license differs from this License).
348 |
349 | 10.4. Distributing Source Code Form that is Incompatible With Secondary
350 | Licenses
351 |
352 | If You choose to distribute Source Code Form that is Incompatible With
353 | Secondary Licenses under the terms of this version of the License, the
354 | notice described in Exhibit B of this License must be attached.
355 |
356 | Exhibit A - Source Code Form License Notice
357 | -------------------------------------------
358 |
359 | This Source Code Form is subject to the terms of the Mozilla Public
360 | License, v. 2.0. If a copy of the MPL was not distributed with this
361 | file, You can obtain one at http://mozilla.org/MPL/2.0/.
362 |
363 | If it is not possible or desirable to put the notice in a particular
364 | file, then You may include the notice in a location (such as a LICENSE
365 | file in a relevant directory) where a recipient would be likely to look
366 | for such a notice.
367 |
368 | You may add additional accurate notices of copyright ownership.
369 |
370 | Exhibit B - "Incompatible With Secondary Licenses" Notice
371 | ---------------------------------------------------------
372 |
373 | This Source Code Form is "Incompatible With Secondary Licenses", as
374 | defined by the Mozilla Public License, v. 2.0.
375 |
376 |
377 | */
378 |
379 |
380 | using System;
381 | using System.Net;
382 | using System.Net.Sockets;
383 | using System.Threading;
384 |
385 | namespace MarsNATRP_Server
386 | {
387 | public class MarsNATRPServerConnection
388 | {
389 | String clientip;
390 | ushort clientport;
391 | private TcpListener tl;
392 | public MarsNATRPServerConnection(MarsNATRPServerCore server, Socket client, string clientip, ushort clientport)
393 | {
394 | this.Server = server;
395 | this.Client = client;
396 | this.clientip = clientip;
397 | this.clientport = clientport;
398 | }
399 |
400 | private MarsNATRPServerCore Server
401 | {
402 | get;
403 | set;
404 | }
405 |
406 | internal Socket Client
407 | {
408 | private set;
409 | get;
410 | }
411 |
412 | private void DoRequest(object state)
413 | {
414 | if (this.Server.IsStarting)
415 | {
416 | this.CreateConnectionBridge();
417 | goto __EXIT;
418 | }
419 | this.Close();
420 | __EXIT:
421 | return;
422 | }
423 | private byte[] _ClientBuffer;
424 | private byte[] _ProxyBuffer;
425 |
426 |
427 | private TcpClient Proxy
428 | {
429 | get;
430 | set;
431 | }
432 |
433 | private void CreateConnectionBridge()
434 | {
435 | if (this.Client.Connected)
436 | {
437 | this.Proxy = new TcpClient();
438 | tl = new TcpListener(IPAddress.Parse(this.clientip), this.clientport);
439 | try
440 | {
441 | tl.Start();
442 | Proxy = tl.AcceptTcpClient();
443 | tl.Stop();
444 | this.Server.WriteLineLog(string.Format("MarsNATRP_Server connect at {0} from {1}...", DateTime.Now, this.Proxy.Client.RemoteEndPoint));
445 | if (this.Proxy.Connected)
446 | {
447 | _ClientBuffer = new byte[this.Client.ReceiveBufferSize];
448 | _ProxyBuffer = new byte[this.Proxy.ReceiveBufferSize];
449 | this.Client.BeginReceive(_ClientBuffer, 0, _ClientBuffer.Length, SocketFlags.None, this.OnClientReceive, this.Client);
450 | this.Proxy.Client.BeginReceive(_ProxyBuffer, 0, _ProxyBuffer.Length, SocketFlags.None, this.OnProxyReceive, this.Proxy.Client);
451 | }
452 | else
453 | {
454 | this.Close();
455 | }
456 | }
457 | catch (Exception ex)
458 | {
459 |
460 | if (tl.LocalEndpoint != null)
461 | {
462 | tl.Stop();
463 | }
464 | else
465 | {
466 | this.Server.WriteLineLog("An error occurred : " + ex.Message);
467 | }
468 | this.Close();
469 | }
470 | if (tl.LocalEndpoint != null)
471 | {
472 | tl.Stop();
473 | }
474 | }
475 | else
476 | {
477 | this.Close();
478 | }
479 | }
480 |
481 |
482 | private void OnClientReceive(IAsyncResult result)
483 | {
484 | if (this.Server.IsStarting)
485 | {
486 | try
487 | {
488 | Socket socket = result.AsyncState as Socket;
489 | SocketError error;
490 | int size = this.Client.EndReceive(result, out error);
491 | if (size > 0)
492 | {
493 | SocketUtils.Send(this.Proxy.Client, _ClientBuffer, 0, size);
494 |
495 | if (this.Server.IsStarting)
496 | this.Client.BeginReceive(_ClientBuffer, 0, _ClientBuffer.Length, SocketFlags.None, this.OnClientReceive, this.Client);
497 | }
498 | else
499 | {
500 | this.Close();
501 | }
502 |
503 | }
504 | catch (Exception ex)
505 | {
506 | this.Server.WriteLineLog("An error occurred : " + ex.Message);
507 | }
508 | }
509 | }
510 |
511 |
512 |
513 | private void OnProxyReceive(IAsyncResult result)
514 | {
515 | if (this.Server.IsStarting)
516 | {
517 | try
518 | {
519 | Socket socket = result.AsyncState as Socket;
520 | SocketError error;
521 | int size = socket.EndReceive(result, out error);
522 | if (size > 0)
523 | {
524 | SocketUtils.Send(this.Client, _ProxyBuffer, 0, size);
525 | if (this.Server.IsStarting)
526 | socket.BeginReceive(_ProxyBuffer, 0, _ProxyBuffer.Length, SocketFlags.None, this.OnProxyReceive, socket);
527 | }
528 | else
529 | {
530 | this.Close();
531 | }
532 | }
533 | catch (Exception ex)
534 | {
535 | this.Server.WriteLineLog("An error occurred : " + ex.Message);
536 | }
537 | }
538 | }
539 | private void Close()
540 | {
541 | try
542 | {
543 | if (this.Client != null)
544 | {
545 | this.Server.WriteLineLog(string.Format("MarsNATRP_Server has closed the connection with {1} at {0}.", DateTime.Now, this.Client.RemoteEndPoint));
546 | this.Client.Close(3);
547 | this.Client = null;
548 | }
549 | if (this.Proxy != null)
550 | {
551 | this.Server.WriteLineLog(string.Format("MarsNATRP_Server has closed the connection with {1} at {0}.", DateTime.Now, this.Proxy.Client.RemoteEndPoint));
552 | this.Proxy.Close();
553 | this.Proxy = null;
554 | }
555 | }
556 | catch (Exception ex)
557 | {
558 | this.Server.WriteLineLog("An error occurred : " + ex.Message);
559 | }
560 | }
561 |
562 | public static void DoRequest(MarsNATRPServerCore server, Socket client, string clientip, ushort clientport)
563 | {
564 | MarsNATRPServerConnection connection = new MarsNATRPServerConnection(server, client, clientip, clientport);
565 | ThreadPool.QueueUserWorkItem(new WaitCallback(connection.DoRequest));
566 | }
567 | }
568 | }
--------------------------------------------------------------------------------
/MarsNATRP_Server/Core/MarsNATRPServerCore.cs:
--------------------------------------------------------------------------------
1 | /*
2 | Mozilla Public License Version 2.0
3 | ==================================
4 |
5 | 1. Definitions
6 | --------------
7 |
8 | 1.1. "Contributor"
9 | means each individual or legal entity that creates, contributes to
10 | the creation of, or owns Covered Software.
11 |
12 | 1.2. "Contributor Version"
13 | means the combination of the Contributions of others (if any) used
14 | by a Contributor and that particular Contributor's Contribution.
15 |
16 | 1.3. "Contribution"
17 | means Covered Software of a particular Contributor.
18 |
19 | 1.4. "Covered Software"
20 | means Source Code Form to which the initial Contributor has attached
21 | the notice in Exhibit A, the Executable Form of such Source Code
22 | Form, and Modifications of such Source Code Form, in each case
23 | including portions thereof.
24 |
25 | 1.5. "Incompatible With Secondary Licenses"
26 | means
27 |
28 | (a) that the initial Contributor has attached the notice described
29 | in Exhibit B to the Covered Software; or
30 |
31 | (b) that the Covered Software was made available under the terms of
32 | version 1.1 or earlier of the License, but not also under the
33 | terms of a Secondary License.
34 |
35 | 1.6. "Executable Form"
36 | means any form of the work other than Source Code Form.
37 |
38 | 1.7. "Larger Work"
39 | means a work that combines Covered Software with other material, in
40 | a separate file or files, that is not Covered Software.
41 |
42 | 1.8. "License"
43 | means this document.
44 |
45 | 1.9. "Licensable"
46 | means having the right to grant, to the maximum extent possible,
47 | whether at the time of the initial grant or subsequently, any and
48 | all of the rights conveyed by this License.
49 |
50 | 1.10. "Modifications"
51 | means any of the following:
52 |
53 | (a) any file in Source Code Form that results from an addition to,
54 | deletion from, or modification of the contents of Covered
55 | Software; or
56 |
57 | (b) any new file in Source Code Form that contains any Covered
58 | Software.
59 |
60 | 1.11. "Patent Claims" of a Contributor
61 | means any patent claim(s), including without limitation, method,
62 | process, and apparatus claims, in any patent Licensable by such
63 | Contributor that would be infringed, but for the grant of the
64 | License, by the making, using, selling, offering for sale, having
65 | made, import, or transfer of either its Contributions or its
66 | Contributor Version.
67 |
68 | 1.12. "Secondary License"
69 | means either the GNU General Public License, Version 2.0, the GNU
70 | Lesser General Public License, Version 2.1, the GNU Affero General
71 | Public License, Version 3.0, or any later versions of those
72 | licenses.
73 |
74 | 1.13. "Source Code Form"
75 | means the form of the work preferred for making modifications.
76 |
77 | 1.14. "You" (or "Your")
78 | means an individual or a legal entity exercising rights under this
79 | License. For legal entities, "You" includes any entity that
80 | controls, is controlled by, or is under common control with You. For
81 | purposes of this definition, "control" means (a) the power, direct
82 | or indirect, to cause the direction or management of such entity,
83 | whether by contract or otherwise, or (b) ownership of more than
84 | fifty percent (50%) of the outstanding shares or beneficial
85 | ownership of such entity.
86 |
87 | 2. License Grants and Conditions
88 | --------------------------------
89 |
90 | 2.1. Grants
91 |
92 | Each Contributor hereby grants You a world-wide, royalty-free,
93 | non-exclusive license:
94 |
95 | (a) under intellectual property rights (other than patent or trademark)
96 | Licensable by such Contributor to use, reproduce, make available,
97 | modify, display, perform, distribute, and otherwise exploit its
98 | Contributions, either on an unmodified basis, with Modifications, or
99 | as part of a Larger Work; and
100 |
101 | (b) under Patent Claims of such Contributor to make, use, sell, offer
102 | for sale, have made, import, and otherwise transfer either its
103 | Contributions or its Contributor Version.
104 |
105 | 2.2. Effective Date
106 |
107 | The licenses granted in Section 2.1 with respect to any Contribution
108 | become effective for each Contribution on the date the Contributor first
109 | distributes such Contribution.
110 |
111 | 2.3. Limitations on Grant Scope
112 |
113 | The licenses granted in this Section 2 are the only rights granted under
114 | this License. No additional rights or licenses will be implied from the
115 | distribution or licensing of Covered Software under this License.
116 | Notwithstanding Section 2.1(b) above, no patent license is granted by a
117 | Contributor:
118 |
119 | (a) for any code that a Contributor has removed from Covered Software;
120 | or
121 |
122 | (b) for infringements caused by: (i) Your and any other third party's
123 | modifications of Covered Software, or (ii) the combination of its
124 | Contributions with other software (except as part of its Contributor
125 | Version); or
126 |
127 | (c) under Patent Claims infringed by Covered Software in the absence of
128 | its Contributions.
129 |
130 | This License does not grant any rights in the trademarks, service marks,
131 | or logos of any Contributor (except as may be necessary to comply with
132 | the notice requirements in Section 3.4).
133 |
134 | 2.4. Subsequent Licenses
135 |
136 | No Contributor makes additional grants as a result of Your choice to
137 | distribute the Covered Software under a subsequent version of this
138 | License (see Section 10.2) or under the terms of a Secondary License (if
139 | permitted under the terms of Section 3.3).
140 |
141 | 2.5. Representation
142 |
143 | Each Contributor represents that the Contributor believes its
144 | Contributions are its original creation(s) or it has sufficient rights
145 | to grant the rights to its Contributions conveyed by this License.
146 |
147 | 2.6. Fair Use
148 |
149 | This License is not intended to limit any rights You have under
150 | applicable copyright doctrines of fair use, fair dealing, or other
151 | equivalents.
152 |
153 | 2.7. Conditions
154 |
155 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
156 | in Section 2.1.
157 |
158 | 3. Responsibilities
159 | -------------------
160 |
161 | 3.1. Distribution of Source Form
162 |
163 | All distribution of Covered Software in Source Code Form, including any
164 | Modifications that You create or to which You contribute, must be under
165 | the terms of this License. You must inform recipients that the Source
166 | Code Form of the Covered Software is governed by the terms of this
167 | License, and how they can obtain a copy of this License. You may not
168 | attempt to alter or restrict the recipients' rights in the Source Code
169 | Form.
170 |
171 | 3.2. Distribution of Executable Form
172 |
173 | If You distribute Covered Software in Executable Form then:
174 |
175 | (a) such Covered Software must also be made available in Source Code
176 | Form, as described in Section 3.1, and You must inform recipients of
177 | the Executable Form how they can obtain a copy of such Source Code
178 | Form by reasonable means in a timely manner, at a charge no more
179 | than the cost of distribution to the recipient; and
180 |
181 | (b) You may distribute such Executable Form under the terms of this
182 | License, or sublicense it under different terms, provided that the
183 | license for the Executable Form does not attempt to limit or alter
184 | the recipients' rights in the Source Code Form under this License.
185 |
186 | 3.3. Distribution of a Larger Work
187 |
188 | You may create and distribute a Larger Work under terms of Your choice,
189 | provided that You also comply with the requirements of this License for
190 | the Covered Software. If the Larger Work is a combination of Covered
191 | Software with a work governed by one or more Secondary Licenses, and the
192 | Covered Software is not Incompatible With Secondary Licenses, this
193 | License permits You to additionally distribute such Covered Software
194 | under the terms of such Secondary License(s), so that the recipient of
195 | the Larger Work may, at their option, further distribute the Covered
196 | Software under the terms of either this License or such Secondary
197 | License(s).
198 |
199 | 3.4. Notices
200 |
201 | You may not remove or alter the substance of any license notices
202 | (including copyright notices, patent notices, disclaimers of warranty,
203 | or limitations of liability) contained within the Source Code Form of
204 | the Covered Software, except that You may alter any license notices to
205 | the extent required to remedy known factual inaccuracies.
206 |
207 | 3.5. Application of Additional Terms
208 |
209 | You may choose to offer, and to charge a fee for, warranty, support,
210 | indemnity or liability obligations to one or more recipients of Covered
211 | Software. However, You may do so only on Your own behalf, and not on
212 | behalf of any Contributor. You must make it absolutely clear that any
213 | such warranty, support, indemnity, or liability obligation is offered by
214 | You alone, and You hereby agree to indemnify every Contributor for any
215 | liability incurred by such Contributor as a result of warranty, support,
216 | indemnity or liability terms You offer. You may include additional
217 | disclaimers of warranty and limitations of liability specific to any
218 | jurisdiction.
219 |
220 | 4. Inability to Comply Due to Statute or Regulation
221 | ---------------------------------------------------
222 |
223 | If it is impossible for You to comply with any of the terms of this
224 | License with respect to some or all of the Covered Software due to
225 | statute, judicial order, or regulation then You must: (a) comply with
226 | the terms of this License to the maximum extent possible; and (b)
227 | describe the limitations and the code they affect. Such description must
228 | be placed in a text file included with all distributions of the Covered
229 | Software under this License. Except to the extent prohibited by statute
230 | or regulation, such description must be sufficiently detailed for a
231 | recipient of ordinary skill to be able to understand it.
232 |
233 | 5. Termination
234 | --------------
235 |
236 | 5.1. The rights granted under this License will terminate automatically
237 | if You fail to comply with any of its terms. However, if You become
238 | compliant, then the rights granted under this License from a particular
239 | Contributor are reinstated (a) provisionally, unless and until such
240 | Contributor explicitly and finally terminates Your grants, and (b) on an
241 | ongoing basis, if such Contributor fails to notify You of the
242 | non-compliance by some reasonable means prior to 60 days after You have
243 | come back into compliance. Moreover, Your grants from a particular
244 | Contributor are reinstated on an ongoing basis if such Contributor
245 | notifies You of the non-compliance by some reasonable means, this is the
246 | first time You have received notice of non-compliance with this License
247 | from such Contributor, and You become compliant prior to 30 days after
248 | Your receipt of the notice.
249 |
250 | 5.2. If You initiate litigation against any entity by asserting a patent
251 | infringement claim (excluding declaratory judgment actions,
252 | counter-claims, and cross-claims) alleging that a Contributor Version
253 | directly or indirectly infringes any patent, then the rights granted to
254 | You by any and all Contributors for the Covered Software under Section
255 | 2.1 of this License shall terminate.
256 |
257 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
258 | end user license agreements (excluding distributors and resellers) which
259 | have been validly granted by You or Your distributors under this License
260 | prior to termination shall survive termination.
261 |
262 | ************************************************************************
263 | * *
264 | * 6. Disclaimer of Warranty *
265 | * ------------------------- *
266 | * *
267 | * Covered Software is provided under this License on an "as is" *
268 | * basis, without warranty of any kind, either expressed, implied, or *
269 | * statutory, including, without limitation, warranties that the *
270 | * Covered Software is free of defects, merchantable, fit for a *
271 | * particular purpose or non-infringing. The entire risk as to the *
272 | * quality and performance of the Covered Software is with You. *
273 | * Should any Covered Software prove defective in any respect, You *
274 | * (not any Contributor) assume the cost of any necessary servicing, *
275 | * repair, or correction. This disclaimer of warranty constitutes an *
276 | * essential part of this License. No use of any Covered Software is *
277 | * authorized under this License except under this disclaimer. *
278 | * *
279 | ************************************************************************
280 |
281 | ************************************************************************
282 | * *
283 | * 7. Limitation of Liability *
284 | * -------------------------- *
285 | * *
286 | * Under no circumstances and under no legal theory, whether tort *
287 | * (including negligence), contract, or otherwise, shall any *
288 | * Contributor, or anyone who distributes Covered Software as *
289 | * permitted above, be liable to You for any direct, indirect, *
290 | * special, incidental, or consequential damages of any character *
291 | * including, without limitation, damages for lost profits, loss of *
292 | * goodwill, work stoppage, computer failure or malfunction, or any *
293 | * and all other commercial damages or losses, even if such party *
294 | * shall have been informed of the possibility of such damages. This *
295 | * limitation of liability shall not apply to liability for death or *
296 | * personal injury resulting from such party's negligence to the *
297 | * extent applicable law prohibits such limitation. Some *
298 | * jurisdictions do not allow the exclusion or limitation of *
299 | * incidental or consequential damages, so this exclusion and *
300 | * limitation may not apply to You. *
301 | * *
302 | ************************************************************************
303 |
304 | 8. Litigation
305 | -------------
306 |
307 | Any litigation relating to this License may be brought only in the
308 | courts of a jurisdiction where the defendant maintains its principal
309 | place of business and such litigation shall be governed by laws of that
310 | jurisdiction, without reference to its conflict-of-law provisions.
311 | Nothing in this Section shall prevent a party's ability to bring
312 | cross-claims or counter-claims.
313 |
314 | 9. Miscellaneous
315 | ----------------
316 |
317 | This License represents the complete agreement concerning the subject
318 | matter hereof. If any provision of this License is held to be
319 | unenforceable, such provision shall be reformed only to the extent
320 | necessary to make it enforceable. Any law or regulation which provides
321 | that the language of a contract shall be construed against the drafter
322 | shall not be used to construe this License against a Contributor.
323 |
324 | 10. Versions of the License
325 | ---------------------------
326 |
327 | 10.1. New Versions
328 |
329 | Mozilla Foundation is the license steward. Except as provided in Section
330 | 10.3, no one other than the license steward has the right to modify or
331 | publish new versions of this License. Each version will be given a
332 | distinguishing version number.
333 |
334 | 10.2. Effect of New Versions
335 |
336 | You may distribute the Covered Software under the terms of the version
337 | of the License under which You originally received the Covered Software,
338 | or under the terms of any subsequent version published by the license
339 | steward.
340 |
341 | 10.3. Modified Versions
342 |
343 | If you create software not governed by this License, and you want to
344 | create a new license for such software, you may create and use a
345 | modified version of this License if you rename the license and remove
346 | any references to the name of the license steward (except to note that
347 | such modified license differs from this License).
348 |
349 | 10.4. Distributing Source Code Form that is Incompatible With Secondary
350 | Licenses
351 |
352 | If You choose to distribute Source Code Form that is Incompatible With
353 | Secondary Licenses under the terms of this version of the License, the
354 | notice described in Exhibit B of this License must be attached.
355 |
356 | Exhibit A - Source Code Form License Notice
357 | -------------------------------------------
358 |
359 | This Source Code Form is subject to the terms of the Mozilla Public
360 | License, v. 2.0. If a copy of the MPL was not distributed with this
361 | file, You can obtain one at http://mozilla.org/MPL/2.0/.
362 |
363 | If it is not possible or desirable to put the notice in a particular
364 | file, then You may include the notice in a location (such as a LICENSE
365 | file in a relevant directory) where a recipient would be likely to look
366 | for such a notice.
367 |
368 | You may add additional accurate notices of copyright ownership.
369 |
370 | Exhibit B - "Incompatible With Secondary Licenses" Notice
371 | ---------------------------------------------------------
372 |
373 | This Source Code Form is "Incompatible With Secondary Licenses", as
374 | defined by the Mozilla Public License, v. 2.0.
375 |
376 |
377 | */
378 |
379 |
380 | using System;
381 | using System.Net;
382 | using System.Net.Sockets;
383 |
384 | namespace MarsNATRP_Server
385 | {
386 | public class MarsNATRPServerCore
387 | {
388 | public MarsNATRPServerCore(string ListenIP, ushort listenports, string clientip, ushort clientport)
389 | {
390 | this.ListPort = listenports;
391 | this.ListIP = ListenIP;
392 | this.Cliip = clientip;
393 | this.Cliport = clientport;
394 | }
395 | public ushort ListPort
396 | {
397 | get;
398 | private set;
399 | }
400 | public string ListIP
401 | {
402 | get;
403 | private set;
404 | }
405 | public string Cliip
406 | {
407 | get;
408 | private set;
409 | }
410 | public ushort Cliport
411 | {
412 | get;
413 | private set;
414 | }
415 |
416 | public System.IO.TextWriter LogWatcher
417 | {
418 | get;
419 | set;
420 | }
421 |
422 | internal void WriteLineLog(string message)
423 | {
424 |
425 | if (this.LogWatcher != null) this.LogWatcher.WriteLine(message);
426 | }
427 |
428 |
429 | private TcpListener _Listener;
430 | internal bool IsStarting
431 | {
432 | get;
433 | private set;
434 | }
435 |
436 |
437 | public void StartServer()
438 | {
439 | if (!this.IsStarting)
440 | {
441 |
442 | try
443 | {
444 | this._Listener = new TcpListener(IPAddress.Parse(this.ListIP), this.ListPort);
445 | this._Listener.Start();
446 | this._Listener.BeginAcceptSocket(this.OnBeginAcceptSocket, this._Listener);
447 | this.IsStarting = true;
448 | this.WriteLineLog(string.Format("MarsNATRP_Server has started at {0}.", DateTime.Now));
449 | }
450 | catch (Exception ex)
451 | {
452 |
453 | Console.WriteLine(ex.Message);
454 | System.Environment.Exit(0);
455 | }
456 | }
457 | }
458 |
459 | public void StopServer()
460 | {
461 | if (this.IsStarting)
462 | {
463 | this.IsStarting = false;
464 | this._Listener.Stop();
465 | this._Listener = null;
466 | this.WriteLineLog(string.Format("MarsNATRP_Server has stopped at {0}.", DateTime.Now));
467 | }
468 | }
469 |
470 |
471 | private void OnBeginAcceptSocket(IAsyncResult async)
472 | {
473 | TcpListener listener = async.AsyncState as TcpListener;
474 | try
475 | {
476 | Socket client = listener.EndAcceptSocket(async);
477 | this.WriteLineLog(string.Format("MarsNATRP_Server has received connecting request from {1} at {0}...", DateTime.Now, client.RemoteEndPoint));
478 |
479 | MarsNATRPServerConnection.DoRequest(this, client, this.Cliip, this.Cliport);
480 | if (this.IsStarting)
481 | {
482 | listener.BeginAcceptSocket(this.OnBeginAcceptSocket, listener);
483 | }
484 | }
485 | catch (ObjectDisposedException) { }
486 | catch (Exception ex)
487 | {
488 | this.WriteLineLog(string.Format("An Exception ( {1} ) occurred at {0}", DateTime.Now, ex.Message));
489 | }
490 | }
491 | }
492 | }
--------------------------------------------------------------------------------
/MarsNATRP_Server/Core/SocketUtils.cs:
--------------------------------------------------------------------------------
1 | /*
2 | Mozilla Public License Version 2.0
3 | ==================================
4 |
5 | 1. Definitions
6 | --------------
7 |
8 | 1.1. "Contributor"
9 | means each individual or legal entity that creates, contributes to
10 | the creation of, or owns Covered Software.
11 |
12 | 1.2. "Contributor Version"
13 | means the combination of the Contributions of others (if any) used
14 | by a Contributor and that particular Contributor's Contribution.
15 |
16 | 1.3. "Contribution"
17 | means Covered Software of a particular Contributor.
18 |
19 | 1.4. "Covered Software"
20 | means Source Code Form to which the initial Contributor has attached
21 | the notice in Exhibit A, the Executable Form of such Source Code
22 | Form, and Modifications of such Source Code Form, in each case
23 | including portions thereof.
24 |
25 | 1.5. "Incompatible With Secondary Licenses"
26 | means
27 |
28 | (a) that the initial Contributor has attached the notice described
29 | in Exhibit B to the Covered Software; or
30 |
31 | (b) that the Covered Software was made available under the terms of
32 | version 1.1 or earlier of the License, but not also under the
33 | terms of a Secondary License.
34 |
35 | 1.6. "Executable Form"
36 | means any form of the work other than Source Code Form.
37 |
38 | 1.7. "Larger Work"
39 | means a work that combines Covered Software with other material, in
40 | a separate file or files, that is not Covered Software.
41 |
42 | 1.8. "License"
43 | means this document.
44 |
45 | 1.9. "Licensable"
46 | means having the right to grant, to the maximum extent possible,
47 | whether at the time of the initial grant or subsequently, any and
48 | all of the rights conveyed by this License.
49 |
50 | 1.10. "Modifications"
51 | means any of the following:
52 |
53 | (a) any file in Source Code Form that results from an addition to,
54 | deletion from, or modification of the contents of Covered
55 | Software; or
56 |
57 | (b) any new file in Source Code Form that contains any Covered
58 | Software.
59 |
60 | 1.11. "Patent Claims" of a Contributor
61 | means any patent claim(s), including without limitation, method,
62 | process, and apparatus claims, in any patent Licensable by such
63 | Contributor that would be infringed, but for the grant of the
64 | License, by the making, using, selling, offering for sale, having
65 | made, import, or transfer of either its Contributions or its
66 | Contributor Version.
67 |
68 | 1.12. "Secondary License"
69 | means either the GNU General Public License, Version 2.0, the GNU
70 | Lesser General Public License, Version 2.1, the GNU Affero General
71 | Public License, Version 3.0, or any later versions of those
72 | licenses.
73 |
74 | 1.13. "Source Code Form"
75 | means the form of the work preferred for making modifications.
76 |
77 | 1.14. "You" (or "Your")
78 | means an individual or a legal entity exercising rights under this
79 | License. For legal entities, "You" includes any entity that
80 | controls, is controlled by, or is under common control with You. For
81 | purposes of this definition, "control" means (a) the power, direct
82 | or indirect, to cause the direction or management of such entity,
83 | whether by contract or otherwise, or (b) ownership of more than
84 | fifty percent (50%) of the outstanding shares or beneficial
85 | ownership of such entity.
86 |
87 | 2. License Grants and Conditions
88 | --------------------------------
89 |
90 | 2.1. Grants
91 |
92 | Each Contributor hereby grants You a world-wide, royalty-free,
93 | non-exclusive license:
94 |
95 | (a) under intellectual property rights (other than patent or trademark)
96 | Licensable by such Contributor to use, reproduce, make available,
97 | modify, display, perform, distribute, and otherwise exploit its
98 | Contributions, either on an unmodified basis, with Modifications, or
99 | as part of a Larger Work; and
100 |
101 | (b) under Patent Claims of such Contributor to make, use, sell, offer
102 | for sale, have made, import, and otherwise transfer either its
103 | Contributions or its Contributor Version.
104 |
105 | 2.2. Effective Date
106 |
107 | The licenses granted in Section 2.1 with respect to any Contribution
108 | become effective for each Contribution on the date the Contributor first
109 | distributes such Contribution.
110 |
111 | 2.3. Limitations on Grant Scope
112 |
113 | The licenses granted in this Section 2 are the only rights granted under
114 | this License. No additional rights or licenses will be implied from the
115 | distribution or licensing of Covered Software under this License.
116 | Notwithstanding Section 2.1(b) above, no patent license is granted by a
117 | Contributor:
118 |
119 | (a) for any code that a Contributor has removed from Covered Software;
120 | or
121 |
122 | (b) for infringements caused by: (i) Your and any other third party's
123 | modifications of Covered Software, or (ii) the combination of its
124 | Contributions with other software (except as part of its Contributor
125 | Version); or
126 |
127 | (c) under Patent Claims infringed by Covered Software in the absence of
128 | its Contributions.
129 |
130 | This License does not grant any rights in the trademarks, service marks,
131 | or logos of any Contributor (except as may be necessary to comply with
132 | the notice requirements in Section 3.4).
133 |
134 | 2.4. Subsequent Licenses
135 |
136 | No Contributor makes additional grants as a result of Your choice to
137 | distribute the Covered Software under a subsequent version of this
138 | License (see Section 10.2) or under the terms of a Secondary License (if
139 | permitted under the terms of Section 3.3).
140 |
141 | 2.5. Representation
142 |
143 | Each Contributor represents that the Contributor believes its
144 | Contributions are its original creation(s) or it has sufficient rights
145 | to grant the rights to its Contributions conveyed by this License.
146 |
147 | 2.6. Fair Use
148 |
149 | This License is not intended to limit any rights You have under
150 | applicable copyright doctrines of fair use, fair dealing, or other
151 | equivalents.
152 |
153 | 2.7. Conditions
154 |
155 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
156 | in Section 2.1.
157 |
158 | 3. Responsibilities
159 | -------------------
160 |
161 | 3.1. Distribution of Source Form
162 |
163 | All distribution of Covered Software in Source Code Form, including any
164 | Modifications that You create or to which You contribute, must be under
165 | the terms of this License. You must inform recipients that the Source
166 | Code Form of the Covered Software is governed by the terms of this
167 | License, and how they can obtain a copy of this License. You may not
168 | attempt to alter or restrict the recipients' rights in the Source Code
169 | Form.
170 |
171 | 3.2. Distribution of Executable Form
172 |
173 | If You distribute Covered Software in Executable Form then:
174 |
175 | (a) such Covered Software must also be made available in Source Code
176 | Form, as described in Section 3.1, and You must inform recipients of
177 | the Executable Form how they can obtain a copy of such Source Code
178 | Form by reasonable means in a timely manner, at a charge no more
179 | than the cost of distribution to the recipient; and
180 |
181 | (b) You may distribute such Executable Form under the terms of this
182 | License, or sublicense it under different terms, provided that the
183 | license for the Executable Form does not attempt to limit or alter
184 | the recipients' rights in the Source Code Form under this License.
185 |
186 | 3.3. Distribution of a Larger Work
187 |
188 | You may create and distribute a Larger Work under terms of Your choice,
189 | provided that You also comply with the requirements of this License for
190 | the Covered Software. If the Larger Work is a combination of Covered
191 | Software with a work governed by one or more Secondary Licenses, and the
192 | Covered Software is not Incompatible With Secondary Licenses, this
193 | License permits You to additionally distribute such Covered Software
194 | under the terms of such Secondary License(s), so that the recipient of
195 | the Larger Work may, at their option, further distribute the Covered
196 | Software under the terms of either this License or such Secondary
197 | License(s).
198 |
199 | 3.4. Notices
200 |
201 | You may not remove or alter the substance of any license notices
202 | (including copyright notices, patent notices, disclaimers of warranty,
203 | or limitations of liability) contained within the Source Code Form of
204 | the Covered Software, except that You may alter any license notices to
205 | the extent required to remedy known factual inaccuracies.
206 |
207 | 3.5. Application of Additional Terms
208 |
209 | You may choose to offer, and to charge a fee for, warranty, support,
210 | indemnity or liability obligations to one or more recipients of Covered
211 | Software. However, You may do so only on Your own behalf, and not on
212 | behalf of any Contributor. You must make it absolutely clear that any
213 | such warranty, support, indemnity, or liability obligation is offered by
214 | You alone, and You hereby agree to indemnify every Contributor for any
215 | liability incurred by such Contributor as a result of warranty, support,
216 | indemnity or liability terms You offer. You may include additional
217 | disclaimers of warranty and limitations of liability specific to any
218 | jurisdiction.
219 |
220 | 4. Inability to Comply Due to Statute or Regulation
221 | ---------------------------------------------------
222 |
223 | If it is impossible for You to comply with any of the terms of this
224 | License with respect to some or all of the Covered Software due to
225 | statute, judicial order, or regulation then You must: (a) comply with
226 | the terms of this License to the maximum extent possible; and (b)
227 | describe the limitations and the code they affect. Such description must
228 | be placed in a text file included with all distributions of the Covered
229 | Software under this License. Except to the extent prohibited by statute
230 | or regulation, such description must be sufficiently detailed for a
231 | recipient of ordinary skill to be able to understand it.
232 |
233 | 5. Termination
234 | --------------
235 |
236 | 5.1. The rights granted under this License will terminate automatically
237 | if You fail to comply with any of its terms. However, if You become
238 | compliant, then the rights granted under this License from a particular
239 | Contributor are reinstated (a) provisionally, unless and until such
240 | Contributor explicitly and finally terminates Your grants, and (b) on an
241 | ongoing basis, if such Contributor fails to notify You of the
242 | non-compliance by some reasonable means prior to 60 days after You have
243 | come back into compliance. Moreover, Your grants from a particular
244 | Contributor are reinstated on an ongoing basis if such Contributor
245 | notifies You of the non-compliance by some reasonable means, this is the
246 | first time You have received notice of non-compliance with this License
247 | from such Contributor, and You become compliant prior to 30 days after
248 | Your receipt of the notice.
249 |
250 | 5.2. If You initiate litigation against any entity by asserting a patent
251 | infringement claim (excluding declaratory judgment actions,
252 | counter-claims, and cross-claims) alleging that a Contributor Version
253 | directly or indirectly infringes any patent, then the rights granted to
254 | You by any and all Contributors for the Covered Software under Section
255 | 2.1 of this License shall terminate.
256 |
257 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
258 | end user license agreements (excluding distributors and resellers) which
259 | have been validly granted by You or Your distributors under this License
260 | prior to termination shall survive termination.
261 |
262 | ************************************************************************
263 | * *
264 | * 6. Disclaimer of Warranty *
265 | * ------------------------- *
266 | * *
267 | * Covered Software is provided under this License on an "as is" *
268 | * basis, without warranty of any kind, either expressed, implied, or *
269 | * statutory, including, without limitation, warranties that the *
270 | * Covered Software is free of defects, merchantable, fit for a *
271 | * particular purpose or non-infringing. The entire risk as to the *
272 | * quality and performance of the Covered Software is with You. *
273 | * Should any Covered Software prove defective in any respect, You *
274 | * (not any Contributor) assume the cost of any necessary servicing, *
275 | * repair, or correction. This disclaimer of warranty constitutes an *
276 | * essential part of this License. No use of any Covered Software is *
277 | * authorized under this License except under this disclaimer. *
278 | * *
279 | ************************************************************************
280 |
281 | ************************************************************************
282 | * *
283 | * 7. Limitation of Liability *
284 | * -------------------------- *
285 | * *
286 | * Under no circumstances and under no legal theory, whether tort *
287 | * (including negligence), contract, or otherwise, shall any *
288 | * Contributor, or anyone who distributes Covered Software as *
289 | * permitted above, be liable to You for any direct, indirect, *
290 | * special, incidental, or consequential damages of any character *
291 | * including, without limitation, damages for lost profits, loss of *
292 | * goodwill, work stoppage, computer failure or malfunction, or any *
293 | * and all other commercial damages or losses, even if such party *
294 | * shall have been informed of the possibility of such damages. This *
295 | * limitation of liability shall not apply to liability for death or *
296 | * personal injury resulting from such party's negligence to the *
297 | * extent applicable law prohibits such limitation. Some *
298 | * jurisdictions do not allow the exclusion or limitation of *
299 | * incidental or consequential damages, so this exclusion and *
300 | * limitation may not apply to You. *
301 | * *
302 | ************************************************************************
303 |
304 | 8. Litigation
305 | -------------
306 |
307 | Any litigation relating to this License may be brought only in the
308 | courts of a jurisdiction where the defendant maintains its principal
309 | place of business and such litigation shall be governed by laws of that
310 | jurisdiction, without reference to its conflict-of-law provisions.
311 | Nothing in this Section shall prevent a party's ability to bring
312 | cross-claims or counter-claims.
313 |
314 | 9. Miscellaneous
315 | ----------------
316 |
317 | This License represents the complete agreement concerning the subject
318 | matter hereof. If any provision of this License is held to be
319 | unenforceable, such provision shall be reformed only to the extent
320 | necessary to make it enforceable. Any law or regulation which provides
321 | that the language of a contract shall be construed against the drafter
322 | shall not be used to construe this License against a Contributor.
323 |
324 | 10. Versions of the License
325 | ---------------------------
326 |
327 | 10.1. New Versions
328 |
329 | Mozilla Foundation is the license steward. Except as provided in Section
330 | 10.3, no one other than the license steward has the right to modify or
331 | publish new versions of this License. Each version will be given a
332 | distinguishing version number.
333 |
334 | 10.2. Effect of New Versions
335 |
336 | You may distribute the Covered Software under the terms of the version
337 | of the License under which You originally received the Covered Software,
338 | or under the terms of any subsequent version published by the license
339 | steward.
340 |
341 | 10.3. Modified Versions
342 |
343 | If you create software not governed by this License, and you want to
344 | create a new license for such software, you may create and use a
345 | modified version of this License if you rename the license and remove
346 | any references to the name of the license steward (except to note that
347 | such modified license differs from this License).
348 |
349 | 10.4. Distributing Source Code Form that is Incompatible With Secondary
350 | Licenses
351 |
352 | If You choose to distribute Source Code Form that is Incompatible With
353 | Secondary Licenses under the terms of this version of the License, the
354 | notice described in Exhibit B of this License must be attached.
355 |
356 | Exhibit A - Source Code Form License Notice
357 | -------------------------------------------
358 |
359 | This Source Code Form is subject to the terms of the Mozilla Public
360 | License, v. 2.0. If a copy of the MPL was not distributed with this
361 | file, You can obtain one at http://mozilla.org/MPL/2.0/.
362 |
363 | If it is not possible or desirable to put the notice in a particular
364 | file, then You may include the notice in a location (such as a LICENSE
365 | file in a relevant directory) where a recipient would be likely to look
366 | for such a notice.
367 |
368 | You may add additional accurate notices of copyright ownership.
369 |
370 | Exhibit B - "Incompatible With Secondary Licenses" Notice
371 | ---------------------------------------------------------
372 |
373 | This Source Code Form is "Incompatible With Secondary Licenses", as
374 | defined by the Mozilla Public License, v. 2.0.
375 |
376 |
377 | */
378 |
379 |
380 | using System;
381 | using System.Net.Sockets;
382 |
383 | namespace MarsNATRP_Server
384 | {
385 | public static class SocketUtils
386 | {
387 |
388 | public const int TIMEOUT = 30000000;
389 |
390 | internal static bool Receive(Socket client, uint maxSize, out byte[] buffer)
391 | {
392 | buffer = new byte[0];
393 | int offset = 0;
394 | if (client.Connected)
395 | {
396 | try
397 | {
398 | buffer = new byte[maxSize];
399 | do
400 | {
401 | if (client.Available == 0)
402 | {
403 |
404 | if (!client.Poll(TIMEOUT, SelectMode.SelectRead)) break;
405 | if (client.Available == 0) break;
406 | }
407 |
408 | int size = client.Receive(buffer, offset, buffer.Length - offset, SocketFlags.None);
409 | offset += size;
410 |
411 | } while (offset < buffer.Length);
412 |
413 | if (offset > 0 && offset < buffer.Length)
414 | {
415 |
416 | Array.Resize(ref buffer, offset);
417 | }
418 | }
419 | catch
420 | {
421 | offset = 0;
422 | }
423 | }
424 | return offset != 0;
425 | }
426 |
427 | internal static void Send(Socket client, byte[] data)
428 | {
429 | Send(client, data, 0, data.Length);
430 | }
431 | internal static void Send(Socket client, byte[] data, int offset, int size)
432 | {
433 | if (client.Connected)
434 | {
435 | try
436 | {
437 |
438 | if (client.Poll(TIMEOUT, SelectMode.SelectWrite))
439 | {
440 |
441 | client.Send(data, offset, size, SocketFlags.Partial);
442 | }
443 | }
444 | catch { }
445 | }
446 | }
447 | }
448 | }
--------------------------------------------------------------------------------
/MarsNATRP_Server/MarsNATRP_Server.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 | http://ghofamily.sctstu.com
7 | 2018 GhostFamilyStudio all rights reserved.
8 | GhostFamilyStudio
9 | SmartGhost
10 | 1.0.1
11 | false
12 | false
13 |
14 |
15 |
16 |
17 |
18 | 0
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/MarsNATRP_Server/MarsNATRP_Server.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | <_LastSelectedProfileId>C:\Users\Administrator\Desktop\Temporary Projects\MarsNATRP\MarsNATRP_Server\Properties\PublishProfiles\ServerWin64.pubxml
5 |
6 |
--------------------------------------------------------------------------------
/MarsNATRP_Server/Program.cs:
--------------------------------------------------------------------------------
1 | /*
2 | Mozilla Public License Version 2.0
3 | ==================================
4 |
5 | 1. Definitions
6 | --------------
7 |
8 | 1.1. "Contributor"
9 | means each individual or legal entity that creates, contributes to
10 | the creation of, or owns Covered Software.
11 |
12 | 1.2. "Contributor Version"
13 | means the combination of the Contributions of others (if any) used
14 | by a Contributor and that particular Contributor's Contribution.
15 |
16 | 1.3. "Contribution"
17 | means Covered Software of a particular Contributor.
18 |
19 | 1.4. "Covered Software"
20 | means Source Code Form to which the initial Contributor has attached
21 | the notice in Exhibit A, the Executable Form of such Source Code
22 | Form, and Modifications of such Source Code Form, in each case
23 | including portions thereof.
24 |
25 | 1.5. "Incompatible With Secondary Licenses"
26 | means
27 |
28 | (a) that the initial Contributor has attached the notice described
29 | in Exhibit B to the Covered Software; or
30 |
31 | (b) that the Covered Software was made available under the terms of
32 | version 1.1 or earlier of the License, but not also under the
33 | terms of a Secondary License.
34 |
35 | 1.6. "Executable Form"
36 | means any form of the work other than Source Code Form.
37 |
38 | 1.7. "Larger Work"
39 | means a work that combines Covered Software with other material, in
40 | a separate file or files, that is not Covered Software.
41 |
42 | 1.8. "License"
43 | means this document.
44 |
45 | 1.9. "Licensable"
46 | means having the right to grant, to the maximum extent possible,
47 | whether at the time of the initial grant or subsequently, any and
48 | all of the rights conveyed by this License.
49 |
50 | 1.10. "Modifications"
51 | means any of the following:
52 |
53 | (a) any file in Source Code Form that results from an addition to,
54 | deletion from, or modification of the contents of Covered
55 | Software; or
56 |
57 | (b) any new file in Source Code Form that contains any Covered
58 | Software.
59 |
60 | 1.11. "Patent Claims" of a Contributor
61 | means any patent claim(s), including without limitation, method,
62 | process, and apparatus claims, in any patent Licensable by such
63 | Contributor that would be infringed, but for the grant of the
64 | License, by the making, using, selling, offering for sale, having
65 | made, import, or transfer of either its Contributions or its
66 | Contributor Version.
67 |
68 | 1.12. "Secondary License"
69 | means either the GNU General Public License, Version 2.0, the GNU
70 | Lesser General Public License, Version 2.1, the GNU Affero General
71 | Public License, Version 3.0, or any later versions of those
72 | licenses.
73 |
74 | 1.13. "Source Code Form"
75 | means the form of the work preferred for making modifications.
76 |
77 | 1.14. "You" (or "Your")
78 | means an individual or a legal entity exercising rights under this
79 | License. For legal entities, "You" includes any entity that
80 | controls, is controlled by, or is under common control with You. For
81 | purposes of this definition, "control" means (a) the power, direct
82 | or indirect, to cause the direction or management of such entity,
83 | whether by contract or otherwise, or (b) ownership of more than
84 | fifty percent (50%) of the outstanding shares or beneficial
85 | ownership of such entity.
86 |
87 | 2. License Grants and Conditions
88 | --------------------------------
89 |
90 | 2.1. Grants
91 |
92 | Each Contributor hereby grants You a world-wide, royalty-free,
93 | non-exclusive license:
94 |
95 | (a) under intellectual property rights (other than patent or trademark)
96 | Licensable by such Contributor to use, reproduce, make available,
97 | modify, display, perform, distribute, and otherwise exploit its
98 | Contributions, either on an unmodified basis, with Modifications, or
99 | as part of a Larger Work; and
100 |
101 | (b) under Patent Claims of such Contributor to make, use, sell, offer
102 | for sale, have made, import, and otherwise transfer either its
103 | Contributions or its Contributor Version.
104 |
105 | 2.2. Effective Date
106 |
107 | The licenses granted in Section 2.1 with respect to any Contribution
108 | become effective for each Contribution on the date the Contributor first
109 | distributes such Contribution.
110 |
111 | 2.3. Limitations on Grant Scope
112 |
113 | The licenses granted in this Section 2 are the only rights granted under
114 | this License. No additional rights or licenses will be implied from the
115 | distribution or licensing of Covered Software under this License.
116 | Notwithstanding Section 2.1(b) above, no patent license is granted by a
117 | Contributor:
118 |
119 | (a) for any code that a Contributor has removed from Covered Software;
120 | or
121 |
122 | (b) for infringements caused by: (i) Your and any other third party's
123 | modifications of Covered Software, or (ii) the combination of its
124 | Contributions with other software (except as part of its Contributor
125 | Version); or
126 |
127 | (c) under Patent Claims infringed by Covered Software in the absence of
128 | its Contributions.
129 |
130 | This License does not grant any rights in the trademarks, service marks,
131 | or logos of any Contributor (except as may be necessary to comply with
132 | the notice requirements in Section 3.4).
133 |
134 | 2.4. Subsequent Licenses
135 |
136 | No Contributor makes additional grants as a result of Your choice to
137 | distribute the Covered Software under a subsequent version of this
138 | License (see Section 10.2) or under the terms of a Secondary License (if
139 | permitted under the terms of Section 3.3).
140 |
141 | 2.5. Representation
142 |
143 | Each Contributor represents that the Contributor believes its
144 | Contributions are its original creation(s) or it has sufficient rights
145 | to grant the rights to its Contributions conveyed by this License.
146 |
147 | 2.6. Fair Use
148 |
149 | This License is not intended to limit any rights You have under
150 | applicable copyright doctrines of fair use, fair dealing, or other
151 | equivalents.
152 |
153 | 2.7. Conditions
154 |
155 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
156 | in Section 2.1.
157 |
158 | 3. Responsibilities
159 | -------------------
160 |
161 | 3.1. Distribution of Source Form
162 |
163 | All distribution of Covered Software in Source Code Form, including any
164 | Modifications that You create or to which You contribute, must be under
165 | the terms of this License. You must inform recipients that the Source
166 | Code Form of the Covered Software is governed by the terms of this
167 | License, and how they can obtain a copy of this License. You may not
168 | attempt to alter or restrict the recipients' rights in the Source Code
169 | Form.
170 |
171 | 3.2. Distribution of Executable Form
172 |
173 | If You distribute Covered Software in Executable Form then:
174 |
175 | (a) such Covered Software must also be made available in Source Code
176 | Form, as described in Section 3.1, and You must inform recipients of
177 | the Executable Form how they can obtain a copy of such Source Code
178 | Form by reasonable means in a timely manner, at a charge no more
179 | than the cost of distribution to the recipient; and
180 |
181 | (b) You may distribute such Executable Form under the terms of this
182 | License, or sublicense it under different terms, provided that the
183 | license for the Executable Form does not attempt to limit or alter
184 | the recipients' rights in the Source Code Form under this License.
185 |
186 | 3.3. Distribution of a Larger Work
187 |
188 | You may create and distribute a Larger Work under terms of Your choice,
189 | provided that You also comply with the requirements of this License for
190 | the Covered Software. If the Larger Work is a combination of Covered
191 | Software with a work governed by one or more Secondary Licenses, and the
192 | Covered Software is not Incompatible With Secondary Licenses, this
193 | License permits You to additionally distribute such Covered Software
194 | under the terms of such Secondary License(s), so that the recipient of
195 | the Larger Work may, at their option, further distribute the Covered
196 | Software under the terms of either this License or such Secondary
197 | License(s).
198 |
199 | 3.4. Notices
200 |
201 | You may not remove or alter the substance of any license notices
202 | (including copyright notices, patent notices, disclaimers of warranty,
203 | or limitations of liability) contained within the Source Code Form of
204 | the Covered Software, except that You may alter any license notices to
205 | the extent required to remedy known factual inaccuracies.
206 |
207 | 3.5. Application of Additional Terms
208 |
209 | You may choose to offer, and to charge a fee for, warranty, support,
210 | indemnity or liability obligations to one or more recipients of Covered
211 | Software. However, You may do so only on Your own behalf, and not on
212 | behalf of any Contributor. You must make it absolutely clear that any
213 | such warranty, support, indemnity, or liability obligation is offered by
214 | You alone, and You hereby agree to indemnify every Contributor for any
215 | liability incurred by such Contributor as a result of warranty, support,
216 | indemnity or liability terms You offer. You may include additional
217 | disclaimers of warranty and limitations of liability specific to any
218 | jurisdiction.
219 |
220 | 4. Inability to Comply Due to Statute or Regulation
221 | ---------------------------------------------------
222 |
223 | If it is impossible for You to comply with any of the terms of this
224 | License with respect to some or all of the Covered Software due to
225 | statute, judicial order, or regulation then You must: (a) comply with
226 | the terms of this License to the maximum extent possible; and (b)
227 | describe the limitations and the code they affect. Such description must
228 | be placed in a text file included with all distributions of the Covered
229 | Software under this License. Except to the extent prohibited by statute
230 | or regulation, such description must be sufficiently detailed for a
231 | recipient of ordinary skill to be able to understand it.
232 |
233 | 5. Termination
234 | --------------
235 |
236 | 5.1. The rights granted under this License will terminate automatically
237 | if You fail to comply with any of its terms. However, if You become
238 | compliant, then the rights granted under this License from a particular
239 | Contributor are reinstated (a) provisionally, unless and until such
240 | Contributor explicitly and finally terminates Your grants, and (b) on an
241 | ongoing basis, if such Contributor fails to notify You of the
242 | non-compliance by some reasonable means prior to 60 days after You have
243 | come back into compliance. Moreover, Your grants from a particular
244 | Contributor are reinstated on an ongoing basis if such Contributor
245 | notifies You of the non-compliance by some reasonable means, this is the
246 | first time You have received notice of non-compliance with this License
247 | from such Contributor, and You become compliant prior to 30 days after
248 | Your receipt of the notice.
249 |
250 | 5.2. If You initiate litigation against any entity by asserting a patent
251 | infringement claim (excluding declaratory judgment actions,
252 | counter-claims, and cross-claims) alleging that a Contributor Version
253 | directly or indirectly infringes any patent, then the rights granted to
254 | You by any and all Contributors for the Covered Software under Section
255 | 2.1 of this License shall terminate.
256 |
257 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
258 | end user license agreements (excluding distributors and resellers) which
259 | have been validly granted by You or Your distributors under this License
260 | prior to termination shall survive termination.
261 |
262 | ************************************************************************
263 | * *
264 | * 6. Disclaimer of Warranty *
265 | * ------------------------- *
266 | * *
267 | * Covered Software is provided under this License on an "as is" *
268 | * basis, without warranty of any kind, either expressed, implied, or *
269 | * statutory, including, without limitation, warranties that the *
270 | * Covered Software is free of defects, merchantable, fit for a *
271 | * particular purpose or non-infringing. The entire risk as to the *
272 | * quality and performance of the Covered Software is with You. *
273 | * Should any Covered Software prove defective in any respect, You *
274 | * (not any Contributor) assume the cost of any necessary servicing, *
275 | * repair, or correction. This disclaimer of warranty constitutes an *
276 | * essential part of this License. No use of any Covered Software is *
277 | * authorized under this License except under this disclaimer. *
278 | * *
279 | ************************************************************************
280 |
281 | ************************************************************************
282 | * *
283 | * 7. Limitation of Liability *
284 | * -------------------------- *
285 | * *
286 | * Under no circumstances and under no legal theory, whether tort *
287 | * (including negligence), contract, or otherwise, shall any *
288 | * Contributor, or anyone who distributes Covered Software as *
289 | * permitted above, be liable to You for any direct, indirect, *
290 | * special, incidental, or consequential damages of any character *
291 | * including, without limitation, damages for lost profits, loss of *
292 | * goodwill, work stoppage, computer failure or malfunction, or any *
293 | * and all other commercial damages or losses, even if such party *
294 | * shall have been informed of the possibility of such damages. This *
295 | * limitation of liability shall not apply to liability for death or *
296 | * personal injury resulting from such party's negligence to the *
297 | * extent applicable law prohibits such limitation. Some *
298 | * jurisdictions do not allow the exclusion or limitation of *
299 | * incidental or consequential damages, so this exclusion and *
300 | * limitation may not apply to You. *
301 | * *
302 | ************************************************************************
303 |
304 | 8. Litigation
305 | -------------
306 |
307 | Any litigation relating to this License may be brought only in the
308 | courts of a jurisdiction where the defendant maintains its principal
309 | place of business and such litigation shall be governed by laws of that
310 | jurisdiction, without reference to its conflict-of-law provisions.
311 | Nothing in this Section shall prevent a party's ability to bring
312 | cross-claims or counter-claims.
313 |
314 | 9. Miscellaneous
315 | ----------------
316 |
317 | This License represents the complete agreement concerning the subject
318 | matter hereof. If any provision of this License is held to be
319 | unenforceable, such provision shall be reformed only to the extent
320 | necessary to make it enforceable. Any law or regulation which provides
321 | that the language of a contract shall be construed against the drafter
322 | shall not be used to construe this License against a Contributor.
323 |
324 | 10. Versions of the License
325 | ---------------------------
326 |
327 | 10.1. New Versions
328 |
329 | Mozilla Foundation is the license steward. Except as provided in Section
330 | 10.3, no one other than the license steward has the right to modify or
331 | publish new versions of this License. Each version will be given a
332 | distinguishing version number.
333 |
334 | 10.2. Effect of New Versions
335 |
336 | You may distribute the Covered Software under the terms of the version
337 | of the License under which You originally received the Covered Software,
338 | or under the terms of any subsequent version published by the license
339 | steward.
340 |
341 | 10.3. Modified Versions
342 |
343 | If you create software not governed by this License, and you want to
344 | create a new license for such software, you may create and use a
345 | modified version of this License if you rename the license and remove
346 | any references to the name of the license steward (except to note that
347 | such modified license differs from this License).
348 |
349 | 10.4. Distributing Source Code Form that is Incompatible With Secondary
350 | Licenses
351 |
352 | If You choose to distribute Source Code Form that is Incompatible With
353 | Secondary Licenses under the terms of this version of the License, the
354 | notice described in Exhibit B of this License must be attached.
355 |
356 | Exhibit A - Source Code Form License Notice
357 | -------------------------------------------
358 |
359 | This Source Code Form is subject to the terms of the Mozilla Public
360 | License, v. 2.0. If a copy of the MPL was not distributed with this
361 | file, You can obtain one at http://mozilla.org/MPL/2.0/.
362 |
363 | If it is not possible or desirable to put the notice in a particular
364 | file, then You may include the notice in a location (such as a LICENSE
365 | file in a relevant directory) where a recipient would be likely to look
366 | for such a notice.
367 |
368 | You may add additional accurate notices of copyright ownership.
369 |
370 | Exhibit B - "Incompatible With Secondary Licenses" Notice
371 | ---------------------------------------------------------
372 |
373 | This Source Code Form is "Incompatible With Secondary Licenses", as
374 | defined by the Mozilla Public License, v. 2.0.
375 |
376 |
377 | */
378 |
379 |
380 | using System;
381 | using System.Collections.Generic;
382 | using System.Diagnostics;
383 | using System.Net.Sockets;
384 | using System.Text;
385 |
386 |
387 | namespace MarsNATRP_Server
388 | {
389 | class Program
390 | {
391 |
392 | static void Main(string[] args)
393 | {
394 | ConsoleColor cfc = Console.ForegroundColor;
395 | Console.ForegroundColor = ConsoleColor.White;
396 | Console.WriteLine("Welcome to use MarsNATRP_Server V1.0.1");
397 | Console.WriteLine("Copyright (c) 2018 GhostFamilyStudio. All rights reserved.");
398 | Console.WriteLine("For more information please visit http://ghofamily.sctstu.com");
399 | Console.ForegroundColor = ConsoleColor.Cyan;
400 |
401 | try
402 | {
403 | MarsNATRPServerCore server = new MarsNATRPServerCore(args[0], Convert.ToUInt16(args[1]), args[2], Convert.ToUInt16(args[3]));
404 | Console.WriteLine("Public bind IP:{0}\r\nPublic bind port:{1}\r\nPrivate bind IP:{2}\r\nPriavte bind port:{3}", args[0], args[1], args[2], args[3]);
405 | server.LogWatcher = Console.Out;
406 | server.StartServer();
407 | Console.ReadLine();
408 | }
409 | catch (Exception ex)
410 | {
411 | Console.WriteLine(ex.Message);
412 | }
413 | Console.ForegroundColor = cfc;
414 | }
415 | }
416 | }
417 |
--------------------------------------------------------------------------------
/MarsNATRP_Server/Properties/PublishProfiles/ServerLinux64.pubxml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | FileSystem
8 | Release
9 | Any CPU
10 | netcoreapp2.1
11 | Release\Linux64
12 | linux-x64
13 | true
14 | <_IsPortable>false
15 |
16 |
--------------------------------------------------------------------------------
/MarsNATRP_Server/Properties/PublishProfiles/ServerLinux64.pubxml.user:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/MarsNATRP_Server/Properties/PublishProfiles/ServerPortable.pubxml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | FileSystem
8 | Release
9 | Any CPU
10 | netcoreapp2.1
11 | Release\Portable
12 | false
13 | <_IsPortable>true
14 |
15 |
--------------------------------------------------------------------------------
/MarsNATRP_Server/Properties/PublishProfiles/ServerPortable.pubxml.user:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/MarsNATRP_Server/Properties/PublishProfiles/ServerWin64.pubxml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | FileSystem
8 | Release
9 | Any CPU
10 | netcoreapp2.1
11 | Release\Win64
12 | win-x64
13 | true
14 | <_IsPortable>false
15 |
16 |
--------------------------------------------------------------------------------
/MarsNATRP_Server/Properties/PublishProfiles/ServerWin64.pubxml.user:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/MarsNATRP_Server/obj/MarsNATRP_Server.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "6yNBQh2v/ypAz2pjTm9ISfKBPW9TGPAUWms0kan8pSglvw5LmmJuuphHVybmHpOQDB6LrFXtuSSXeqL6+ValGw==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/MarsNATRP_Server/obj/MarsNATRP_Server.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | C:\Users\Administrator\Desktop\MarsNATRP\MarsNATRP_Server\obj\project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\Administrator\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 4.8.1
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/MarsNATRP_Server/obj/MarsNATRP_Server.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MarsNATRP
2 | Release: https://github.com/SmartGhost0/MarsNATRP/releases
3 |
4 | How To Use
5 | -----
6 |
7 | * You should download the release files or project.The release pack include MarsNATRP_Server and MarsNATRP_Client.This application was written by .netCore which is easy to make the application run on muti-platform. If you do not find the files which can run on your platform,you can just use the portable vision(.netCore Framework is required).
8 |
9 | Run Application
10 | -----
11 |
12 | * MarsNATRP_Client
13 |
14 | Windows:Run MarsNATRP_Client.exe {ServerIP} {ServerPrivatePort} {LocalIP} {LocalPort}
15 |
16 | Linux/Unix:Run MarsNATRP_Client {ServerIP} {ServerPrivatePort} {LocalIP} {LocalPort}
17 |
18 | For example: If you want to map the private port 8888 of public address 10.10.10.10 to the port 80 of local address 127.0.0.1 you should run MarsNATRP_Client like this.
19 |
20 | Win:MarsNATRP_Client.exe 10.10.10.10 8888 127.0.0.1 80
21 |
22 | L/U:MarsNATRP_Client 10.10.10.10 8888 127.0.0.1 80
23 |
24 |
25 | * MarsNATRP_Server
26 |
27 | Windows:Run MarsNATRP_Server.exe {ServerIP} {ServerPublicPort} {ServerIP} {ServerPrivatePort}
28 |
29 | Linux/Unix:Run MarsNATRP_Server {ServerIP} {ServerPublicPort} {ServerIP} {ServerPrivatePort}
30 |
31 | For example: If you want to map the public port 8080 of public address 10.10.10.10 to the port 8888 of address 10.10.10.10 you should run MarsNATRP_Client like this.
32 |
33 | Win:MarsNATRP_Client.exe 10.10.10.10 8080 10.10.10.10 8888
34 |
35 | L/U:MarsNATRP_Client 10.10.10.10 8080 10.10.10.10 8888
36 |
37 | Test
38 | -----
39 |
40 |
41 | * Test Application
42 |
43 | Try to start a website on local IP:Port and Try to visit PublicIP:Port
44 |
45 |
46 | for example: if you run applicaion like the example of "Run Application",you should run website on 127.0.0.1:80 and visit the public server 10.10.10.10:8080
47 |
48 |
49 | * How does it works
50 |
51 | When user connect to 10.10.10.10:8080 the server will listen 10.10.10.10:8888 to accept the connection of client when the client connected the client will connect to 127.0.0.1:80.After this the reverse proxy bridge can create successful.
52 |
--------------------------------------------------------------------------------