netdb.h(0P)
π netdb.h β definitions for network database operations π
okay bestie, gather round, because we're about to read netdb.h(0P) from the POSIX Programmer's Manual and honestly? it's giving foundational. π«Ά
πΈ PROLOG πΈ
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
no cap, that's the whole disclaimer. it's not being dramatic, it's just being honest π
β¨ NAME β¨
netdb.h β definitions for network database operations
like. that's the vibe. network database operations. periodt.
π SYNOPSIS π
#include <netdb.h>
one include. that's it. iconic behaviour honestly.
π¦ DESCRIPTION π¦
so the <netdb.h> header may define the in_port_t type and the in_addr_t type, as described in <netinet/in.h>. may! it's a maybe girl. π
The <netdb.h> header shall define the hostent structure, and it shall include at least these 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 these 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 these 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 these 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. π₯
π Address Information Structure π
The <netdb.h> header shall define the addrinfo structure, which shall include at least these 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 these symbolic constants, which evaluate to bitwise-distinct integer constants, for use in the flags field of the addrinfo structure:
AI_PASSIVEβ Socket address is intended forbind().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 shall define these symbolic constants, which evaluate to bitwise-distinct integer constants, for use in the flags argument to getnameinfo():
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 shall define these symbolic constants for use as error values for getaddrinfo() and getnameinfo(). The values shall be suitable for use in #if preprocessing directives. (yes bestie, #if. they're macro-friendly. π
)
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_NAMEREQDis 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 inerrno.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. π
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);
look at all those restricts. they're doing the absolute most and we love them for it. π
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>. (so sneaky. so generous. both. π§)
The following sections are informative.
π APPLICATION USAGE π
None.
literally none. the page said "no thoughts, head empty" and honestly? respect. π
β RATIONALE β
None.
πΈ FUTURE DIRECTIONS πΈ
None.
π SEE ALSO π
<inttypes.h>,<netinet_in.h>,<sys_socket.h>
The System Interfaces volume of POSIX.1β2017:
bind(),endhostent(),endnetent(),endprotoent(),endservent(),freeaddrinfo(),gai_strerror(),getnameinfo()
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 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 .
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 .
π«Ά and that's the whole page, bestie. go forth and getaddrinfo() responsibly. slay. πβ¨
β brought to you by IEEE/The Open Group, 2017, signing off from the netdb.h(0P) page like the main character it is ππΈ
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms