PTLib
Version 2.14.3
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
socks.h
Go to the documentation of this file.
1
/*
2
* socks.h
3
*
4
* SOCKS protocol
5
*
6
* Portable Windows Library
7
*
8
* Copyright (c) 1993-2001 Equivalence Pty. Ltd.
9
*
10
* The contents of this file are subject to the Mozilla Public License
11
* Version 1.0 (the "License"); you may not use this file except in
12
* compliance with the License. You may obtain a copy of the License at
13
* http://www.mozilla.org/MPL/
14
*
15
* Software distributed under the License is distributed on an "AS IS"
16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17
* the License for the specific language governing rights and limitations
18
* under the License.
19
*
20
* The Original Code is Portable Windows Library.
21
*
22
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23
*
24
* Contributor(s): ______________________________________.
25
*
26
* $Revision: 28939 $
27
* $Author: csoutheren $
28
* $Date: 2013-01-19 00:50:13 +1100 (Sat, 19 Jan 2013) $
29
*/
30
31
#ifndef PTLIB_SOCKS_H
32
#define PTLIB_SOCKS_H
33
34
#ifdef P_USE_PRAGMA
35
#pragma interface
36
#endif
37
38
39
#include <
ptlib/sockets.h
>
40
41
47
class
PSocksProtocol
48
{
49
public
:
50
PSocksProtocol
(WORD port);
51
virtual
~PSocksProtocol
() { }
52
53
// New functions for class
54
enum
{
55
DefaultServerPort
= 1080
56
};
57
PBoolean
SetServer
(
58
const
PString
& hostname,
59
const
char
* service =
"socks 1080"
60
);
61
PBoolean
SetServer
(
62
const
PString
& hostname,
63
WORD port
64
);
65
70
void
SetAuthentication
(
71
const
PString
& username,
72
const
PString
& password
73
);
74
75
protected
:
76
PBoolean
ConnectSocksServer
(
PTCPSocket
& thisSocket);
77
78
virtual
void
SetErrorCodes
(
PChannel::Errors
errCode,
int
osErr) = 0;
79
80
virtual
PBoolean
SendSocksCommand
(
PTCPSocket
& socket,
81
BYTE command,
82
const
char
* hostname,
83
PIPSocket::Address
addr);
84
virtual
PBoolean
ReceiveSocksResponse
(
PTCPSocket
& socket,
85
PIPSocket::Address
& addr,
86
WORD & port);
87
88
89
PString
serverHost
;
90
WORD
serverPort
;
91
PString
authenticationUsername
;
92
PString
authenticationPassword
;
93
PIPSocket::Address
remoteAddress
;
94
WORD
remotePort
;
95
PIPSocket::Address
localAddress
;
96
WORD
localPort
;
97
};
98
99
102
class
PSocksSocket
:
public
PTCPSocket
,
public
PSocksProtocol
103
{
104
PCLASSINFO
(
PSocksSocket
,
PTCPSocket
)
105
106
public
:
107
PSocksSocket
(
108
WORD
port
= 0
109
);
110
111
// Overrides from class PSocket.
123
virtual
PBoolean
Connect
(
124
const
PString
& address
125
);
126
virtual
PBoolean
Connect
(
127
const
Address
& addr
128
);
129
145
virtual
PBoolean
Listen
(
146
unsigned
queueSize = 5,
147
WORD
port
= 0,
148
Reusability
reuse =
AddressIsExclusive
149
);
150
170
PBoolean
Accept
();
171
virtual
PBoolean
Accept
(
172
PSocket
& socket
173
);
174
175
176
// Overrides from class PIPSocket.
182
virtual
PBoolean
GetLocalAddress
(
183
Address
& addr
184
);
185
virtual
PBoolean
GetLocalAddress
(
186
Address
& addr,
187
WORD &
port
188
);
189
196
virtual
PBoolean
GetPeerAddress
(
197
Address
& addr
198
);
199
virtual
PBoolean
GetPeerAddress
(
200
Address
& addr,
201
WORD & port
202
);
203
204
205
protected
:
206
virtual
void
SetErrorCodes
(
PChannel::Errors
errCode,
int
osErr);
207
P_INT_PTR
TransferHandle
(
PSocksSocket
& destination);
208
209
private
:
210
virtual
PBoolean
Connect
(WORD
localPort
,
const
Address
& addr);
211
};
212
213
216
class
PSocks4Socket
:
public
PSocksSocket
217
{
218
PCLASSINFO
(
PSocks4Socket
,
PSocksSocket
)
219
220
public
:
221
PSocks4Socket
(
222
WORD
port
= 0
223
);
224
PSocks4Socket
(
225
const
PString
& host,
226
WORD
port
= 0
227
);
228
229
// Overrides from class PObject
242
virtual
PObject
*
Clone
()
const
;
243
244
245
protected
:
246
virtual
PBoolean
SendSocksCommand
(
PTCPSocket
& socket,
247
BYTE command,
248
const
char
* hostname,
249
PIPSocket::Address
addr);
250
virtual
PBoolean
ReceiveSocksResponse
(
PTCPSocket
& socket,
251
PIPSocket::Address
& addr,
252
WORD &
port
);
253
};
254
255
258
class
PSocks5Socket
:
public
PSocksSocket
259
{
260
PCLASSINFO
(
PSocks5Socket
,
PSocksSocket
)
261
262
public
:
263
PSocks5Socket
(
264
WORD
port
= 0
265
);
266
PSocks5Socket
(
267
const
PString
& host,
268
WORD
port
= 0
269
);
270
271
// Overrides from class PObject
284
virtual
PObject
*
Clone
()
const
;
285
};
286
287
290
class
PSocksUDPSocket
:
public
PUDPSocket
,
public
PSocksProtocol
291
{
292
PCLASSINFO
(
PSocksUDPSocket
,
PUDPSocket
)
293
294
public
:
295
PSocksUDPSocket
(
296
WORD
port
= 0
297
);
298
PSocksUDPSocket
(
299
const
PString
& host,
300
WORD
port
= 0
301
);
302
303
304
// Overrides from class PObject
317
virtual
PObject
*
Clone
()
const
;
318
319
320
// Overrides from class PSocket.
332
virtual
PBoolean
Connect
(
333
const
PString
& address
// Address of remote machine to connect to.
334
);
335
virtual
PBoolean
Connect
(
336
const
Address
& addr
// Address of remote machine to connect to.
337
);
338
354
virtual
PBoolean
Listen
(
355
unsigned
queueSize = 5,
// Number of pending accepts that may be queued.
356
WORD
port
= 0,
// Port number to use for the connection.
357
Reusability
reuse =
AddressIsExclusive
// Can/Cant listen more than once.
358
);
359
360
// Overrides from class PIPSocket.
366
virtual
PBoolean
GetLocalAddress
(
367
Address
& addr
// Variable to receive hosts IP address
368
);
369
virtual
PBoolean
GetLocalAddress
(
370
Address
& addr,
// Variable to receive peer hosts IP address
371
WORD &
port
// Variable to receive peer hosts port number
372
);
373
380
virtual
PBoolean
GetPeerAddress
(
381
Address
& addr
// Variable to receive hosts IP address
382
);
383
virtual
PBoolean
GetPeerAddress
(
384
Address
& addr,
// Variable to receive peer hosts IP address
385
WORD & port
// Variable to receive peer hosts port number
386
);
387
388
389
// Overrides from class PIPDatagramSocket.
395
virtual
PBoolean
ReadFrom
(
396
void
* buf,
// Data to be written as URGENT TCP data.
397
PINDEX len,
// Number of bytes pointed to by <CODE>buf</CODE>.
398
Address
& addr,
// Address from which the datagram was received.
399
WORD & port
// Port from which the datagram was received.
400
);
401
407
virtual
PBoolean
WriteTo
(
408
const
void
* buf,
// Data to be written as URGENT TCP data.
409
PINDEX len,
// Number of bytes pointed to by <CODE>buf</CODE>.
410
const
Address
& addr,
// Address to which the datagram is sent.
411
WORD port
// Port to which the datagram is sent.
412
);
413
414
415
protected
:
416
virtual
void
SetErrorCodes
(
PChannel::Errors
errCode,
int
osErr);
417
418
PTCPSocket
socksControl
;
419
Address
serverAddress
;
420
421
private
:
422
virtual
PBoolean
Connect
(WORD
localPort
,
const
Address
& addr);
423
};
424
425
426
#endif // PTLIB_SOCKS_H
427
428
429
// End of File ///////////////////////////////////////////////////////////////
include
ptclib
socks.h
Generated on Fri Oct 10 2014 21:15:13 for PTLib by
1.8.3.1