PTLib  Version 2.18.8
 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 
27 #ifndef PTLIB_SOCKS_H
28 #define PTLIB_SOCKS_H
29 
30 #ifdef P_USE_PRAGMA
31 #pragma interface
32 #endif
33 
34 
35 #include <ptlib/sockets.h>
36 
37 
44 {
45  public:
46  PSocksProtocol(WORD port);
47  virtual ~PSocksProtocol() { }
48 
49  // New functions for class
50  enum {
52  };
54  const PString & hostname,
55  const char * service = "socks 1080"
56  );
58  const PString & hostname,
59  WORD port
60  );
61 
66  void SetAuthentication(
67  const PString & username,
68  const PString & password
69  );
70 
71  protected:
73 
74  virtual void SetErrorCodes(PChannel::Errors errCode, int osErr) = 0;
75 
76  virtual PBoolean SendSocksCommand(PTCPSocket & socket,
77  BYTE command,
78  const char * hostname,
79  PIPSocket::Address addr);
80  virtual PBoolean ReceiveSocksResponse(PTCPSocket & socket,
81  PIPSocket::Address & addr,
82  WORD & port);
83 
84 
86  WORD serverPort;
90  WORD remotePort;
92  WORD localPort;
93 };
94 
95 
98 class PSocksSocket : public PTCPSocket, public PSocksProtocol
99 {
101 
102  public:
103  PSocksSocket(
104  WORD port = 0
105  );
106 
107  // Overrides from class PSocket.
119  virtual PBoolean Connect(
120  const PString & address
121  );
122  virtual PBoolean Connect(
123  const Address & addr
124  );
125 
141  virtual PBoolean Listen(
142  unsigned queueSize = 5,
143  WORD port = 0,
145  );
146 
166  PBoolean Accept();
167  virtual PBoolean Accept(
168  PSocket & socket
169  );
170 
171 
172  // Overrides from class PIPSocket.
178  virtual PBoolean GetLocalAddress(
179  Address & addr
180  );
181  virtual PBoolean GetLocalAddress(
182  Address & addr,
183  WORD & port
184  );
185 
192  virtual PBoolean GetPeerAddress(
193  Address & addr
194  );
195  virtual PBoolean GetPeerAddress(
196  Address & addr,
197  WORD & port
198  );
199 
200 
201  protected:
202  virtual void SetErrorCodes(PChannel::Errors errCode, int osErr);
203  P_INT_PTR TransferHandle(PSocksSocket & destination);
204 
205  private:
206  virtual PBoolean Connect(WORD localPort, const Address & addr);
207 };
208 
209 
213 {
215 
216  public:
218  WORD port = 0
219  );
221  const PString & host,
222  WORD port = 0
223  );
224 
225  // Overrides from class PObject
238  virtual PObject * Clone() const;
239 
240 
241  protected:
242  virtual PBoolean SendSocksCommand(PTCPSocket & socket,
243  BYTE command,
244  const char * hostname,
245  PIPSocket::Address addr);
246  virtual PBoolean ReceiveSocksResponse(PTCPSocket & socket,
247  PIPSocket::Address & addr,
248  WORD & port);
249 };
250 
251 
255 {
257 
258  public:
260  WORD port = 0
261  );
263  const PString & host,
264  WORD port = 0
265  );
266 
267  // Overrides from class PObject
280  virtual PObject * Clone() const;
281 };
282 
283 
287 {
289 
290  public:
292  WORD port = 0
293  );
295  const PString & host,
296  WORD port = 0
297  );
298 
299 
300  // Overrides from class PObject
313  virtual PObject * Clone() const;
314 
315 
316  // Overrides from class PSocket.
328  virtual PBoolean Connect(
329  const PString & address // Address of remote machine to connect to.
330  );
331  virtual PBoolean Connect(
332  const Address & addr // Address of remote machine to connect to.
333  );
334 
350  virtual PBoolean Listen(
351  unsigned queueSize = 5, // Number of pending accepts that may be queued.
352  WORD port = 0, // Port number to use for the connection.
353  Reusability reuse = AddressIsExclusive // Can/Cant listen more than once.
354  );
355 
356  // Overrides from class PIPSocket.
362  virtual PBoolean GetLocalAddress(
363  Address & addr // Variable to receive hosts IP address
364  );
365  virtual PBoolean GetLocalAddress(
366  Address & addr, // Variable to receive peer hosts IP address
367  WORD & port // Variable to receive peer hosts port number
368  );
369 
376  virtual PBoolean GetPeerAddress(
377  Address & addr // Variable to receive hosts IP address
378  );
379  virtual PBoolean GetPeerAddress(
380  Address & addr, // Variable to receive peer hosts IP address
381  WORD & port // Variable to receive peer hosts port number
382  );
383 
384 
385  // Overrides from class PIPDatagramSocket.
391  virtual PBoolean ReadFrom(
392  void * buf, // Data to be written as URGENT TCP data.
393  PINDEX len, // Number of bytes pointed to by <CODE>buf</CODE>.
394  Address & addr, // Address from which the datagram was received.
395  WORD & port // Port from which the datagram was received.
396  );
397 
403  virtual PBoolean WriteTo(
404  const void * buf, // Data to be written as URGENT TCP data.
405  PINDEX len, // Number of bytes pointed to by <CODE>buf</CODE>.
406  const Address & addr, // Address to which the datagram is sent.
407  WORD port // Port to which the datagram is sent.
408  );
409 
410 
411  protected:
412  virtual void SetErrorCodes(PChannel::Errors errCode, int osErr);
413 
416 
417  private:
418  virtual PBoolean Connect(WORD localPort, const Address & addr);
419 };
420 
421 
422 #endif // PTLIB_SOCKS_H
423 
424 
425 // End of File ///////////////////////////////////////////////////////////////
Definition: socket.h:87
PSocksUDPSocket(WORD port=0)
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
virtual PObject * Clone() const
Create a copy of the class on the heap.
PString GetLocalAddress() const
Get the Internet Protocol address and port for the local host.
WORD localPort
Definition: socks.h:92
Base class for implementing the SOCKS protocol for use with PSocksSocket and PSocksUDPSocket.
Definition: socks.h:43
A socket channel that uses the UDP transport on the Internet Protocol.
Definition: udpsock.h:42
PIPSocket::Address localAddress
Definition: socks.h:91
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.
PSocksProtocol(WORD port)
PString serverHost
Definition: socks.h:85
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)
P_INT_PTR TransferHandle(PSocksSocket &destination)
PString GetPeerAddress() const
Get the Internet Protocol address for the peer host and port the socket is connected to...
virtual ~PSocksProtocol()
Definition: socks.h:47
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:227
This class allows access to RFC1928 compliant SOCKS server.
Definition: socks.h:254
PTCPSocket socksControl
Definition: socks.h:414
bool PBoolean
Definition: object.h:174
virtual PBoolean ReceiveSocksResponse(PTCPSocket &socket, PIPSocket::Address &addr, WORD &port)
intptr_t P_INT_PTR
Definition: object.h:2646
This is an ancestor class allowing access to a SOCKS servers (version 4 and 5).
Definition: socks.h:98
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:90
PIPSocket::Address remoteAddress
Definition: socks.h:89
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:40
PString authenticationUsername
Definition: socks.h:87
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:59
This class allows access to RFC1928 compliant SOCKS server.
Definition: socks.h:286
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:212
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:59
virtual PBoolean Connect(const PString &address)
Connect a socket to a remote host on the specified port number.
WORD serverPort
Definition: socks.h:86
Definition: socks.h:51
Address serverAddress
Definition: socks.h:415
Reusability
Flags to reuse of port numbers in Listen() function.
Definition: socket.h:85
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
virtual PObject * Clone() const
Create a copy of the class on the heap.
PString authenticationPassword
Definition: socks.h:88
virtual PObject * Clone() const
Create a copy of the class on the heap.