getnameinfo TCP UDP
Converts a socket address to a string describing the host and another string describing the service.
Files
net_bsd.h/net_bsd.c
Prototype
int getnameinfo (const struct sockaddr *p_sockaddr, int addrlen, char *p_host_name, int hostlen, char *p_service_name, int servicelen, int flags)
Arguments
p_sockaddr
Pointer to the sockaddr structure with the protocol address to be converted.
addrlen
Length of the sockaddr structure pointed to by p_sockaddr.
p_host_name
Pointer to the host name string allocated by the caller.
hostlen
Length of string pointed to by p_host_name.
p_service_name
Pointer to the service name string allocated by the caller.
servicelen
Length of string pointed to by p_service_name.
flags
Flags that change how this function converts the socket address.
- NI_NAMEREQD - an EAI_NONAME error will be returned if the host name cannot be resolved.
- NI_DGRAM - the resolved service name will be the name of the UDP service used by that port. Some ports are shared between TCP and UDP.
- NI_NOFQDN - the resolved host name will be truncated until the first '.' character.
- NI_NUMERICHOST - 'p_host_name' will be resolved to the string representation of the IP address in dotted form.
- NI_NUMERICSERV - 'p_service_name' will be resolved to the string representation of numeric value of the service port.
Returned Value
0, if no error.
Most non-zero error codes returned map to the set of errors outlined by Internet Engineering Task Force (IETF) recommendations:
- EAI_AGAIN
- EAI_BADFLAGS
- EAI_FAIL
- EAI_FAMILY
- EAI_MEMORY
- EAI_NONAME
- EAI_OVERFLOW
- EAI_SERVICE