SOCKS5协议成功后,发送数据收不到返回信息是什么情况
我是HOOK的一个棋牌游戏的 ws2_32.connect,然后在里面调用下面的函数。
协商成功后,游戏会自动发送1个数据包,也就是图片上最后一个包,发送到代理服务器上后,就没有返回信息了。望解疑惑。
能搞定的,留下QQ号,我给你发个红包!
int ConnectBySock5(SOCKET socket, string ip, u_short port)
{
char buf[512];
int rc;
if (rc = WSAEventSelect(socket, 0, NULL))//这一个可以不用执行
{
DebugPrint("Error %d : WSAEventSelect Failure!", WSAGetLastError());
}
else
{
DebugPrint("Message : WSAEventSelect successfully!");
}
unsigned long nonBlock = 0;
if (rc = ioctlsocket(socket, FIONBIO, &nonBlock))// 这个真正修改为阻塞类型
{
DebugPrint("Error %d : Set Blocking Failure!", WSAGetLastError());
}
else
{
DebugPrint("Message : Set Blocking successfully!");
}
struct TSock5req1 *proxyreq1;
proxyreq1 = (struct TSock5req1 *)buf;
proxyreq1->Ver = 5;
proxyreq1->nMethods = 1;
proxyreq1->Methods = 2;// m_proxyUserName != "" ? 2 : 0;
DebugPrint("%d %d %d",buf[0], buf[1], buf[2]);
//g_SendBufLen = 3;
//memcpy_s(g_SendBuf, 1024, buf, g_SendBufLen);
Send(socket, buf, 3);
struct TSock5ans1 *proxyans1;
proxyans1 = (struct TSock5ans1 *)buf;
memset(buf, 0, sizeof(buf));
rc = Receive(socket, buf, sizeof(buf));
DebugPrint("proxyans1->Method = %d proxyans1->Ver = %d", proxyans1->Method, proxyans1->Ver);
if (proxyans1->Method != 0 && proxyans1->Method != 2 || proxyans1->Ver != 5)
{
DebugPrint("ConnectBySock5 CONNECT_SERVER_FAIL1");
return CONNECT_SERVER_FAIL;
}
if (proxyans1->Method == 2)
{
int nUserLen = m_proxyUserName.length();
int nPassLen = m_proxyUserPwd.length();
buf[0] = 1;
buf[1] = nUserLen;
memcpy(buf + 2, m_proxyUserName.c_str(), nUserLen);
buf[2 + nUserLen] = nPassLen;
memcpy(buf + 3 + nUserLen, m_proxyUserPwd.c_str(), nPassLen);
//g_SendBufLen = 3 + nUserLen + nPassLen;
// memcpy_s(g_SendBuf, 1024, buf, g_SendBufLen);
Send(socket, buf, 3 + nUserLen + nPassLen);
struct TAuthans *authans;
authans = (struct TAuthans *)buf;
memset(buf, 0, sizeof(buf));
Receive(socket, buf, sizeof(buf));
if (authans->Ver != 1 || authans->Status != 0)
{
DebugPrint("ConnectBySock5 CONNECT_SERVER_FAIL2");
return CONNECT_SERVER_FAIL;
}
}
struct TSock5req2 *proxyreq2;
proxyreq2 = (struct TSock5req2 *)buf;
proxyreq2->Ver = 5;
proxyreq2->Cmd = 1;
proxyreq2->Rsv = 0;
proxyreq2->Atyp = 1;
unsigned long tmpLong = inet_addr(ip.c_str());
unsigned short port1 = ntohs(port);
memcpy((char*)&proxyreq2->other, &tmpLong, 4);
memcpy((char*)(&proxyreq2->other) + 4, &port1, 2);
//Send(socket, buf, sizeof(struct TSock5req2) + 5);
//g_SendBufLen = 10;
//memcpy_s(g_SendBuf, 1024, buf, g_SendBufLen);
Send(socket, buf, 10);
struct TSock5ans2 *proxyans2;
memset(buf, 0, sizeof(buf));
proxyans2 = (struct TSock5ans2 *)buf;
rc = Receive(socket, buf, sizeof(buf));
DebugPrint("len = %d Data = %s", rc, bytesToHexString((byte*)buf,10));
if (proxyans2->Ver != 5 || proxyans2->Rep != 0)
{
DebugPrint("ConnectBySock5 CONNECT_SERVER_FAIL3");
return CONNECT_SERVER_FAIL;
}
//修改socket为非阻塞类型
nonBlock = 1;
if (rc = ioctlsocket(socket, FIONBIO, &nonBlock))
{
DebugPrint("Error %d : Set Non-Blocking Failure!", WSAGetLastError());
//return rc;
}
else
{
DebugPrint("Message : Set Non-Blocking Successful!");
}
//rc = Receive(socket, buf, sizeof(buf));
//DebugPrint("len = %d Data = %s", rc, bytesToHexString((byte*)buf, 10));
return SUCCESS;
}