当我发送我的最后一个数据包时,我有一个问题,就像我在评论中所说的那样,我得到一个警告,说我每次运行时都会返回一个意外的答案,后跟一个不同的十六进制数。 /> 我正在使用Proxifier来测试它,当我尝试连接到谷歌时,它总是给我这个:
[06:22] Starting: Test 1: Connection to the Proxy Server
[06:22] IP Address: 127.0.0.1
[06:22] Connection established
[06:22] Test passed.
[06:22] Starting: Test 2: Connection through the Proxy Server
[06:22] Authentication was successful.
[06:22] Warning : the proxy server has returned an unexpected answer (0x32).
[06:22] Connection to www.google.com:80 established through the proxy server.
`void HandleConnection()
{
cout << "You are connected !!!" << endl;
char temp[30];
Recv(temp, sizeof(temp));
if(temp[0] == 5) // test for version
{
cout << "Version good" << endl;
char* reply = new char[2];
reply[0] = 5; // version
reply[1] = 0; // method choosed (no auth required)
Send(reply, sizeof(reply));
delete [] reply;
memset(temp, '\0', sizeof(temp));
Recv(temp, sizeof(temp));
temp[sizeof(temp)] = '\0';
if(temp[0] == 5) // test for version
{
if(temp[4] == 14) // test for lenght of www.google.com
{
char* domain = new char[temp[4]];
for(int i = 0; i < temp[4]; ++i)
{
domain[i] = temp[i + 5]; // copy domain name
}
domain[14] = '\0';
cout << endl;
cout << domain << endl;
int domainLen = strlen(domain);
//with this packet i get a warning that i send an unexpected answer
char* reply = new char[domainLen + 6];
reply[0] = 5; // version
reply[1] = 0; // succed
reply[2] = 0; // reserved
reply[3] = 3; // its a domain
reply[4] = domainLen; // lenght of domain
for(int j = 0; j < domainLen; ++j)
{
reply[j + 5] = domain[j];
}
reply[4 + domainLen] = 80; // port
Send(reply, domainLen);
delete [] reply;
}
}
}
}`
答案 0 :(得分:1)
遵循这些代码行:
if(temp[4] == 14) // test for lenght of www.google.com
{
char* domain = new char[temp[4]];
//....
也许它应该是
domain[13] = '\0';
代替domain[14] = '\0';