I think you are trying to do this to prevent TCP negotiation if it matches a specific IP. As far as I know, this is not possible in the socket layer. TCP negotiations will take place, and by the time you arrive to accept the socket, negotiations have already taken place.
It is technically possible that you could somehow look into this state information, but this will not do what you expect from it. Accepting a socket is the interface between the kernel that was already doing the work and your program that would like to read the data. The simplest thing is to accept the socket and load it if you do not want it.
If you want to avoid TCP negotiation first, you need to use iptables.
source share