Subject: getaddrinfo() interface questions
To: None <>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-net
Date: 12/09/2001 06:43:21
I'm trying to (for the first time) use getaddrinfo(3), and I've got
some questions and comments.

The manpage contains a code sample that is alleged to be suitable for
opening wildcard listening sockets for a given service.  However, it
uses memset to initialize the hints structure, which includes an
implicit assumption that all-0-bits is a suitable nil pointer.  Is this
a bug in the manpage's sample code, or will getaddrinfo not be defined
on architectures where all-0-bits is not a nil pointer?  (I realize
NetBSD doesn't currently have any (and possibly never will), but surely
getaddrinfo() isn't supposed to be tied to NetBSD!)  If the latter,
wouldn't it be a good idea to explicitly mention this in the manpage?
(If the former, I definitely feel the sample code should be fixed.)

The same code passes an ai_addr pointer directly to connect().  While I
can see wording that implies that the ai_addr pointer points to
suitably aligned storage, I think that this too should be stated

Also, the code is supposedly server code and hence should be using
bind(), not connect().  (Probably a too-hasty cut-and-paste....)

The code for getaddrinfo also contains a comment indicating that
PF_UNSPEC hints disallow numeric servname strings.  However, I see no
such limitation in the actual code or in the manpage, and a test call
with a numeric servname string and PF_UNSPEC hints does not return an
error.  Which is right, the comment or the code/manpage?  If the
comment, what is the correct way to do "listen on port N for all
address families I can"?  Surely not wire the list [AF_INET,AF_INET6]
into the code!  I can understand that some address families may not
have port numbers or otherwise be unable to use whatever string is
passed in, but shouldn't getaddrinfo() just filter them out of the list
it returns?

Or should I just send-pr?  For the moment, I haven't done that because
I would particularly like an answer to the questions for my own
code, not just for the sake of improving the manpage.

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B