]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/socks++.cpp
0ab7d50c63e4c7a0b2528f802943318792c84375
   2  * Copyright (c) 2000-2001,2004,2011,2014 Apple Inc. All Rights Reserved. 
   4  * @APPLE_LICENSE_HEADER_START@ 
   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 
  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. 
  21  * @APPLE_LICENSE_HEADER_END@ 
  26 // socks - socks version of IP sockets 
  28 // [Also see comments in header file.] 
  30 // This file contains the "generic" Socks functionality. 
  31 // Socks4 and Socks5 implementations are in their separate files. 
  40 namespace IPPlusPlus 
{ 
  46 ModuleNexus
<SocksServer::Global
> SocksServer::global
; 
  50 // SocksServer destruction 
  52 SocksServer::~SocksServer() 
  57 // Create a SocksServer object 
  59 SocksServer 
*SocksServer::make(Version version
, const IPSockAddress 
&addr
) 
  63         return NULL
;            // no socks 
  65         return new Socks4::Server(addr
); 
  67         return new Socks5::Server(addr
); 
  69         UnixError::throwMe(EINVAL
); 
  75 // TCPClientSockets (CONNECT access) 
  77 void SocksClientSocket::open(const IPSockAddress 
&peer
) 
  80         Support::connect(*this, peer
); 
  81         lastConnected(mPeerAddress
.address()); 
  83         TCPClientSocket::open(peer
); 
  87 void SocksClientSocket::open(const IPAddress 
&addr
, IPPort port
) 
  89     open(IPSockAddress(addr
, port
)); 
  92 void SocksClientSocket::open(const Host 
&host
, IPPort port
) 
  95         Support::connect(*this, host
, port
); 
  96         lastConnected(mPeerAddress
.address()); 
  98         TCPClientSocket::open(host
, port
); 
 102 void SocksClientSocket::setFd(int fd
, const IPSockAddress 
&local
, const IPSockAddress 
&peer
) 
 105     mLocalAddress 
= local
; 
 111 // TCPServerSockets (BIND access) 
 113 void SocksServerSocket::open(const IPSockAddress 
&local
, int) 
 118             Support::bind(*this, mConnectionPeer
, local
.port()); 
 120             Support::bind(*this, lastConnected(), local
.port()); 
 123             mConnectionPeer 
? mConnectionPeer 
: lastConnected(), 
 127         TCPServerSocket::open(local
, 1); 
 131 void SocksServerSocket::receive(SocksClientSocket 
&client
) 
 134         Support::receive(*this, client
); 
 136         TCPServerSocket::receive(client
); 
 144 IPSockAddress 
SocksServer::Support::localAddress(const Socket 
&me
) const 
 147         return mLocalAddress
; 
 149         return me
.localAddress(); 
 152 IPSockAddress 
SocksServer::Support::peerAddress(const Socket 
&me
) const 
 157         return me
.peerAddress(); 
 161 }       // end namespace IPPlusPlus 
 162 }       // end namespace Security