From owner-freebsd-hackers@FreeBSD.ORG Sun Feb 3 14:12:47 2008 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3F19F16A418 for ; Sun, 3 Feb 2008 14:12:47 +0000 (UTC) (envelope-from wundram@beenic.net) Received: from mail.beenic.net (mail.beenic.net [83.246.72.40]) by mx1.freebsd.org (Postfix) with ESMTP id 0C40C13C45B for ; Sun, 3 Feb 2008 14:12:46 +0000 (UTC) (envelope-from wundram@beenic.net) Received: from phoenix (hnvr-4dbbaf92.pool.einsundeins.de [77.187.175.146]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.beenic.net (Postfix) with ESMTP id DAC49A44529 for ; Sun, 3 Feb 2008 14:49:04 +0100 (CET) From: "Heiko Wundram (Beenic)" Organization: Beenic Networks GmbH To: hackers@freebsd.org Date: Sun, 3 Feb 2008 14:50:18 +0100 User-Agent: KMail/1.9.7 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200802031450.19420.wundram@beenic.net> Cc: Subject: getaddrinfo() spec doesn't match behaviour X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Feb 2008 14:12:47 -0000 Hey all! Before I go post this as a PR (or go about fixing the libc code), I just wanted to ask whether this is a known issue (and I simply haven't been able to find it), or if it's simply my stupidity that makes this fail. Basically, I have the following code: addrinfo hints; addrinfo* res; // Fill in hints structure. memset(&hints,0,sizeof(hints)); hints.ai_flags = AI_PASSIVE | AI_V4MAPPED; hints.ai_family = SERV.m_ipv6 ? AF_INET6 : AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; // Query address info. if( ( rv = getaddrinfo(bindaddr,port,&hints,&res) ) ) { if( rv == EAI_SYSTEM ) throw OSError("Failed resolving service and/or bind address"); throw ValueError(gai_strerror(rv)); } Now, according to the man-page of getaddrinfo() and my previous knowledge, this should work fine (for some bindaddr and port coming into this function as const char*), but, alas, it doesn't, and fails with EAI_BADFLAGS. Tracing through the libc code for getaddrinfo(), the cause of this failing is pretty obvious: hints.ai_flags is logically anded with AI_MASK at the beginning of the function, and AI_MASK (at least in my local netdb.h header) does not contain the flag AI_V4MAPPED. In case the result of that is non-zero (which it is due to me specifying AI_V4MAPPED), the function returns EAI_BADFLAGS. After that, getaddrinfo() does some checks on AI_V4MAPPED and AI_ALL (masking the respective flags in case the ai_family isn't AF_INET6), which are basically superfluous (as they can never be set anyway due to AI_MASK), but I didn't find any other reference to the flag in the whole of lib/libc/net/getaddrinfo.c, so I actually don't know whether the cause of this failing is that it simply isn't implemented (completely), or there's any other reason for AI_MASK not to contain these flags that I haven't grasped so far. If anyone out there can shed a hint on this, I'd be grateful, even if it's just the fact that my netdb.h installation is broken. Thanks! -- Heiko Wundram Product & Application Development