mirror of https://github.com/mkerrisk/man-pages
wfix + ffix
This commit is contained in:
parent
f11e5e44f7
commit
6602f61c23
|
@ -181,52 +181,53 @@ In order to assist the programmer in choosing reasonable sizes
|
||||||
for the supplied buffers,
|
for the supplied buffers,
|
||||||
.I <netdb.h>
|
.I <netdb.h>
|
||||||
defines the constants
|
defines the constants
|
||||||
.RS
|
.in +0.5i
|
||||||
.nf
|
.nf
|
||||||
|
|
||||||
# define NI_MAXHOST 1025
|
# define NI_MAXHOST 1025
|
||||||
.br
|
|
||||||
# define NI_MAXSERV 32
|
# define NI_MAXSERV 32
|
||||||
.fi
|
.fi
|
||||||
.RE
|
.in
|
||||||
|
.PP
|
||||||
The former is the constant MAXDNAME in recent versions of BIND's
|
The former is the constant MAXDNAME in recent versions of BIND's
|
||||||
.I <arpa/nameser.h>
|
.I <arpa/nameser.h>
|
||||||
header file.
|
header file.
|
||||||
The latter is a guess based on the services listed
|
The latter is a guess based on the services listed
|
||||||
in the current Assigned Numbers RFC.
|
in the current Assigned Numbers RFC.
|
||||||
.SH EXAMPLE
|
.SH EXAMPLE
|
||||||
The following code tries to get the numeric hostname and service name, for
|
The following code tries to get the numeric hostname and service name,
|
||||||
a given socket address.
|
for a given socket address.
|
||||||
Note that there is no hardcoded reference to
|
Note that there is no hardcoded reference to
|
||||||
a particular address family.
|
a particular address family.
|
||||||
|
|
||||||
.RS
|
.in +0.5i
|
||||||
.nf
|
.nf
|
||||||
struct sockaddr *sa; /* input */
|
struct sockaddr *sa; /* input */
|
||||||
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
||||||
|
|
||||||
if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf,
|
if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf,
|
||||||
sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0)
|
sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0)
|
||||||
printf("host=%s, serv=%s\en", hbuf, sbuf);
|
printf("host=%s, serv=%s\en", hbuf, sbuf);
|
||||||
.fi
|
.fi
|
||||||
.RE
|
.in
|
||||||
|
|
||||||
The following version checks if the socket address has a
|
The following version checks if the socket address has a
|
||||||
reverse address mapping.
|
reverse address mapping.
|
||||||
|
|
||||||
.RS
|
.in +0.5i
|
||||||
.fi
|
.nf
|
||||||
struct sockaddr *sa; /* input */
|
struct sockaddr *sa; /* input */
|
||||||
char hbuf[NI_MAXHOST];
|
char hbuf[NI_MAXHOST];
|
||||||
|
|
||||||
if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf),
|
if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf),
|
||||||
NULL, 0, NI_NAMEREQD))
|
NULL, 0, NI_NAMEREQD))
|
||||||
printf("could not resolve hostname");
|
printf("could not resolve hostname");
|
||||||
else
|
else
|
||||||
printf("host=%s\en", hbuf);
|
printf("host=%s\en", hbuf);
|
||||||
.fi
|
.fi
|
||||||
.RE
|
.in
|
||||||
.PP
|
.PP
|
||||||
An example program use
|
An example program using
|
||||||
.BR getnameinfo ()
|
.BR getnameinfo ()
|
||||||
can be found in
|
can be found in
|
||||||
.BR getaddrinfo (3).
|
.BR getaddrinfo (3).
|
||||||
|
|
Loading…
Reference in New Issue