Example #1
0
void Server::connect(SocksClientSocket &me, const Host &host, IPPort port)
{
#if 1
    //@@@ should be using Hostname (server resolution) mode, but this won't get us
    //@@@ any useful peer address to use for bind relaying. Need to rethink this scenario.
    set<IPAddress> addrs = host.addresses();
    for (set<IPAddress>::const_iterator it = addrs.begin(); it != addrs.end(); it++) {
        try {
            IPSockAddress addr(*it, port);
            connect(me, addr);
            return;
        } catch (const UnixError &err) {
            errno = err.error;
        }
    }
    // exhausted
    UnixError::throwMe();
#else
    open(me, me);
    Message request(socksConnect, host.name().c_str(), port);
    request.send(me);
    Message reply(me);
    me.mLocalAddress = reply.address();
    //me.mPeerAddress = not provided by Socks5 protocol;
    secdebug("socks", "%d socks connected to %s", me.fd(), host.name().c_str());
#endif
}
void Server::connect(SocksClientSocket &me, const Host &host, IPPort port)
{
    // Socks4 has no name resolution support. Do it here
    //@@@ error reporting sucks here
    set<IPAddress> addrs = host.addresses();
    for (set<IPAddress>::const_iterator it = addrs.begin(); it != addrs.end(); it++) {
        try {
            IPSockAddress addr(*it, port);
            connect(me, addr);
            return;
        } catch (const UnixError &err) {
            errno = err.error;
        }
    }
    // exhausted
    UnixError::throwMe();
}
Example #3
0
//
// Connect to a Host object.
// This version of connect performs nontrivial work and makes interesting decisions.
//
void Socket::connect(const Host &host, IPPort port)
{
    //@@@ use two-step stutter algorithm?
    //@@@ randomize order?
    //@@@ keep worked-recently information?
    //@@@ what about nonblocking operation?
    set<IPAddress> addrs = host.addresses();
    for (set<IPAddress>::const_iterator it = addrs.begin(); it != addrs.end(); it++) {
        const IPSockAddress address(*it, port);
        if (::connect(fd(), address, sizeof(IPSockAddress)) == 0) {
            secdebug("sockio", "%d connect to %s", fd(), string(address).c_str());
            return;
        }
    }
    // no joy on any of the candidate addresses. Throw last error
    //@@@ clean up errno?
    UnixError::throwMe();
}