getnameinfo() and sa_len

From: Jeroen Massar
Date: Thu Feb 19 2004 - 09:11:32 EST


-----BEGIN PGP SIGNED MESSAGE-----

Hi,

A small google on getnameinfo() and sa_len produced that
Linux apparently doesn't have any sa_len field in the sockaddr
structures, while every other OS (including your beloved Windows ;)
and the various BSD's have it, apparently it is 'optional', but
from the EXAMPLES section on a Debian unstable's getnameinfo(3) page:
8<--------
EXAMPLES
The following code tries to get the numeric hostname and service
name, for a given socket address. Note
that there is no hardcoded reference to a particular address family.

struct sockaddr *sa; /* input */
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];

if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf,
sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0)
printf("host=%s, serv=%s\n", hbuf, sbuf);
- -------->8

Notez bien this page is from "Linux Man Page 2000-12-11 getnameinfo(3)"
The same page is included on Fedora Core 1 btw.
I saw reports of sa_len not being supported by Alan Cox from 1999:
http://www.ussg.iu.edu/hypermail/linux/net/9908.1/0018.html
RedHat has it apparently:
http://sources.redhat.com/ecos/docs-latest/ref/net-common-tcpip-manpages-getnameinfo.html

So what is up with the documentation, or better, how can I as an
application programmer get a valid sa_len for getnameinfo() ? :)
It is easier if it is stuck in the sockaddr, than when I have to
ifdef all the way around every app and pass it along everywhere.
Making a own struct full_sockaddr { uint8_t sa_len; struct sockaddr sa; };
is just completely silly to make it easier to port apps back and
forth between the various BSD's, Windows and Linux...

Greets,
Jeroen

-----BEGIN PGP SIGNATURE-----
Version: Unfix PGP for Outlook Alpha 13 Int.
Comment: Jeroen Massar / http://unfix.org/~jeroen

iQA/AwUBQDTDmCmqKFIzPnwjEQIyFgCggrXM0Er/NQHDBD/gjH3moVJSpf8AoK1B
aR1Z19gzaedRj0Hgx+EA6ZfP
=glg2
-----END PGP SIGNATURE-----

-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html