我正在尝试连接到 UDP Socks5 代理,但没有服务器会回复我的初始握手。Wire Shark 显示正确的信号正在发送到服务器,但没有收到回复
#define PUT_BYTE(ptr,data) (*(unsigned char*)ptr = data)
static int Connect_proxy(SOCKET sock,sockaddr_in Rcv_address) {
char buff[200],*ptr;
sockaddr_in SenderAddrTemp;
int SenderAddrSize= sizeof(SenderAddrTemp);
ptr=buff;
int iResult;
PUT_BYTE(ptr++,5);
PUT_BYTE(ptr++,1);
PUT_BYTE(ptr++,0);
iResult = sendto(sock,
buff, ptr-buff, 0, (SOCKADDR *) & Rcv_address, sizeof (Rcv_address));
if (iResult == SOCKET_ERROR) {
wprintf(L"[Send]Conection request failed with error: %d\n", WSAGetLastError());
//closesocket(sock);
//WSACleanup();
return -1;
}
iResult = recvfrom(sock,buff, 200, 0, (SOCKADDR *) & SenderAddrTemp, &SenderAddrSize);
if (iResult==-1) {
wprintf(L"[Recv] Connection request failed with error: %d\n", WSAGetLastError());
return -1;
}
else
if (iResult==2) {
wprintf(L"OK");
}
return 0;
}
套接字初始化是:
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != NO_ERROR) {
wprintf(L"WSAStartup failed with error: %d\n", iResult);
return 1;
}
//---------------------------------------------
// Create a socket for sending data
SendSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (SendSocket == INVALID_SOCKET) {
wprintf(L"socket failed with error: %ld\n", WSAGetLastError());
WSACleanup();
return 1;
}
RecvAddr.sin_family = AF_INET;
RecvAddr.sin_port = htons(8888);
RecvAddr.sin_addr.s_addr = inet_addr("114.207.246.173");
service.sin_family = AF_INET;
service.sin_addr.s_addr = htonl(INADDR_ANY);
service.sin_port = htons(0);
bind(SendSocket, (SOCKADDR *) &service, sizeof (service));
if (iResult == SOCKET_ERROR) {
wprintf(L"bind failed with error %u\n", WSAGetLastError());
closesocket(SendSocket);
WSACleanup();
return 1;
}
Connect_proxy(SendSocket,RecvAddr);
谢谢!