![]() |
| | #1 |
| Registered User Join Date: Apr 2008
Posts: 309
| socks4/5 proxy question From other topics I have seen terms like blocking/nonblocking and I think that one of these apply here. I have one main do loop that is basically is a recv() loop. When I make the connection to the server, where do I insert that recv? initconn() makes a connection to the server. I only support socks4 atm. Code: do
{
err = recv(sckclient, recvbuf, 2048, 0);
if (err > 0)
{
msgnum++;
if (msgnum == 1)
{
if ((recvbuf[0] == 0x04) && (recvbuf[1] == 0x01))
{
sckdestin = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sckdestin == INVALID_SOCKET)
{
printf("Invalid Socket\n");
errout(WSAGetLastError());
WSACleanup();
return 1;
}
err = initconn(sckdestin, destinservice);
if (acceptdeny(sckclient, err) == 0x01)
return 1;
printf("SOCKS 4 Connection established with TCP/IP stream connection\n");
}
else
{
printf("SOCKS 4 Connection failed\n");
acceptdeny(sckclient, 0x02);
}
}
else
{
printf("Message Received\n");
}
}
else if (err == 0)
printf("Connection closing...\n");
else
{
errout(WSAGetLastError());
closesocket(sckclient);
WSACleanup();
return 1;
}
} while (err > 0);
|
| carrotcake1029 is offline | |
| | #2 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,650
| > err = initconn(sckdestin, destinservice); So where did these two parameters get defined? Also, your initial recv() makes no account of fragmentation. |
| Salem is offline | |
| | #3 |
| Registered User Join Date: Apr 2008
Posts: 309
| Sorry for maybe not being as clear as I'd hoped, but here is how they are defined... Code: SOCKET sckdestin; struct sockaddr_in destinservice; My question is just a logic one. If my client recv loop is always looping, where do I put my server recv loop in order for me to not lose data from either one. |
| carrotcake1029 is offline | |
| | #4 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,650
| destinservice = someRandomBitOfMagic; Is that what happens, or is there something else? > I am unsure what you mean by how recv makes no account of fragmentation. If you send 10 bytes in a single send() call, then there's NO guarantee that the recv() will get those 10 bytes in a single call. You could easily get them as 6 bytes + 4 bytes. Or in extreme cases, 1 at a time. If your code doesn't allow for that, then it's not going to work. |
| Salem is offline | |
| | #5 |
| Registered User Join Date: Apr 2008
Posts: 309
| Good point about the fragmentation thing, shouldn't be too hard to fix. I remember having issues like that from my BASIC days. If you really want to know about destinservice, here is how it gets modified: Code: serv.sin_family = AF_INET;
serv.sin_addr.s_addr = ip;
serv.sin_port = port;
I tend to write code to get the job done first, then make it all spiffy-like later. My real question though is how do I get my program to be able to receive data on 2 different sockets at the same time. |
| carrotcake1029 is offline | |
| | #6 |
| Registered User Join Date: Apr 2008
Posts: 282
| use either select() or poll(). |
| root4 is offline | |
| | #7 |
| Registered User Join Date: Apr 2008
Posts: 309
| Thank you. I am assuming select() is for Win32 and poll() is for unix variants? |
| carrotcake1029 is offline | |
| | #8 |
| Registered User Join Date: Apr 2008
Posts: 282
| both exist on unix. I don't know for windows. |
| root4 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Force connection through proxy | ShadowBeast | C# Programming | 6 | 05-02-2007 01:35 PM |
| Simple Proxy | Lina | C Programming | 0 | 04-01-2007 12:36 PM |
| Connecting through a proxy... | jverkoey | Networking/Device Communication | 1 | 07-20-2005 11:53 AM |
| Alice.... | Lurker | General Discussions | 16 | 06-20-2005 02:51 PM |
| Question... | TechWins | A Brief History of Cprogramming.com | 16 | 07-28-2003 09:47 PM |