PTLib  Version 2.10.11
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: 24177 $
27  * $Author: rjongbloed $
28  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
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 
48 {
49  public:
50  PSocksProtocol(WORD port);
51  virtual ~PSocksProtocol() { }
52 
53  // New functions for class
54  enum {
56  };
58  const PString & hostname,
59  const char * service = "socks 1080"
60  );
62  const PString & hostname,
63  WORD port
64  );
65 
70  void SetAuthentication(
71  const PString & username,
72  const PString & password
73  );
74 
75  protected:
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 
90  WORD serverPort;
94  WORD remotePort;
96  WORD localPort;
97 };
98 
99 
102 class PSocksSocket : public PTCPSocket, public PSocksProtocol
103 {
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,
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  int TransferHandle(PSocksSocket & destination);
208 
209  private:
210  virtual PBoolean Connect(WORD localPort, const Address & addr);
211 };
212 
213 
217 {
219 
220  public:
222  WORD port = 0
223  );
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 
259 {
261 
262  public:
264  WORD port = 0
265  );
267  const PString & host,
268  WORD port = 0
269  );
270 
271  // Overrides from class PObject
284  virtual PObject * Clone() const;
285 };
286 
287 
291 {
293 
294  public:
296  WORD port = 0
297  );
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 
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 ///////////////////////////////////////////////////////////////
Definition: socket.h:86
PSocksUDPSocket(WORD port=0)
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
virtual PObject * Clone() const
Create a copy of the class on the heap.
WORD localPort
Definition: socks.h:96
int TransferHandle(PSocksSocket &destination)
Base class for implementing the SOCKS protocol for use with PSocksSocket and PSocksUDPSocket.
Definition: socks.h:47
A socket channel that uses the UDP transport on the Internet Protocol.
Definition: udpsock.h:47
PIPSocket::Address localAddress
Definition: socks.h:95
virtual PBoolean Listen(unsigned queueSize=5, WORD port=0, Reusability reuse=AddressIsExclusive)
Listen on a socket for a remote host on the specified port number.
virtual PString GetLocalAddress()
Get the Internet Protocol address and port for the local host.
PSocksProtocol(WORD port)
Definition: socks.h:55
PString serverHost
Definition: socks.h:89
virtual PBoolean WriteTo(const void *buf, PINDEX len, const Address &addr, WORD port)
Write a datagram to a remote computer.
virtual PBoolean SendSocksCommand(PTCPSocket &socket, BYTE command, const char *hostname, PIPSocket::Address addr)
WORD port
Port to be used by the socket when opening the channel.
Definition: socket.h:444
virtual ~PSocksProtocol()
Definition: socks.h:51
PBoolean Accept()
Open a socket to a remote host on the specified port number.
PSocksSocket(WORD port=0)
Errors
Normalised error codes.
Definition: channel.h:529
BOOL PBoolean
Definition: object.h:102
This class allows access to RFC1928 compliant SOCKS server.
Definition: socks.h:258
PTCPSocket socksControl
Definition: socks.h:418
virtual PBoolean ReceiveSocksResponse(PTCPSocket &socket, PIPSocket::Address &addr, WORD &port)
This is an ancestor class allowing access to a SOCKS servers (version 4 and 5).
Definition: socks.h:102
virtual PBoolean SendSocksCommand(PTCPSocket &socket, BYTE command, const char *hostname, PIPSocket::Address addr)
The character string class.
Definition: pstring.h:108
WORD remotePort
Definition: socks.h:94
PIPSocket::Address remoteAddress
Definition: socks.h:93
virtual PBoolean Connect(const PString &address)
Connect a socket to a remote host on the specified port number.
A socket that uses the TCP transport on the Internet Protocol.
Definition: tcpsock.h:44
PString authenticationUsername
Definition: socks.h:91
PBoolean SetServer(const PString &hostname, const char *service="socks 1080")
virtual void SetErrorCodes(PChannel::Errors errCode, int osErr)
virtual PBoolean ReadFrom(void *buf, PINDEX len, Address &addr, WORD &port)
Read a datagram from a remote computer.
A class describing an IP address.
Definition: ipsock.h:75
This class allows access to RFC1928 compliant SOCKS server.
Definition: socks.h:290
virtual PString GetPeerAddress()
Get the Internet Protocol address for the peer host and port the socket is connected to...
virtual PBoolean ReceiveSocksResponse(PTCPSocket &socket, PIPSocket::Address &addr, WORD &port)
virtual void SetErrorCodes(PChannel::Errors errCode, int osErr)
PBoolean ConnectSocksServer(PTCPSocket &thisSocket)
This class allows access to RFC1928 compliant SOCKS server.
Definition: socks.h:216
PSocks4Socket(WORD port=0)
virtual PBoolean Listen(unsigned queueSize=5, WORD port=0, Reusability reuse=AddressIsExclusive)
Listen on a socket for a remote host on the specified port number.
PSocks5Socket(WORD port=0)
virtual void SetErrorCodes(PChannel::Errors errCode, int osErr)=0
void SetAuthentication(const PString &username, const PString &password)
Set the username and password for the SOCKS server authentication.
A network communications channel.
Definition: socket.h:58
virtual PBoolean Connect(const PString &address)
Connect a socket to a remote host on the specified port number.
WORD serverPort
Definition: socks.h:90
Address serverAddress
Definition: socks.h:419
Reusability
Flags to reuse of port numbers in Listen() function.
Definition: socket.h:84
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
virtual PObject * Clone() const
Create a copy of the class on the heap.
PString authenticationPassword
Definition: socks.h:92
virtual PObject * Clone() const
Create a copy of the class on the heap.