From owner-freebsd-questions@FreeBSD.ORG Sun Sep 9 19:43:44 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 53789106564A for ; Sun, 9 Sep 2012 19:43:44 +0000 (UTC) (envelope-from mrsam@courier-mta.com) Received: from www.courier-mta.com (www.courier-mta.com [216.254.115.190]) by mx1.freebsd.org (Postfix) with ESMTP id D342E8FC12 for ; Sun, 9 Sep 2012 19:43:43 +0000 (UTC) Received: from monster.email-scan.com (monster.email-scan.com [::ffff:192.168.0.2]) (TLS: TLSv1/SSLv3,256bits,AES256-SHA) by www.courier-mta.com with ESMTPS; Sun, 09 Sep 2012 15:43:43 -0400 id 0000000000060198.00000000504CF16F.00007A63 Received: from monster.email-scan.com (localhost [127.0.0.1]) (IDENT: uid 1000) by monster.email-scan.com with ESMTP; Sun, 09 Sep 2012 15:43:42 -0400 id 0000000000040906.00000000504CF16E.00004C2A Message-ID: X-Mailer: http://www.courier-mta.org/cone/ From: Sam Varshavchik To: freebsd-questions@freebsd.org Date: Sun, 09 Sep 2012 15:43:42 -0400 Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=_monster.email-scan.com-17725-1347219822-0003"; micalg=pgp-sha1; protocol="application/pgp-signature" Subject: How to detect unconnected AF_UNIX sockets X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Sep 2012 19:43:44 -0000 This is a MIME GnuPG-signed message. If you see this text, it means that your E-mail or Usenet software does not support MIME signed messages. The Internet standard for MIME PGP messages, RFC 2015, was published in 1996. To open this message correctly you will need to install E-mail or Usenet software that supports modern Internet standards. --=_monster.email-scan.com-17725-1347219822-0003 Content-Type: text/plain; format=flowed; delsp=yes; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 7bit 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. --=_monster.email-scan.com-17725-1347219822-0003 Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEABECAAYFAlBM8W4ACgkQx9p3GYHlUOIbZgCeKBKMVKMOApXOkIb2R0eY6zWM sv4An0sJM2aIYhXOgEZ30FuIuN+gMDH5 =H0nQ -----END PGP SIGNATURE----- --=_monster.email-scan.com-17725-1347219822-0003--