---
name: "getnameinfo"
section: "3bind"
platform: "linux"
package: "bind-dev"
version: "1:8.4.7-1"
release: "Debian 4.0 (Etch)"
platforms: ["linux"]
url: "https://new.carta.tech/getnameinfo/3bind"
---

# getnameinfo(3bind)

address-to-name translation in protocol-independent manner

## NAME

**getnameinfo** – address-to-name translation in protocol-independent manner

## SYNOPSIS

**#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*);

## DESCRIPTION

The **getnameinfo**() function is defined for protocol-independent address-to-nodename translation. It performs functionality of  [gethostbyaddr(3)](/gethostbyaddr/3.md) and [getservbyport(3)](/getservbyport/3.md) in more sophisticated manner.

The *sa* arguement is a pointer to a generic socket address structure of size *salen*. The arguements *host* and *serv* are pointers to buffers to hold the return values. Their sizes are specified by *hostlen* and *servlen* repectively. Either *host* or *serv* may be NULL if the hostname  or service name is not required.

The  *flags* arguement modifies the behaviour of  **getnameinfo**() as follows:

If  NI\_NOFQDN is set only the unqualified hostname is returned for local fully qualified names.

If NI\_NUMERICHOST is set then the numeric form of the hostname is returned.

If NI\_NAMEREQD is set, then a error is returned if the hostname cannot be looked up.

If NI\_NUMERICSERV is set then the service is returned in numeric form.

If NI\_DGRAM is set then the service is UDP based rather than TCP based.

## SEE ALSO

[getaddrinfo(3)](/getaddrinfo/3.md), [gethostbyaddr(3)](/gethostbyaddr/3.md), [getservbyport(3)](/getservbyport/3.md), [hosts(5)](/hosts/5.md), [services(5)](/services/5.md), [hostname(7)](/hostname/7.md), [named(8)](/named/8.md)

R. Gilligan, S.  Thomson, J. Bound, and W. Stevens, \`\`Basic Socket Interface Extensions for IPv6,'' RFC2133, April 1997.

## STANDARDS

The **getaddrinfo**() function is defined IEEE POSIX 1003.1g draft specification, and documented in \`\`Basic Socket Interface Extensions for IPv6'' (RFC2133).
