http://www.bford.info/pub/net/p2pnat/index.html
Apparently SO_REUSEADDR allows the same local endpoint to be used for connect AND accept which would bypass the problem noted in this paper where sim open can fail for behaviour characteristic 2.
So with SO_REUSEADDR enabled you can just listen on the same endpoint for listen() and connect() and the code will work fine. (Note: BSD will need the SO_REUSEPORT option set though.)
http://www.bford.info/pub/net/p2pnat/index.html Apparently SO_REUSEADDR allows the same local endpoint to be used for connect AND accept which would bypass the problem noted in this paper where sim open can fail for behaviour characteristic 2.
So with SO_REUSEADDR enabled you can just listen on the same endpoint for listen() and connect() and the code will work fine. (Note: BSD will need the SO_REUSEPORT option set though.)