Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Jan 2008 17:01:49 +0100
From:      "Heiko Wundram (Beenic)" <wundram@beenic.net>
To:        Dag-Erling =?utf-8?q?Sm=C3=B8rgrav?= <des@des.no>, freebsd-hackers@freebsd.org
Subject:   Re: OT: getting the protocol family of a file descriptor
Message-ID:  <200801311701.49792.wundram@beenic.net>
In-Reply-To: <86zlumvwob.fsf@ds4.des.no>
References:  <200801310923.16029.wundram@beenic.net> <86zlumvwob.fsf@ds4.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help
Am Donnerstag, 31. Januar 2008 16:31:32 schrieben Sie:
> "Heiko Wundram (Beenic)" <wundram@beenic.net> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200801311701.49792.wundram>