Go to main content

man pages section 3: Library Interfaces and Headers

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

netdb(3HEAD)

Name

netdb.h, netdb - definitions for network database operations

Synopsis

#include <netdb.h> 

Description

The <netdb.h> header defines the type in_port_t and the type in_addr_t as described in in.h(3HEAD).

Address Information Structure

The <netdb.h> header defines the addrinfo structure, which includes the following members:

int              ai_flags     /* Input flags */
int              ai_family    /* Address family of socket */
int              ai_socktype  /* Socket type */
int              ai_protocol  /* Protocol of socket */
socklen_t        ai_addrlen   /* Length of socket address */
struct sockaddr *ai_addr      /* Socket address of socket */
char            *ai_canonname /* Canonical name of service location */
struct addrinfo *ai_next      /* Pointer to next in list */

See the getaddrinfo(3C) man page for details on the usage of these members in the addrinfo structure.

The <netdb.h> header defines the following symbolic constants that evaluate to bitwise-distinct integer constants for use in the flags field of the addrinfo structure:

AI_PASSIVE

Socket address is intended for bind(3C).

AI_CANONNAME

Request for canonical name.

AI_NUMERICHOST

Return numeric host address as name.

AI_NUMERICSERV

Inhibit service name resolution.

AI_V4MAPPED

If no IPv6 addresses are found, query for IPv4 addresses and return them to the caller as IPv4-mapped IPv6 addresses.

AI_ALL

Query for both IPv4 and IPv6 addresses.

AI_ADDRCONFIG

Query for IPv4 addresses only when an IPv4 address is configured; query for IPv6 addresses only when an IPv6 address is configured.

The <netdb.h> header defines the following symbolic constants that evaluate to bitwise-distinct integer constants for use in the flags argument to getnameinfo(3C):

NI_NOFQDN

Only the nodename portion of the FQDN is returned for local hosts.

NI_NUMERICHOST

The numeric form of the node's address is returned instead of its name.

NI_NAMEREQD

Return an error if the node's name cannot be located in the database.

NI_NUMERICSERV

The numeric form of the service address is returned instead of its name.

NI_NUMERICSCOPE

For IPv6 addresses, the numeric form of the scope identifier is returned instead of its name.

NI_DGRAM

Indicates that the service is a datagram service (SOCK_DGRAM).

Address Information Errors

The <netdb.h> header defines the following macros for use as error values for getaddrinfo(3C) and getnameinfo(3C). The gai_strerror(3C) function translates these values to error message strings for user presentation.

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_SERVICE

The service passed was not recognized for the specified socket type.

EAI_SOCKTYPE

The intended socket type was not recognized.

EAI_SYSTEM

A system error occurred. The error code can be found in errno.

EAI_OVERFLOW

An argument buffer overflowed.

Legacy Host Information Structure

The <netdb.h> header defines the hostent structure that includes the following members:

char *h_name          /* official name of the host */
char **h_aliases      /* pointer to an array of pointers to
                         alternative host names, terminated
                         by a null pointer */
int  h_addrtype       /* address type */
int  h_length         /* length, in bytes, of the address */
char **h_addr_list    /* pointer to an array of pointers to
                         network addresses (in network byte
                         order)for the host, terminated by a
                         null pointer */

The <netdb.h> header defines the netent structure that includes the following members:


char      *n_name     /* official, fully-qualified */
                         (including the domain) name
                         of the network */
char      **n_aliases /* pointer to an array of pointers to
                         alternative network names, terminated */
                         by a null pointer */
int       n_addrtype  /* the address type of the network */
in_addr_t n_net       /* the network number, in host byte order */

The <netdb.h> header defines the protoent structure that includes the following members:

char *p_name         /* official name of the protocol */
char **p_aliases     /* pointer to an array of pointers to
                        alternative protocol names, terminated
                        by a null pointer */
int  p_proto         /* protocol number */

The <netdb.h> header defines the servent structure that includes the following members:

char *s_name         /* official name of the service */
char **s_aliases     /* pointer to an array of pointers to
                        alternativeservice names, terminated by
                        a null pointer */
int  s_port          /* port number at which the service
                        resides, in network byte order */
char *s_proto        /* name of the protocol to use when
                        contacting the service */

The <netdb.h> header defines the macro IPPORT_RESERVED with the value of the highest normally reserved Internet port number. This will not reflect system configuration changes via the “smallest-nonpriv-port” property which may be set by ipadm(8).

The <netdb.h> header provides a declaration for h_errno:

extern int h_errno;

The <netdb.h> header defines the following macros for use as error values for gethostbyaddr() and gethostbyname():

  • HOST_NOT_FOUND
  • NO_DATA
  • NO_RECOVERY
  • TRY_AGAIN

Inclusion of the <netdb.h> header may also make visible all symbols from in.h(3HEAD) and socket.h(3HEAD).

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
Standard

See Also

endhostent(3C), endnetent(3C), endprotoent(3C), endservent(3C), freeaddrinfo(3C), gai_strerror(3C), getaddrinfo(3C), gethostbyname(3C), gethostent(3C), getnameinfo(3C), getnetent(3C), getprotoent(3C), getservbyname(3C), getservent(3C), sethostent(3C), setnetent(3C), setprotoent(3C), setservent(3C), in.h(3HEAD), socket.h(3HEAD), intro(3), attributes(7), standards(7)

Gilligan, R. RFC 3493, Basic Socket Interface Extensions for IPv6. Network Working Group. February 2003. https://tools.ietf.org/html/rfc3493