Advertisement
mfgnik

Untitled

Apr 6th, 2020
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include "socks4.h"
  2.  
  3. void Sock4Connect(cactus::IConn* conn, folly::SocketAddress endpoint, const std::string& user) {
  4.     std::vector<char> buf;
  5.     buf.push_back(4);
  6.     buf.push_back(1);
  7.     buf.push_back(endpoint.getPort() /  256);
  8.     buf.push_back(endpoint.getPort() %  256);
  9.     for (size_t index = 0; index < 4; ++index) {
  10.         buf.push_back(endpoint.getIPAddress().getNthMSByte(index));
  11.     }
  12.     for (auto letter : user) {
  13.         buf.push_back(letter);
  14.     }
  15.     buf.push_back('\0');
  16.     conn->Write(cactus::View(buf));
  17.     buf.resize(8);
  18.     int n = conn->Read(cactus::View(buf));
  19.     if (n != 8 || buf[0] != 0 || buf[1] != 90) {
  20.         throw std::runtime_error("");
  21.     }
  22. }
  23.  
  24. std::unique_ptr<cactus::IConn> DialProxyChain(std::vector<Proxy> proxies, folly::SocketAddress
  25.                                                                               endpoint) {
  26.     proxies.push_back(Proxy{endpoint, ""});
  27.     auto conn = cactus::DialTCP(proxies.begin()->proxy_address);
  28.     for (size_t index = 0; index + 1 < proxies.size(); ++index) {
  29.         Sock4Connect(conn.get(), proxies[index + 1].proxy_address, proxies[index].username);
  30.     }
  31.     return conn;
  32. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement