Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "socks4.h"
- void Sock4Connect(cactus::IConn* conn, folly::SocketAddress endpoint, const std::string& user) {
- std::vector<char> buf;
- buf.push_back(4);
- buf.push_back(1);
- buf.push_back(endpoint.getPort() / 256);
- buf.push_back(endpoint.getPort() % 256);
- for (size_t index = 0; index < 4; ++index) {
- buf.push_back(endpoint.getIPAddress().getNthMSByte(index));
- }
- for (auto letter : user) {
- buf.push_back(letter);
- }
- buf.push_back('\0');
- conn->Write(cactus::View(buf));
- buf.resize(8);
- int n = conn->Read(cactus::View(buf));
- if (n != 8 || buf[0] != 0 || buf[1] != 90) {
- throw std::runtime_error("");
- }
- }
- std::unique_ptr<cactus::IConn> DialProxyChain(std::vector<Proxy> proxies, folly::SocketAddress
- endpoint) {
- proxies.push_back(Proxy{endpoint, ""});
- auto conn = cactus::DialTCP(proxies.begin()->proxy_address);
- for (size_t index = 0; index + 1 < proxies.size(); ++index) {
- Sock4Connect(conn.get(), proxies[index + 1].proxy_address, proxies[index].username);
- }
- return conn;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement