netdb.h - definitions for network database operations
#include <netdb.h>fP
The <netdb.h> header may define the in_port_t type and the in_addr_t type as described in <netinet/in.h> . The <netdb.h> header shall define the hostent structure that includes at least the following members:The <netdb.h> header shall define the netent structure that includes at least the following members:char *h_name fP Official name of the host. fB
char **h_aliases fP A pointer to an array of pointers to fB fP alternative host names, terminated by a fB fP null pointer. fB int h_addrtype fP Address type. fB int h_length fP The length, in bytes, of the address. fB char **h_addr_list fP A pointer to an array of pointers to network fB fP addresses (in network byte order) for the host, fB fP terminated by a null pointer. fB fPThe uint32_t type shall be defined as described in <inttypes.h> . The <netdb.h> header shall define the protoent structure that includes at least the following members:char *n_name fP Official, fully-qualified (including the fB
fP domain) name of the host. fB char **n_aliases fP A pointer to an array of pointers to fB fP alternative network names, terminated by a fB fP null pointer. fB int n_addrtype fP The address type of the network. fB uint32_t n_net fP The network number, in host byte order. fB fPThe <netdb.h> header shall define the servent structure that includes at least the following members:char *p_name fP Official name of the protocol. fB
char **p_aliases fP A pointer to an array of pointers to fB fP alternative protocol names, terminated by fB fP a null pointer. fB int p_proto fP The protocol number. fB fPThe <netdb.h> header shall define the IPPORT_RESERVED macro with the value of the highest reserved Internet port number. When the <netdb.h> header is included, h_errno shall be available as a modifiable lvalue of type int. It is unspecified whether h_errno is a macro or an identifier declared with external linkage. The <netdb.h> header shall define the following macros for use as error values for gethostbyaddr() and gethostbyname():char *s_name fP Official name of the service. fB
char **s_aliases fP A pointer to an array of pointers to fB fP alternative service names, terminated by fB fP a null pointer. fB int s_port fP The port number at which the service fB fP resides, in network byte order. fB char *s_proto fP The name of the protocol to use when fB fP contacting the service. fB fPHOST_NOT_FOUND NO_DATA NO_RECOVERY TRY_AGAIN
Address Information Structure
The <netdb.h> header shall define the addrinfo structure that includes at least the following members:The <netdb.h> header shall define the following macros that evaluate to bitwise-distinct integer constants for use in the flags field of the addrinfo structure:int ai_flags fP Input flags. fB
int ai_family fP Address family of socket. fB int ai_socktype fP Socket type. fB int ai_protocol fP Protocol of socket. fB socklen_t ai_addrlen fP Length of socket address. fB struct sockaddr *ai_addr fP Socket address of socket. fB char *ai_canonname fP Canonical name of service location. fB struct addrinfo *ai_next fP Pointer to next in list. fB fPAI_PASSIVE
Socket address is intended for bind().AI_CANONNAME.sp Request for canonical name.AI_NUMERICHOST
.sp Return numeric host address as name.AI_NUMERICSERV.sp 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_ALLQuery for both IPv4 and IPv6 addresses.AI_ADDRCONFIG
.sp 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 shall define the following macros that evaluate to bitwise-distinct integer constants for use in the flags argument to getnameinfo():NI_NOFQDNOnly the nodename portion of the FQDN is returned for local hosts.NI_NUMERICHOST
.sp The numeric form of the node's address is returned instead of its name.NI_NAMEREQDReturn an error if the node's name cannot be located in the database.NI_NUMERICSERV
.sp The numeric form of the service address is returned instead of its name.NI_NUMERICSCOPE.sp 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).EAI_AGAINAddress Information Errors
The <netdb.h> header shall define the following macros for use as error values for getaddrinfo() and getnameinfo():The name could not be resolved at this time. Future attempts may succeed.EAI_BADFLAGS
The flags had an invalid value.EAI_FAILA non-recoverable error occurred.EAI_FAMILY
The address family was not recognized or the address length was invalid for the specified family.EAI_MEMORYThere 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_SERVICEThe service passed was not recognized for the specified socket type.EAI_SOCKTYPE
The intended socket type was not recognized.EAI_SYSTEMA system error occurred. The error code can be found in errno. EAI_OVERFLOW An argument buffer overflowed. The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.The type socklen_t shall be defined through typedef as described in <sys/socket.h>. Inclusion of the <netdb.h> header may also make visible all symbols from <netinet/in.h>, <sys/socket.h>, and <inttypes.h>. The following sections are informative.void endhostent(void);
void endnetent(void); void endprotoent(void); void endservent(void); void freeaddrinfo(struct addrinfo *); const char *gai_strerror(int); int getaddrinfo(const char *restrict, const char *restrict, const struct addrinfo *restrict, struct addrinfo **restrict); struct hostent *gethostbyaddr(const void *, socklen_t, int); struct hostent *gethostbyname(const char *); struct hostent *gethostent(void); int getnameinfo(const struct sockaddr *restrict, socklen_t, char *restrict, socklen_t, char *restrict, socklen_t, int); struct netent *getnetbyaddr(uint32_t, int); struct netent *getnetbyname(const char *); struct netent *getnetent(void); struct protoent *getprotobyname(const char *); struct protoent *getprotobynumber(int); struct protoent *getprotoent(void); struct servent *getservbyname(const char *, const char *); struct servent *getservbyport(int, const char *); struct servent *getservent(void); void sethostent(int); void setnetent(int); void setprotoent(int); void setservent(int); fP
None.
None.
None.
<netinet/in.h>, <inttypes.h>, <sys/socket.h>, the System Interfaces volume of IEEE Std 1003.1-2001, bind(), endhostent(), endnetent(), endprotoent(), endservent(), getaddrinfo(), getnameinfo()
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .