Linux/Unix Socket Self-connection
When a client try to connect to a server, if client and server are both localhost, self-connection may happen(source port and destination port happened to be the same.). But my problem is, client is not listening to that port, how can self-connection be possible? I found your question after encountering the same phenomenon. The best explanation I found is at Everything About Nothing: TCP Client Self Connect . You can ask for the port assigned to you via getsockname() and compare it to the remote port to detect these self connections: sockaddr_in addr_client; socklet_t len = sizeof(saddr_in);