# getnameinfo

## PROLOG



           This manual page is part of the POSIX Programmer's Manual.  The
           Linux implementation of this interface may differ (consult the
           corresponding Linux manual page for details of Linux behavior), or
           the interface may not be implemented on Linux.
    


## NAME



           getnameinfo — get name information
    


## SYNOPSIS



           #include <sys/socket.h>
           #include <netdb.h>
    
           int getnameinfo(const struct sockaddr *restrict _sa_ , socklen_t _salen_ ,
               char *restrict _node_ , socklen_t _nodelen_ , char *restrict _service_ ,
               socklen_t _servicelen_ , int _flags_);
    


## DESCRIPTION



           The _getnameinfo_() function shall translate a socket address to a
           node name and service location, all of which are defined as in
           freeaddrinfo(3p).
    
           The _sa_ argument points to a socket address structure to be
           translated. The _salen_ argument contains the length of the address
           pointed to by _sa_.
    
           If the socket address structure contains an IPv4-mapped IPv6
           address or an IPv4-compatible IPv6 address, the implementation
           shall extract the embedded IPv4 address and lookup the node name
           for that IPv4 address.
    
           If the address is the IPv6 unspecified address (**"::"**), a lookup
           shall not be performed and the behavior shall be the same as when
           the node's name cannot be located.
    
           If the _node_ argument is non-NULL and the _nodelen_ argument is non-
           zero, then the _node_ argument points to a buffer able to contain up
           to _nodelen_ bytes that receives the node name as a null-terminated
           string. If the _node_ argument is NULL or the _nodelen_ argument is
           zero, the node name shall not be returned. If the node's name
           cannot be located, the numeric form of the address contained in
           the socket address structure pointed to by the _sa_ argument is
           returned instead of its name.
    
           If the _service_ argument is non-NULL and the _servicelen_ argument is
           non-zero, then the _service_ argument points to a buffer able to
           contain up to _servicelen_ bytes that receives the service name as a
           null-terminated string.  If the _service_ argument is NULL or the
           _servicelen_ argument is zero, the service name shall not be
           returned. If the service's name cannot be located, the numeric
           form of the service address (for example, its port number) shall
           be returned instead of its name.
    
           The _flags_ argument is a flag that changes the default actions of
           the function. By default the fully-qualified domain name (FQDN)
           for the host shall be returned, but:
    
            *  If the flag bit NI_NOFQDN is set, only the node name portion
               of the FQDN shall be returned for local hosts.
    
            *  If the flag bit NI_NUMERICHOST is set, the numeric form of the
               address contained in the socket address structure pointed to
               by the _sa_ argument shall be returned instead of its name.
    
            *  If the flag bit NI_NAMEREQD is set, an error shall be returned
               if the host's name cannot be located.
    
            *  If the flag bit NI_NUMERICSERV is set, the numeric form of the
               service address shall be returned (for example, its port
               number) instead of its name.
    
            *  If the flag bit NI_NUMERICSCOPE is set, the numeric form of
               the scope identifier shall be returned (for example, interface
               index) instead of its name. This flag shall be ignored if the
               _sa_ argument is not an IPv6 address.
    
            *  If the flag bit NI_DGRAM is set, this indicates that the
               service is a datagram service (SOCK_DGRAM). The default
               behavior shall assume that the service is a stream service
               (SOCK_STREAM).
    
           **Notes:**
    
                      1. The two NI_NUMERICxxx flags are required to support
                         the **-n** flag that many commands provide.
    
                      2. The NI_DGRAM flag is required for the few AF_INET
                         and AF_INET6 port numbers (for example, [512,514])
                         that represent different services for UDP and TCP.
    
           The _getnameinfo_() function shall be thread-safe.
    


## RETURN VALUE



           A zero return value for _getnameinfo_() indicates successful
           completion; a non-zero return value indicates failure. The
           possible values for the failures are listed in the ERRORS section.
    
           Upon successful completion, _getnameinfo_() shall return the _node_
           and _service_ names, if requested, in the buffers provided. The
           returned names are always null-terminated strings.
    


## ERRORS



           The _getnameinfo_() function shall fail and return the corresponding
           value if:
    
           [EAI_AGAIN] The name could not be resolved at this time. Future
                       attempts may succeed.
    
           [EAI_BADFLAGS]
                       The _flags_ had an invalid value.
    
           [EAI_FAIL]  A non-recoverable error occurred.
    
           [EAI_FAMILY]
                       The address family was not recognized or the address
                       length was invalid for the specified family.
    
           [EAI_MEMORY]
                       There was a memory allocation failure.
    
           [EAI_NONAME]
                       The name does not resolve for the supplied parameters.
    
                       NI_NAMEREQD is set and the host's name cannot be
                       located, or both _nodename_ and _servname_ were null.
    
           [EAI_OVERFLOW]
                       An argument buffer overflowed. The buffer pointed to
                       by the _node_ argument or the _service_ argument was too
                       small.
    
           [EAI_SYSTEM]
                       A system error occurred. The error code can be found
                       in _errno_.
    
           _The following sections are informative._
    


## EXAMPLES



           None.
    


## APPLICATION USAGE



           If the returned values are to be used as part of any further name
           resolution (for example, passed to _getaddrinfo_()), applications
           should provide buffers large enough to store any result possible
           on the system.
    
           Given the IPv4-mapped IPv6 address **"::ffff:1.2.3.4"** , the
           implementation performs a lookup as if the socket address
           structure contains the IPv4 address **"1.2.3.4"**.
    
           The IPv6 unspecified address (**"::"**) and the IPv6 loopback address
           (**"::1"**) are not IPv4-compatible addresses.
    


## RATIONALE



           None.
    


## FUTURE DIRECTIONS



           None.
    


* * *