How to get client IP address before accepting connection in C ++

I am learning C ++ socket programming ... The server program communicates with the socket and starts listening for connection requests ... ok now, how can I list the IP addresses of the listening requests? I know that I can get IP addresses after accepting connections, but I can say that I do not want to accept a connection from a specific IP address ...

+4
source share
3 answers

To ensure optimal performance, this will be solved by filtering in the network stack, but the details of this will depend on the operating system (this is not part of the socket interface, and your application, as a rule, does not even have rights to configure the network stack in this way.)

Another possibility is after accept , by this time the connection has already been accepted (CONNECT ACK) at the TCP level.

I do not think that you can do this in the middle phase, where you prefer it. However, this will not differ much from this after accept .

+2
source

This cannot be done in terms of the standard socket API. On all platforms that I know, the system actually accepts the connection (i.e., Answers with the SYN + TCP ACK datagram) until the application has the ability to track a pending request. p>

+4
source

For Windows only, you can use the WinSock2 WSAAccept() conditional callback function to access client information before accepting a connection and even reject the connection before accepting it.

+3
source

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


All Articles