#include <netdb.h>
The <netdb.h> header shall define the hostent structure, which shall include at least the following members:
char *h_name Official name of the host. char **h_aliases A pointer to an array of pointers to alternative host names, terminated by a null pointer. int h_addrtype Address type. int h_length The length, in bytes, of the address. char **h_addr_list A 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 shall define the netent structure, which shall include at least the following members:
char *n_name Official, fully-qualified (including the domain) name of the host. char **n_aliases A pointer to an array of pointers to alternative network names, terminated by a null pointer. int n_addrtype The address type of the network. uint32_t n_net The network number, in host byte order.
The <netdb.h> header shall define the uint32_t type as described in <inttypes.h>.
The <netdb.h> header shall define the protoent structure, which shall include at least the following members:
char *p_name Official name of the protocol. char **p_aliases A pointer to an array of pointers to alternative protocol names, terminated by a null pointer. int p_proto The protocol number.
The <netdb.h> header shall define the servent structure, which shall include at least the following members:
char *s_name Official name of the service. char **s_aliases A pointer to an array of pointers to alternative service names, terminated by a null pointer. int s_port A value which, when converted to uint16_t, yields the port number in network byte order at which the service resides. char *s_proto The name of the protocol to use when contacting the service.
The <netdb.h> header shall define the IPPORT_RESERVED symbolic constant with the value of the highest reserved Internet port number.
The <netdb.h> header shall define the addrinfo structure, which shall include at least 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.
The <netdb.h> header shall define the following symbolic constants that evaluate to bitwise-distinct integer constants for use in the flags field of the addrinfo structure:
The <netdb.h> header shall define the following symbolic constants that evaluate to bitwise-distinct integer constants for use in the flags argument to getnameinfo():
The <netdb.h> header shall define the following symbolic constants for use as error values for getaddrinfo() and getnameinfo(). The values shall be suitable for use in #if preprocessing directives.
NI_NAMEREQD is set and the host's name cannot be located, or both nodename and servname were null.
The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.
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 *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);
The <netdb.h> header shall define the socklen_t type 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.
The System Interfaces volume of POSIX.1-2017, bind(), endhostent(), endnetent(), endprotoent(), endservent(), freeaddrinfo(), gai_strerror(), getnameinfo()
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .