Copyright (C) 2000-2012 |
Manpages getnameinfoSection: UNIX Programmer's Manual (3)Updated: 2000-12-11 Index Return to Main Contents NAMEgetnameinfo - address-to-name translation in protocol-independent mannerSYNOPSIS#include <sys/socket.h> #include <netdb.h> int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags); DESCRIPTIONThe getnameinfo(3) function is defined for protocol-independent address-to-nodename translation. It combines the functionality of gethostbyaddr(3) and getservbyport(3) and is the inverse of getaddrinfo(3). The sa argument is a pointer to a generic socket address structure (of type sockaddr_in or sockaddr_in6) of size salen that holds the input IP address and port number. The arguments host and serv are pointers to buffers (of size hostlen and servlen repectively) to hold the return values.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) parameter. However, at least one of hostname or service name must be requested. The flags argument modifies the behaviour of getnameinfo(3) as follows:
RETURN VALUEOn success 0 is returned, and node and service names, if requested, are filled with NUL-terminated strings, possibly truncated to fit the specified buffer lengths. On error a nonzero value is returned, and errno is set appropriately.ERRORS
FILES/etc/hosts/etc/nsswitch.conf /etc/resolv.conf NOTEIn order to assist the programmer in choosing reasonable sizes for the supplied buffers, <netdb.h> defines the constants
EXAMPLESThe 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.
The following version checks if the socket address has a reverse address mapping.
CONFORMING TORFC 2553. (See also XNS, issue 5.2.)SEE ALSOgetaddrinfo(3), gethostbyaddr(3), getservbyname(3), getservbyport(3), inet_ntop(3), socket(3), hosts(5), services(5), hostname(7), named(8)R. Gilligan, S. Thomson, J. Bound and W. Stevens, Basic Socket Interface 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
IndexThis document was created by man2html, using the manual pages. Time: 15:00:19 GMT, April 19, 2024 |