]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/socks++5.h
Security-54.1.tar.gz
[apple/security.git] / cdsa / cdsa_utilities / socks++5.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // socks++5 - version 5 Socks protocol
21 //
22 #ifndef _H_SOCKSPLUSPLUS5
23 #define _H_SOCKSPLUSPLUS5
24
25 #include "socks++.h"
26
27
28 namespace Security {
29 namespace IPPlusPlus {
30 namespace Socks5 {
31
32
33 typedef unsigned char Byte;
34
35
36 class Server : public SocksServer {
37 public:
38 Server(const IPSockAddress &s) : SocksServer(5, s) { }
39
40 virtual void connect(SocksClientSocket &me, const IPSockAddress &peer);
41 virtual void connect(SocksClientSocket &me, const Host &host, IPPort port);
42 virtual void bind(SocksServerSocket &me, const IPAddress &peer, IPPort port);
43 virtual void receive(SocksServerSocket &me, SocksClientSocket &receiver);
44
45 private:
46 void open(Socket &s, Support &me);
47 };
48
49
50 // request code (message field outbound)
51 enum Command {
52 socksConnect = 1, // connect (outbound)
53 socksBind = 2, // bind (single inbound)
54 socksUDP = 3 // UDP associate (not implemented)
55 };
56
57 // reply code (message field inbound)
58 enum SocksReply {
59 socksSuccess = 0,
60 socksFailed = 1,
61 socksDenied = 2,
62 socksNetUnreach = 3,
63 socksHostUnreach = 4,
64 socksConRefused = 5,
65 socksTTLExpired = 6,
66 socksUnsupported = 7,
67 socksAddressNotSupported = 8
68 };
69
70 // authentication type (in setup request)
71 enum AuthenticationType {
72 socksAuthPublic = 0, // anonymous access
73 socksAuthGSSAPI = 1, // GSSAPI (yuk)
74 socksAuthUsername = 2, // username/password
75 socksAuthNoneAcceptable = 0xff // can't help you there...
76 };
77
78 // address types (inbound/outbound)
79 enum AddressType {
80 socksIPv4 = 1,
81 socksName = 3,
82 socksIPv6 = 4
83 };
84
85
86 //
87 // A Message object contains a single request or reply of the Socks5 protocol.
88 // Since some of the data is dynamically sized, we have to fudge a bit. The static
89 // layout corresponds to IPv4 addresses, the common case. The object itself is big
90 // enough for all cases.
91 //
92 struct Message {
93 Byte version; // Socks version
94 Byte message; // message/reply
95 Byte reserved; // not used (zero)
96 Byte addressType; // address type
97 IPAddress addr; // address starts here (IPv4 case)
98 // following fields dynamically located if (addressType != socksIPv4)
99 IPPort port; // port field IF addr is IPv4
100 Byte pad[256-sizeof(IPAddress)-sizeof(IPPort)]; // enough room for type 3 addresses (256 bytes)
101
102 // the following fields are not part of the message data
103 size_t length; // calculated length of message (bytes, starting at version)
104
105 Message(Command cmd, IPAddress addr, IPPort port); // type 1 request
106 Message(Command cmd, const char *hostname, IPPort port); // type 3 request
107 void send(Socket &s); // send request
108
109 Message(Socket &socket); // receive (type 1 only)
110
111 IPSockAddress address() const { return IPSockAddress(addr, ntohs(port)); }
112 };
113
114
115 } // end namespace Socks
116 } // end namespace IPPlusPlus
117 } // end namespace Security
118
119 #endif //_H_SOCKSPLUSPLUS5