networking - Winsock, accept request only from specific IP address -


How can I accept a connection request from a Winsock program with only a specific address? Instead of getting TCP rejection, I would like to ignore completely ignored denials.

To create a Winsock program, only accept connections from specific IP addresses, using conditional Use it. First of all, enable the feature:

  socket sd = socket (...); Listen (sd, ...); DWORD nTrue = 1; Setochop (SD, SOL_Cock, SO-CodexNational_ ACCPPT, (four *) and NTRU, Psychof (NTRU));  

Then, modify your acceptance call to see something like this:

  sockaddr_in sin; WSAAccept (SD, (Socadar *) and sin, size (sin), conditional accept checker, 0);  

ConditionalAcceptChecker is a function that you write, which makes this decision whether the stack will accept or reject the connection. If it is rejected, then the remote colleague takes a TCP RST packet, so it knows that it was rejected.

If you want the network stack to miss the connection attempts at a remote address without any address, then you have to do this at a lower level than Winsock. Vista or a version of Windows Server 2008 and later, this command firewall rules will be modified to reflect the expected impact by:

  Nets Adwayrwal firewall add rule name = MyProtocol dir = in = RemotePoint = 1.2.3.4 Localport = 1234 Protocol = TCP Action = Allow  

This is a command, split due to the limitations of formatting on the stack overflow.

What does it say that the remote machine 1.2.3.4 on IP is allowed to connect to TCP port 1234 on this machine. If your firewall is enabled in its default mode, which does not specifically permit traffic, then connections efforts will be removed from all other machines.

On the earlier versions of Windows, going back to XP, the "Net Firewall" syntax to get a different one effect, just type "Netash Firewall" at the command prompt to run through its built-in support. Please.


Comments