00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
#ifndef _SOCKS_H
00052
#define _SOCKS_H
00053
00054
#ifdef P_USE_PRAGMA
00055
#pragma interface
00056
#endif
00057
00058
00059
#include <ptlib/sockets.h>
00060
00061
00067 class PSocksProtocol
00068 {
00069
public:
00070
PSocksProtocol(WORD port);
00071 virtual ~PSocksProtocol() { }
00072
00073
00074
enum {
00075 DefaultServerPort = 1080
00076 };
00077 BOOL
SetServer(
00078
const PString & hostname,
00079
const char * service =
"socks 1080"
00080 );
00081 BOOL SetServer(
00082
const PString & hostname,
00083 WORD port
00084 );
00085
00090
void SetAuthentication(
00091
const PString & username,
00092
const PString & password
00093 );
00094
00095
protected:
00096 BOOL
ConnectSocksServer(
PTCPSocket & thisSocket);
00097
00098
virtual void SetErrorCodes(PChannel::Errors errCode,
int osErr) = 0;
00099
00100
virtual BOOL
SendSocksCommand(
PTCPSocket & socket,
00101 BYTE command,
00102
const char * hostname,
00103
PIPSocket::Address addr);
00104
virtual BOOL
ReceiveSocksResponse(
PTCPSocket & socket,
00105
PIPSocket::Address & addr,
00106 WORD & port);
00107
00108
00109 PString serverHost;
00110 WORD
serverPort;
00111 PString authenticationUsername;
00112 PString authenticationPassword;
00113 PIPSocket::Address remoteAddress;
00114 WORD
remotePort;
00115 PIPSocket::Address localAddress;
00116 WORD
localPort;
00117 };
00118
00119
00122 class PSocksSocket :
public PTCPSocket,
public PSocksProtocol
00123 {
00124
PCLASSINFO(
PSocksSocket,
PTCPSocket)
00125
00126
public:
00127
PSocksSocket(
00128 WORD port = 0
00129 );
00130
00131
00143
virtual BOOL
Connect(
00144
const PString & address
00145 );
00146
virtual BOOL Connect(
00147
const Address & addr
00148 );
00149
00165
virtual BOOL
Listen(
00166
unsigned queueSize = 5,
00167 WORD port = 0,
00168 Reusability reuse = AddressIsExclusive
00169 );
00170
00190 BOOL
Accept();
00191
virtual BOOL
Accept(
00192
PSocket & socket
00193 );
00194
00195
00196
00202
virtual BOOL
GetLocalAddress(
00203 Address & addr
00204 );
00205
virtual BOOL GetLocalAddress(
00206 Address & addr,
00207 WORD & port
00208 );
00209
00216
virtual BOOL
GetPeerAddress(
00217 Address & addr
00218 );
00219
virtual BOOL GetPeerAddress(
00220 Address & addr,
00221 WORD & port
00222 );
00223
00224
00225
protected:
00226
virtual void SetErrorCodes(PChannel::Errors errCode,
int osErr);
00227
int TransferHandle(
PSocksSocket & destination);
00228
00229
private:
00230
virtual BOOL Connect(WORD localPort,
const Address & addr);
00231 };
00232
00233
00236 class PSocks4Socket :
public PSocksSocket
00237 {
00238
PCLASSINFO(
PSocks4Socket,
PSocksSocket)
00239
00240
public:
00241
PSocks4Socket(
00242 WORD port = 0
00243 );
00244
PSocks4Socket(
00245
const PString & host,
00246 WORD port = 0
00247 );
00248
00249
00262
virtual PObject *
Clone()
const;
00263
00264
00265
protected:
00266
virtual BOOL
SendSocksCommand(
PTCPSocket & socket,
00267 BYTE command,
00268
const char * hostname,
00269
PIPSocket::Address addr);
00270
virtual BOOL
ReceiveSocksResponse(
PTCPSocket & socket,
00271
PIPSocket::Address & addr,
00272 WORD & port);
00273 };
00274
00275
00278 class PSocks5Socket :
public PSocksSocket
00279 {
00280
PCLASSINFO(
PSocks5Socket,
PSocksSocket)
00281
00282
public:
00283
PSocks5Socket(
00284 WORD port = 0
00285 );
00286
PSocks5Socket(
00287
const PString & host,
00288 WORD port = 0
00289 );
00290
00291
00304
virtual PObject *
Clone()
const;
00305 };
00306
00307
00310 class PSocksUDPSocket :
public PUDPSocket,
public PSocksProtocol
00311 {
00312
PCLASSINFO(
PSocksUDPSocket,
PUDPSocket)
00313
00314
public:
00315
PSocksUDPSocket(
00316 WORD port = 0
00317 );
00318
PSocksUDPSocket(
00319
const PString & host,
00320 WORD port = 0
00321 );
00322
00323
00324
00337
virtual PObject *
Clone()
const;
00338
00339
00340
00352
virtual BOOL
Connect(
00353
const PString & address
00354 );
00355
virtual BOOL Connect(
00356
const Address & addr
00357 );
00358
00374
virtual BOOL
Listen(
00375
unsigned queueSize = 5,
00376 WORD port = 0,
00377 Reusability reuse = AddressIsExclusive
00378 );
00379
00380
00386
virtual BOOL
GetLocalAddress(
00387 Address & addr
00388 );
00389
virtual BOOL GetLocalAddress(
00390 Address & addr,
00391 WORD & port
00392 );
00393
00400
virtual BOOL
GetPeerAddress(
00401 Address & addr
00402 );
00403
virtual BOOL GetPeerAddress(
00404 Address & addr,
00405 WORD & port
00406 );
00407
00408
00409
00415
virtual BOOL
ReadFrom(
00416
void * buf,
00417 PINDEX len,
00418 Address & addr,
00419 WORD & port
00420 );
00421
00427
virtual BOOL
WriteTo(
00428
const void * buf,
00429 PINDEX len,
00430
const Address & addr,
00431 WORD port
00432 );
00433
00434
00435
protected:
00436
virtual void SetErrorCodes(PChannel::Errors errCode,
int osErr);
00437
00438 PTCPSocket socksControl;
00439 Address
serverAddress;
00440
00441
private:
00442
virtual BOOL Connect(WORD localPort,
const Address & addr);
00443 };
00444
00445
00446
#endif // _SOCKS_H
00447
00448
00449