Re: OT: getting the protocol family of a file descriptor
- From: "Heiko Wundram (Beenic)" <wundram@xxxxxxxxxx>
- Date: Thu, 31 Jan 2008 17:01:49 +0100
Am Donnerstag, 31. Januar 2008 16:31:32 schrieben Sie:
"Heiko Wundram (Beenic)" <wundram@xxxxxxxxxx> 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
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"
- Follow-Ups:
- Re: OT: getting the protocol family of a file descriptor
- From: Dag-Erling Smørgrav
- Re: OT: getting the protocol family of a file descriptor
- References:
- OT: getting the protocol family of a file descriptor
- From: Heiko Wundram (Beenic)
- Re: OT: getting the protocol family of a file descriptor
- From: Dag-Erling Smørgrav
- OT: getting the protocol family of a file descriptor
- Prev by Date: Re: OT: getting the protocol family of a file descriptor
- Next by Date: Re: OT: getting the protocol family of a file descriptor
- Previous by thread: Re: OT: getting the protocol family of a file descriptor
- Next by thread: Re: OT: getting the protocol family of a file descriptor
- Index(es):
Relevant Pages
|
|