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