Click to See Complete Forum and Search --> : How to reject unwanted connects in Winsock


Randy C
September 10th, 2003, 04:09 PM
I want to make my winsock server as 'self healing' as possible which means that the listened socket will remain listening even after a connection is accepted. It's only a one client at a time system, but if a client goes away without my knowing, and tries to re-connect, I'll detect that and close the old data socket, and connect the new one. But what i want to know, is there any way to make listen() automatically reject requests that don't come from a specified IP address? Of course I could accept any incoming connection, then check it's address, and clos it if it's somebody i don't want to talk to. But is there an easier way?

mistersulu
September 10th, 2003, 04:49 PM
randy,

i know of one way that is definitely not easier. you could use 'pcap' or 'winpcap' to capture packets that are normally behind the scenes in Winsock. that way ur app would get the first packet sent from the peer requesting a connection, including the ip in the header. just a possibility, although it is harder and slower than accepting and authenticating.

EDIT:
just a note, winpcap is open source... maybe you can find some ideas in the code,
http://winpcap.polito.it/install/default.htm

sulu

filthy_mcnasty
September 12th, 2003, 01:15 AM
i dont have much good info for you either.

what i do when i want to limit IP addresses that can connect i immediately get the IP off of the socket returned by the accept call. use getpeername for this.

what i also do is make the first few bytes of everything sent have to match something the server's expecting and if it doesn't buh bye connection. this will help kill 'unauthorized' connections.

if you want the server to keep listening then you'll need a thread w/ loop of sorts or handle it all asynchrously