如何连接到 sock4 客户端的网络字节地址?



我正在尝试使用boost-asio制作socks 4代理服务器。我怎么能连接到由客户端指定的网站,如果它在网络字节顺序?你能举个例子吗?我用的是linux,所以没有winsock。

sock4request是服务器从客户端接收到的。

            const boost::array<unsigned char,4> addr={sock4request[5],sock4request[6],sock4request[7],sock4request[8]}; //Network byte address
            unsigned char port[]={sock4request[3],sock4request[4]};
            boost::asio::ip::address_v4 addrip(addr);
            unsigned short portint=lexical_cast<unsigned short>(port);
            tcp::endpoint addrinfo(addrip,portint);
            tcp::socket finalsocket(io_service);
            boost::asio::connect(finalsocket,endpoint_iterator);

您应该使用内置的linux函数,如hons, ntohs..请查看此页:

http://www.beej.us/guide/bgnet/output/html/multipage/htonsman.html

相关内容

最新更新