From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS6939 64.71.128.0/18 X-Spam-Status: No, score=-2.3 required=3.0 tests=AWL,BAYES_00, MSGID_FROM_MTA_HEADER,URIBL_BLOCKED shortcircuit=no autolearn=unavailable version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.kgio.general Subject: Re: Fixes for OpenBSD Date: Thu, 5 May 2011 11:45:25 -0700 Message-ID: <20110505184525.GA21251@dcvr.yhbt.net> References: <20110505181846.GB9693@jeremyevans.local> <20110505181846.GB9693@jeremyevans.local> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1304621148 28457 80.91.229.12 (5 May 2011 18:45:48 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 5 May 2011 18:45:48 +0000 (UTC) To: kgio@librelist.com Original-X-From: kgio@librelist.com Thu May 05 20:45:44 2011 Return-path: Envelope-to: gclrkg-kgio@m.gmane.org List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: kgio@librelist.com Xref: news.gmane.org gmane.comp.lang.ruby.kgio.general:18 Archived-At: Received: from zedshaw.xen.prgmr.com ([64.71.167.205]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QI3YW-00036Z-5L for gclrkg-kgio@m.gmane.org; Thu, 05 May 2011 20:45:44 +0200 Received: from zedshaw.xen.prgmr.com (localhost [IPv6:::1]) by zedshaw.xen.prgmr.com (Postfix) with ESMTP id 1885C21C983 for ; Thu, 5 May 2011 18:46:47 +0000 (UTC) Jeremy Evans wrote: other changes look fine > getaddrinfo gives an error if you use AF_UNSPEC as the ai_family, > the man page says PF_UNSPEC should be used. And other entries > in hints need to be 0 or NULL. I'm not sure why OpenBSD differs from POSIX here: http://pubs.opengroup.org/onlinepubs/009695399/functions/getaddrinfo.html Even though PF_UNSPEC == AF_UNSPEC in most systems, I'd rather go with the following patch and single out OpenBSD (and maybe other *BSDs) since "AF_" (address family) makes more sense than "PF_" (protocol family): diff --git a/ext/kgio/connect.c b/ext/kgio/connect.c index 3b40054..e4ee9fb 100644 --- a/ext/kgio/connect.c +++ b/ext/kgio/connect.c @@ -1,6 +1,21 @@ #include "kgio.h" #include "sock_for_fd.h" +/* + * OpenBSD getaddrinfo() requires PF_UNSPEC, but POSIX (and Linux) docs + * say AF_UNSPEC. AF_UNSPEC is typically PF_UNSPEC anyways, but apparently + * OpenBSD differs. + * + * http://www.openbsd.org/cgi-bin/man.cgi?query=getaddrinfo&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html + * http://pubs.opengroup.org/onlinepubs/009695399/functions/getaddrinfo.html + */ +#if defined(__OpenBSD__) +# if defined(AF_UNSPEC) +# undef AF_UNSPEC +# endif +# define AF_UNSPEC PF_UNSPEC +#endif + static void close_fail(int fd, const char *msg) { int saved_errno = errno; @@ -69,6 +84,7 @@ static VALUE tcp_connect(VALUE klass, VALUE ip, VALUE port, int io_wait) rc = snprintf(ipport, sizeof(ipport), "%u", uport); if (rc >= (int)sizeof(ipport) || rc <= 0) rb_raise(rb_eArgError, "invalid TCP port: %u", uport); + memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; -- Eric Wong