Manual Pages for Linux CentOS command on man getnameinfo
MyWebUniversity

Manual Pages for Linux CentOS command on man getnameinfo

GETNAMEINFO(3) Linux Programmer's Manual GETNAMEINFO(3)

NAME

getnameinfo - address-to-name translation in protocol-independent man‐ ner SYNOPSIS

#include

#include int getnameinfo(const struct sockaddr *sa, socklent salen, char *host, sizet hostlen, char *serv, sizet servlen, int flags); Feature Test Macro Requirements for glibc (see featuretestmacros(7)): getnameinfo(): POSIXCSOURCE >= 1 || XOPENSOURCE || POSIXSOURCE DESCRIPTION The getnameinfo() function is the inverse of getaddrinfo(3): it con‐ verts a socket address to a corresponding host and service, in a proto‐

col-independent manner. It combines the functionality of gethost‐ byaddr(3) and getservbyport(3), but unlike those functions, getname‐

info() is reentrant and allows programs to eliminate IPv4-versus-IPv6 dependencies. The sa argument is a pointer to a generic socket address structure (of type sockaddrin or sockaddrin6) of size salen that holds the input IP address and port number. The arguments host and serv are pointers to

caller-allocated buffers (of size hostlen and servlen respectively)

into which getnameinfo() places null-terminated strings containing the host and service names respectively. The caller can specify that no hostname (or no service name) is required by providing a NULL host (or serv) argument or a zero hostlen (or servlen) argument. However, at least one of hostname or service name must be requested. The flags argument modifies the behavior of getnameinfo() as follows: NINAMEREQD If set, then an error is returned if the hostname cannot be determined. NIDGRAM If set, then the service is datagram (UDP) based rather than stream (TCP) based. This is required for the few ports

(512-514) that have different services for UDP and TCP. NINOFQDN If set, return only the hostname part of the fully qualified domain name for local hosts. NINUMERICHOST If set, then the numeric form of the hostname is returned. (When not set, this will still happen in case the node's name cannot be determined.) NINUMERICSERV If set, then the numeric form of the service address is returned. (When not set, this will still happen in case the service's name cannot be determined.) Extensions to getnameinfo() for Internationalized Domain Names Starting with glibc 2.3.4, getnameinfo() has been extended to selec‐ tively allow hostnames to be transparently converted to and from the Internationalized Domain Name (IDN) format (see RFC 3490, Internation‐ alizing Domain Names in Applications (IDNA)). Three new flags are defined: NIIDN If this flag is used, then the name found in the lookup process is converted from IDN format to the locale's encoding if neces‐

sary. ASCII-only names are not affected by the conversion, which makes this flag usable in existing programs and environ‐ ments. NIIDNALLOWUNASSIGNED, NIIDNUSESTD3ASCIIRULES Setting these flags will enable the IDNAALLOWUNASSIGNED (allow unassigned Unicode code points) and IDNAUSESTD3ASCIIRULES (check output to make sure it is a STD3 conforming hostname) flags respectively to be used in the IDNA handling. RETURN VALUE On success 0 is returned, and node and service names, if requested, are

filled with null-terminated strings, possibly truncated to fit the specified buffer lengths. On error one of the following nonzero error codes is returned: EAIAGAIN The name could not be resolved at this time. Try again later. EAIBADFLAGS The flags argument has an invalid value. EAIFAIL A nonrecoverable error occurred. EAIFAMILY The address family was not recognized, or the address length was invalid for the specified family. EAIMEMORY Out of memory. EAINONAME The name does not resolve for the supplied arguments. NINAMEREQD is set and the host's name cannot be located, or neither hostname nor service name were requested. EAIOVERFLOW The buffer pointed to by host or serv was too small. EAISYSTEM A system error occurred. The error code can be found in errno. The gaistrerror(3) function translates these error codes to a human readable string, suitable for error reporting. FILES /etc/hosts /etc/nsswitch.conf /etc/resolv.conf VERSIONS getnameinfo() is provided in glibc since version 2.1. CONFORMING TO

RFC 2553, POSIX.1-2001. NOTES In order to assist the programmer in choosing reasonable sizes for the supplied buffers, defines the constants

#define NIMAXHOST 1025

#define NIMAXSERV 32 Since glibc 2.8, these definitions are exposed only if one of the fea‐ ture test macros BSDSOURCE, SVIDSOURCE, or GNUSOURCE is defined. The former is the constant MAXDNAME in recent versions of BIND's header file. The latter is a guess based on the ser‐ vices listed in the current Assigned Numbers RFC. EXAMPLE 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 */ socklent len; /* input */ char hbuf[NIMAXHOST], sbuf[NIMAXSERV]; if (getnameinfo(sa, len, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NINUMERICHOST | NINUMERICSERV) == 0)

printf("host=%s, serv=%s\n", hbuf, sbuf); The following version checks if the socket address has a reverse address mapping. struct sockaddr *sa; /* input */ socklent len; /* input */ char hbuf[NIMAXHOST]; if (getnameinfo(sa, len, hbuf, sizeof(hbuf), NULL, 0, NINAMEREQD)) printf("could not resolve hostname"); else

printf("host=%s\n", hbuf); An example program using getnameinfo() can be found in getaddrinfo(3). SEE ALSO accept(2), getpeername(2), getsockname(2), recvfrom(2), socket(2), getaddrinfo(3), gethostbyaddr(3), getservbyname(3), getservbyport(3), inetntop(3), hosts(5), services(5), hostname(7), named(8) R. Gilligan, S. Thomson, J. Bound and W. Stevens, Basic Socket Inter‐ face Extensions for IPv6, RFC 2553, March 1999. Tatsuya Jinmei and Atsushi Onoe, An Extension of Format for IPv6 Scoped Addresses, internet draft, work in progress ⟨ftp://ftp.ietf.org

/internet-drafts/draft-ietf-ipngwg-scopedaddr-format-02.txt⟩. Craig Metz, Protocol Independence Using the Sockets API, Proceedings of the freenix track: 2000 USENIX annual technical conference, June 2000 ⟨http://www.usenix.org/publications/library/proceedings/usenix2000 /freenix/metzprotocol.html⟩. COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

GNU 2013-01-15 GETNAMEINFO(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™