2

Here is simple server listening to port 80 of localhost:

nc -4 --listen 127.0.0.1 80

Here is the client to connect to server on localhost using source port same as destination port of server:

nc -4 --source-port 80 --source 127.0.0.1 127.0.0.1 80

I get error:

libnsock mksock_bind_addr(): Bind to 127.0.0.1:80 failed (IOD #1): Address already in use (98)

According to the rule that states: { SRC-IP, SRC-PORT, DST-IP, DST-PORT, PROTO } must be unique, the creation of this connection should be allowed. There was no such tuple before attempting to create the connection for the first time. Why is this not allowed? I'm running Fedora 23 with kernel 4.4.6.

  • I'm not quite sure how to answer this, maybe I didn't get the question. But it is simply impossible when connecting to a port, it needs to open a source port to receive the answers on. If that's already in use, it won't work. Usually those ports are randomly opened in the higher port area. – Jakob Lenfers Apr 17 '16 at 20:27
3

What you are attempting to do doesn't make any sense. You are trying to create two TCP sockets with the same 5-tuple { SRC-IP, SRC-PORT, DST-IP, DST-PORT, PROTO } therefore the two sockets would be indistinguishable from each other.

Think of it this way: if this were allowed, then, when a TCP packet arrives sourced from 127.0.0.1:80 and destined to 127.0.0.1:80, which socket receives it? Both?

  • 1
    Ahaa. The point is that two TCP sockets are created. My mistake is that I believed there should be one socket because it is localhost. – Majid Azimi Apr 17 '16 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.