]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/socks++.cpp
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
20 // socks - socks version of IP sockets
22 // [Also see comments in header file.]
24 // This file contains the "generic" Socks functionality.
25 // Socks4 and Socks5 implementations are in their separate files.
34 namespace IPPlusPlus
{
40 ModuleNexus
<SocksServer::Global
> SocksServer::global
;
44 // Create a SocksServer object
46 SocksServer
*SocksServer::make(Version version
, const IPSockAddress
&addr
)
50 return NULL
; // no socks
52 return new Socks4::Server(addr
);
54 return new Socks5::Server(addr
);
56 UnixError::throwMe(EINVAL
);
62 // TCPClientSockets (CONNECT access)
64 void SocksClientSocket::open(const IPSockAddress
&peer
)
67 Support::connect(*this, peer
);
68 lastConnected(mPeerAddress
.address());
70 TCPClientSocket::open(peer
);
74 void SocksClientSocket::open(const IPAddress
&addr
, IPPort port
)
76 open(IPSockAddress(addr
, port
));
79 void SocksClientSocket::open(const Host
&host
, IPPort port
)
82 Support::connect(*this, host
, port
);
83 lastConnected(mPeerAddress
.address());
85 TCPClientSocket::open(host
, port
);
89 void SocksClientSocket::setFd(int fd
, const IPSockAddress
&local
, const IPSockAddress
&peer
)
92 mLocalAddress
= local
;
98 // TCPServerSockets (BIND access)
100 void SocksServerSocket::open(const IPSockAddress
&local
, int)
105 Support::bind(*this, mConnectionPeer
, local
.port());
107 Support::bind(*this, lastConnected(), local
.port());
110 mConnectionPeer
? mConnectionPeer
: lastConnected(),
114 TCPServerSocket::open(local
, 1);
118 void SocksServerSocket::receive(SocksClientSocket
&client
)
121 Support::receive(*this, client
);
123 TCPServerSocket::receive(client
);
131 IPSockAddress
SocksServer::Support::localAddress(const Socket
&me
) const
134 return mLocalAddress
;
136 return me
.localAddress();
139 IPSockAddress
SocksServer::Support::peerAddress(const Socket
&me
) const
144 return me
.peerAddress();
148 } // end namespace IPPlusPlus
149 } // end namespace Security