From owner-freebsd-hackers@FreeBSD.ORG Thu Jan 31 16:00:38 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BD29B16A417 for ; Thu, 31 Jan 2008 16:00:38 +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 7471413C461 for ; Thu, 31 Jan 2008 16:00:38 +0000 (UTC) (envelope-from wundram@beenic.net) Received: from [192.168.1.38] (a89-182-148-8.net-htp.de [89.182.148.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.beenic.net (Postfix) with ESMTP id 40D3FA44529; Thu, 31 Jan 2008 17:00:17 +0100 (CET) From: "Heiko Wundram (Beenic)" Organization: Beenic Networks GmbH To: Dag-Erling =?utf-8?q?Sm=C3=B8rgrav?= , freebsd-hackers@freebsd.org Date: Thu, 31 Jan 2008 17:01:49 +0100 User-Agent: KMail/1.9.7 References: <200801310923.16029.wundram@beenic.net> <86zlumvwob.fsf@ds4.des.no> In-Reply-To: <86zlumvwob.fsf@ds4.des.no> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200801311701.49792.wundram@beenic.net> Cc: Subject: Re: OT: getting the protocol family of a file descriptor 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: Thu, 31 Jan 2008 16:00:38 -0000 Am Donnerstag, 31. Januar 2008 16:31:32 schrieben Sie: > "Heiko Wundram (Beenic)" writes: > > I'm currently in the need to get the protocol family that was used to > > create a socket (and passed via a unix domain socket to another > > program), and I've not really come up with a proper scheme other than > > to use getsockname and retrieve sa_family from the resulting socket > > (which currently matches the socket domain and historically has, but > > why take the chances ;-)). > > This is the correct way to do it, I don't understand why you think it > might not work in the future. > > > Is there any other "better" way to get at the domain (protocol family) > > of a socket? > > Why should there be a better way? Just like there is getsockopt(fd,SOL_SOCKET,SO_TYPE), I'd (somehow) assume that there's a getsockopt(fd,SOL_SOCKET,SO_DOMAIN/SO_FAMILY). I can understand that the actual protocol used to create a socket is irrelevant in most of the applications which get sockets from "outside" (as long as the type they want matches the type of the passed socket), and I've not found any (general [!], of course there's specific ways depending on the PF) way to get at that yet from a file-descriptor, but I can't understand why this also applies to the domain, as for example in case you're trying to format the address a socket is bound/connected to in a user-readable manner, you will have different code depending on the actual address type. Currently, you're basically required to do a getsockname to a struct sockaddr_storage and typecast that to the actual socket addres type based on the ss_family member (to be able to pass it to one of the *_ntop-functions, for example), but generally, I don't find this too beautiful. But, maybe, that's just my (horribly broken) taste. ;-) -- Heiko Wundram Product & Application Development