February 1st, 2011, 02:39 PM
proxy server problem c++
I'm trying to build a proxy server using socks5 tcp/ip. I'm having problems when sendind packets to the client,i get the following errors when trying to connect to google.com. For client i use Proxifier:
And this is my code where i receive and send packets:
[25:23] Starting: Test 1: Connection to the Proxy Server
[25:23] IP Address: 127.0.0.1
[25:23] Connection established
[25:23] Test passed.
[25:23] Starting: Test 2: Connection through the Proxy Server
[25:23] Authentication was successful.
[25:24] Warning : the proxy server has returned an unexpected answer (0xFFFFFF84).
[25:24] Connection to www.google.com:80 established through the proxy server.
[25:24] Error : the reply that was recieved from the target host does not look like a usual Web Server reply.
Please make sure that the target host is a Web Server.
The error may also indicate that the proxy server is not operating properly.
Target host reply = www.google.c
[25:24] Test failed.
[25:24] Testing Finished.
I hope i find someone who can help me,i'm strugling for days,with no answer.Thanks in advanced.
cout << "You are connected !!!" << endl;
// Client sends 5,1,0 (version,nr of methods, the method(0 = no auth))
if(temp == 5) // test for version
char* reply = new char;
reply = 5; // version
reply = 0; // method choosed (no auth required)
Send(reply, sizeof(reply)); // i send 5,0 (version,method choosed) i get warning that i send an unexpected answer
delete  reply;
memset(temp, '\0', sizeof(temp));
// i receive 5,0,0,3,14,www.google.com,80 (version,command, reserved,type of address, dest adress, dest port)
int version = static_cast<int>(temp);
int connectionType = static_cast<int>(temp);
int adrressType = static_cast<int>(temp);
int domainLen = static_cast<int>(temp);
char* destinationAdrress = static_cast<char*>(&temp);
int port1 = static_cast<int>(temp);
int port2 = static_cast<int>(temp);
int packetSize = sizeof(temp);
cout << "Size of packet: " << packetSize << endl;
cout << "Version: " << version << endl;
cout << "Conn type: " << connectionType << endl;
cout << "Adrr type: " << adrressType << endl;
cout << "Domain lenght: " << domainLen << endl;
cout << "Destination adrress: " << destinationAdrress << endl;
cout << "Destination port: " << port2 << endl;
if(version == 5) // test for version
reply = 5; // version
reply = 0; // succed
reply = 0; // reserved
reply = 3; // its a domain
reply = domainLen;; // lenght of domain
for(int j = 0; j < domainLen; ++j)
reply[j + 5] = destinationAdrress[j];
reply[5 + domainLen] = htons(port1);
reply[6 + domainLen] = htons(port2);
February 2nd, 2011, 07:09 PM
Re: proxy server problem c++
The variable named "reply" is a char pointer, and its size is therefore 4 bytes.
Thus, all of your calls to "Send(reply, sizeof(reply))" are wrong, since they always send 4 bytes.
PS: Your call to memset on "temp" is also wrong, for the same reason.
Click Here to Expand Forum to Full Width