How to detect unconnected AF_UNIX sockets

Sam Varshavchik mrsam at courier-mta.com
Sun Sep 9 19:43:44 UTC 2012


I'm porting existing code from Linux where a connect() to an AF_UNIX socket  
that exists, but does not have a listener, fails with ECONNREFUSED. This is  
quite agreeable with the comparable scenario in AF_INET, with a connection  
attempt to a port without a listener on it. So the same code handles both  
situations, immediately reporting an error, and without caring much about  
the type of the socket.

But on FreeBSD, according to truss, it seems that a connect() to an AF_UNIX  
socket without a listener still succeeds. A subsequent write() also  
succeeds, and read() blocks.

The fall-out is quite unfortunate, and I was hoping for a way to detect that  
my allegedly connected socket is lying to me, and it's not really connected  
to anything. How would I go about doing that? I tried using the  
LOCAL_CONNWAIT option as documented in unix(4), but that does not appear to  
make any difference, in this situation.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20120909/6bc84fab/attachment.pgp


More information about the freebsd-questions mailing list