NAME

  tst_getnameinfo - Translate a socket address to a node name and service location


PURPOSE

  To check that getnameinfo() can used to translate a socket address to
  a node name and service location.


SYNOPSIS

  ./tst_getnameinfo [-tooloption ...]
    -tooloption : v6api tool option


TEST PROCEDURE

  1. The flag bit NI_NUMERICHOST is set
  2. Check A: the numeric form of the host's address shall be returned
  3. The flag bit NI_NUMERICSERV is set, and the port numbers is set
  4. Check B: the numeric form of the service address shall be returned
  5. The port numbers is set and flag is set to 0
  6. Check C: service name should be returned
  7. The flag bit NI_DGRAM is set, and the port numbers is set
  8. Check D: service name should be returned
  9. The address is the IPv6 unspecified address
  10.Check E: the EAI_NONAME error should be returned
  11.Both the nodename and servname are null
  12.Check F: the EAI_NONAME error should be returned
  13.The address family was not recognized
  14.Check G: the EAI_FAMILY error should be returned
  15.The address length was invalid for the specified family
  16.Check H: the EAI_FAMILY error should be returned
  17.The flags had an invalid value
  18.Check I: the EAI_BADFLAGS error should be returned
  19.An argument buffer overflowed
  20.Check J: the EAI_OVERFLOW error should be returned


NOTE

  None


REFERENCE

  RFC 3493
  6.2 Socket Address Structure to Node Name and Service Name
    The getnameinfo() function is used to translate the contents of a
    socket address structure to a node name and/or service name.
    #include <sys/socket.h>
    #include <netdb.h>
    int getnameinfo(const struct sockaddr *sa, socklen_t salen,
                       char *node, socklen_t nodelen,
                       char *service, socklen_t servicelen,
                         int flags);
    The getnameinfo() function shall translate a socket address to a node
    name and service location, all of which are defined as in
    getaddrinfo().
    The sa argument points to a socket address structure to be
    translated.
    The salen argument holds the size of the socket address structure
    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.
      Note: The IPv6 unspecified address ("::") and the IPv6 loopback
      address ("::1") are not IPv4-compatible addresses.  If the address
      is the IPv6 unspecified address ("::"), a lookup is not performed,
      and the [EAI_NONAME] error is returned.
    If the node argument is non-NULL and the nodelen argument is nonzero,
    then the node argument points to a buffer able to contain up to
    nodelen characters 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 node's address 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 arguments node and service cannot both be NULL.
    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
       host's address shall be returned instead of its name, under all
       circumstances.
    -  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, under all circumstances.
    -  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).
    Note:
    1. The NI_NUMERICxxx flags are required to support the "-n" flags
       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.
    A zero return value for getnameinfo() indicates successful
    completion; a non-zero return value indicates failure.
    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.
    Error Return Values:
    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.
    [EAI_SYSTEM]   A system error occurred.  The error code can be found
                   in errno.