Limit incoming TCP connections based on IP addresses

Do sockets in C offer any way to limit the number of incoming connections to an IP based socket?

For example, to prevent one client from connecting IP addresses from spam, is there a way to limit the number of IP connections to a socket?

Or should something like this be custom made?

+4
source share
3 answers

I feel that the real intention that you are talking about is throttling, that is, for a specific client / connection, allowing only a fixed number of packets at a given time. This seems like a more realistic use case than allowing / denying more connections.

Most modern languages ​​provide some support, such as java or C #, but not c.

However, this is an elegant approach to its implementation. I myself used it in production code.

throttling implementation

+1
source

There is nothing like this in sockets. You need an individual solution, and better think about it in your firewall.

+1
source

There is nothing for this in the standard socket API, no. Using the standard APIs, the only thing the server code can do is accept() client connection, check its IP address and then close the connection if necessary.

In the case of the Microsoft WinSock API, the WSAAccept() function has a callback that is called before the connection is received from the server queue. The callback function can decide to either accept the connection, reject the connection, or leave it in the queue.

+1
source

Source: https://habr.com/ru/post/1443525/


All Articles