I am trying to understand how can it be possible to start multiple processes listening on the same TCP {IP, Port} pair on Windows XP.
For example, I can start two ncat.exe
programs listening on port 371. The second one is started without any problem and receives incoming connections while the first one does not. Once the process lastly started is terminated, the first one receives them.
netstat -a -n | find "LISTENING"
TCP 0.0.0.0:371 0.0.0.0:0 LISTENING
TCP 0.0.0.0:371 0.0.0.0:0 LISTENING
Assuming this a Windows (XP) behaviour, how can it be a safe & secure behaviour? It means one can "overload" any already listening port instead of getting the usual "address already in use" error message, and simply bypass firewalls with rules just saying "any incoming TCP connections on port 371 are allowed".
SO_REUSEADDR socket option is interpreted differently in windows i.e. in Linux it would allow you to reuse the same socket unless all of the five tuple (src/dst port/ip and protocol are exactly same).
However, windows actually allow you to steal the socket. I would quote a much better written answer here elaborating both.