c++ - 通过 SOCKS 代理发送 UDP 数据包

标签 c++ sockets proxy winsock socks

我正在构建一个简单的应用程序,它应该通过 socks4/5 代理发送 UDP 数据报包。我使用 UDP 方法,所以我不必保持连接打开。

然而,这并不像我想的那么容易。根据这个模式,我得出结论,如果不先与代理服务器建立 TCP 连接,我就无法通过代理发送 UDP 数据。 enter image description here

尽管如此,我找不到在 CPP 中建立此类连接的任何合适示例。如果有任何资源,我将不胜感激 :)

最佳答案

这是可能的。根据 wikipedia,您必须在客户端连接请求的字段 2 中指定值 0x03。 SOCKS5协议(protocol)的描述。

The client's connection request is
field 1: SOCKS version number, 1 byte (must be 0x05 for this version)
field 2: command code, 1 byte:
0x01 = establish a TCP/IP stream connection
0x02 = establish a TCP/IP port binding
0x03 = associate a UDP port
field 3: reserved, must be 0x00
field 4: address type, 1 byte:
0x01 = IPv4 address
0x03 = Domain name
0x04 = IPv6 address
field 5: destination address of
4 bytes for IPv4 address
1 byte of name length followed by the name for Domain name
16 bytes for IPv6 address
field 6: port number in a network byte order, 2 bytes

正如 Hasturkun 指出的那样

Your code doesn't work because you aren't sending a connection request at all. You must send a UDP ASSOCIATE request (on the TCP connection), and you need to use the port and address from the response to get your datagrams relayed.

你真的应该看看Socks5 RFC

关于c++ - 通过 SOCKS 代理发送 UDP 数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18428498/

相关文章:

node.js - 使用命名管道的 Node HTTP 请求

python - 检测 python 中套接字的正常关闭

android - 我们可以用任何其他方式在 Android 中访问 C++ 代码而不是使用 JNI

c++ - 在循环期间更改订阅的发布者/订阅者

c - 数据未正确发送/接收

docker - 如何为Docker配置Polipo的HTTP代理以部署Kubernetes

java - BrowserMob 代理不会将 https 资源列入黑名单

c++ - 想要一些文字在游戏中抹去自己

c++ - Visual C++ 2010 Express 中的 "Unresolved External"错误

tcp - WSO2 ESB 4.9.0 : what means error 101500