PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 22, 2022

[FIXED] Why does OS X allow listening on the same TCP port twice?

 October 22, 2022     macos, netcat, sockets     No comments   

Issue

I was trying to debug port allocation problems in Jenkins on OS X by listening to certain ports with netcat, which led to some weird results.


In a terminal on OS X 10.8.2:

$ uname -rs
Darwin 12.2.1

$ nc -l 54321

Then in an second terminal:

$ nc -l 54321

And in a third terminal, lsof shows that both instances have bound to the same port:

$ lsof -i | grep 54321
nc  70706 chris    3u  IPv4 0x55618c024692f4d1      0t0  TCP *:54321 (LISTEN)
nc  70769 chris    3u  IPv4 0x55618c0232cb8661      0t0  TCP *:54321 (LISTEN)

On Linux:

First terminal:

$ uname -rs
Linux 3.2.0-34-generic

$ nc -l 54321

Second terminal:

$ nc -l 54321
nc: Address already in use

Why doesn't OS X also report that the address is already in use?


Solution

The binary on OS X is setting the SO_REUSEPORT socket option, which allows completely duplicate bindings (setsockopt on OS X). You can verify this using dtrace on OS X.

The netcat binary on Linux does not do this, so you get a bind error as expected. Again, you can verify that using strace. I belive SO_REUSEPORT is deprecated, or not even available on newer Linux kernels.



Answered By - Neal
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing