Subject: any way to let host act as TCP server OR client on same IP/port?

From: Chris Friesen <[email-masked]>
Date: Wed, 13 Jul 2011 10:30:52 -0600

I've been asked an interesting question about TCP.  We have some people 
that want to set up a TCP socket that can listen for connections on a 
given IP/port, but also initiate connections from that same IP/port. 
(Only one at a time, of course.)

The TCP state machine seems to allow this (moving from LISTEN to 
SYN_SENT) but it's not a normal transition.

Is there any way to do this using the socket API?

I thought up a hack whereby we could use NFQUEUE to detect an incoming 
SYN and delay it while we call listen() on the socket.  Is there any 
better way to do this?

Thanks,

Chris

-- 
Chris Friesen
Software Developer
GENBAND
[email-masked]
www.genband.com