wfix + ffix

This commit is contained in:
Michael Kerrisk 2007-05-28 10:45:57 +00:00
parent f11e5e44f7
commit 6602f61c23
1 changed files with 24 additions and 23 deletions

View File

@ -181,52 +181,53 @@ In order to assist the programmer in choosing reasonable sizes
for the supplied buffers,
.I <netdb.h>
defines the constants
.RS
.in +0.5i
.nf
# define NI_MAXHOST 1025
.br
# define NI_MAXSERV 32
.fi
.RE
.in
.PP
The former is the constant MAXDNAME in recent versions of BIND's
.I <arpa/nameser.h>
header file.
The latter is a guess based on the services listed
in the current Assigned Numbers RFC.
.SH EXAMPLE
The following code tries to get the numeric hostname and service name, for
a given socket address.
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.
.RS
.in +0.5i
.nf
struct sockaddr *sa; /* input */
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
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\en", hbuf, sbuf);
if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf,
sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0)
printf("host=%s, serv=%s\en", hbuf, sbuf);
.fi
.RE
.in
The following version checks if the socket address has a
reverse address mapping.
.RS
.fi
struct sockaddr *sa; /* input */
char hbuf[NI_MAXHOST];
.in +0.5i
.nf
struct sockaddr *sa; /* input */
char hbuf[NI_MAXHOST];
if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf),
NULL, 0, NI_NAMEREQD))
printf("could not resolve hostname");
else
printf("host=%s\en", hbuf);
if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf),
NULL, 0, NI_NAMEREQD))
printf("could not resolve hostname");
else
printf("host=%s\en", hbuf);
.fi
.RE
.in
.PP
An example program use
An example program using
.BR getnameinfo ()
can be found in
.BR getaddrinfo (3).