#include <netdb.h>

netdb.h

49 macros · 39 functions · 6 structs · 1 variable

macro_PATH_HEQUIV

#define _PATH_HEQUIV "/etc/hosts.equiv"

macro_PATH_HOSTS

#define _PATH_HOSTS "/etc/hosts"

macro_PATH_NETWORKS

#define _PATH_NETWORKS "/etc/networks"

macro_PATH_PROTOCOLS

#define _PATH_PROTOCOLS "/etc/protocols"

macro_PATH_SERVICES

#define _PATH_SERVICES "/etc/services"

variableh_errno

extern int h_errno

structhostent

Structures returned by network data base library. All addresses are supplied in host order, and returned in network order (suitable for use in system calls).
size 32, align 8
char *h_nameofficial name of host
char **h_aliasesalias list
inth_addrtypehost address type
inth_lengthlength of address
char **h_addr_listlist of addresses from name server

macroh_addr

#define h_addr h_addr_list[0]
address, for backward compatibility

structnetent

Assumption here is that a network number fits in an unsigned long -- probably a poor one.
size 24, align 8
char *n_nameofficial name of net
char **n_aliasesalias list
intn_addrtypenet address type
uint32_tn_netnetwork #

structservent

size 32, align 8
char *s_nameofficial service name
char **s_aliasesalias list
ints_portport #
char *s_protoprotocol to use

structprotoent

size 24, align 8
char *p_nameofficial protocol name
char **p_aliasesalias list
intp_protoprotocol #

structaddrinfo

size 48, align 8
intai_flagsAI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST
intai_familyPF_xxx
intai_socktypeSOCK_xxx
intai_protocol0 or IPPROTO_xxx for IPv4 and IPv6
socklen_tai_addrlenlength of ai_addr
char *ai_canonnamecanonical name for hostname
struct sockaddr *ai_addrbinary address
struct addrinfo *ai_nextnext structure in linked list

structrpcent

size 24, align 8
char *r_namename of server for this rpc program
char **r_aliasesalias list
intr_numberrpc program number

macroNETDB_INTERNAL

Error return codes from gethostbyname() and gethostbyaddr() (left in h_errno).
#define NETDB_INTERNAL -1
see errno

macroNETDB_SUCCESS

#define NETDB_SUCCESS 0
no problem

macroHOST_NOT_FOUND

#define HOST_NOT_FOUND 1
Authoritative Answer Host not found

macroTRY_AGAIN

#define TRY_AGAIN 2
Non-Authoritative Host not found, or SERVERFAIL

macroNO_RECOVERY

#define NO_RECOVERY 3
Non recoverable errors, FORMERR, REFUSED, NOTIMP

macroNO_DATA

#define NO_DATA 4
Valid name, no data record of requested type

macroNO_ADDRESS

#define NO_ADDRESS NO_DATA
no address, look for MX record

macroEAI_ADDRFAMILY

Error return codes from getaddrinfo()
#define EAI_ADDRFAMILY 1
address family for hostname not supported

macroEAI_AGAIN

#define EAI_AGAIN 2
temporary failure in name resolution

macroEAI_BADFLAGS

#define EAI_BADFLAGS 3
invalid value for ai_flags

macroEAI_FAIL

#define EAI_FAIL 4
non-recoverable failure in name resolution

macroEAI_FAMILY

#define EAI_FAMILY 5
ai_family not supported

macroEAI_MEMORY

#define EAI_MEMORY 6
memory allocation failure

macroEAI_NODATA

#define EAI_NODATA 7
no address associated with hostname

macroEAI_NONAME

#define EAI_NONAME 8
hostname nor servname provided, or not known

macroEAI_SERVICE

#define EAI_SERVICE 9
servname not supported for ai_socktype

macroEAI_SOCKTYPE

#define EAI_SOCKTYPE 10
ai_socktype not supported

macroEAI_SYSTEM

#define EAI_SYSTEM 11
system error returned in errno

macroEAI_BADHINTS

#define EAI_BADHINTS 12
invalid value for hints

macroEAI_PROTOCOL

#define EAI_PROTOCOL 13
resolved protocol is unknown

macroEAI_OVERFLOW

#define EAI_OVERFLOW 14
argument buffer overflow

macroEAI_MAX

#define EAI_MAX 15

macroAI_PASSIVE

Flag values for getaddrinfo()
#define AI_PASSIVE 0x00000001
get address to use bind()

macroAI_CANONNAME

#define AI_CANONNAME 0x00000002
fill ai_canonname

macroAI_NUMERICHOST

#define AI_NUMERICHOST 0x00000004
prevent host name resolution

macroAI_NUMERICSERV

#define AI_NUMERICSERV 0x00001000
prevent service name resolution

macroAI_MASK

valid flags for addrinfo (not a standard def, apps should not use it)
#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV |
    AI_ADDRCONFIG)

macroAI_ALL

#define AI_ALL 0x00000100
IPv6 and IPv4-mapped (with AI_V4MAPPED)

macroAI_V4MAPPED_CFG

#define AI_V4MAPPED_CFG 0x00000200
accept IPv4-mapped if kernel supports

macroAI_ADDRCONFIG

#define AI_ADDRCONFIG 0x00000400
only if any address is assigned

macroAI_V4MAPPED

#define AI_V4MAPPED 0x00000800
accept IPv4-mapped IPv6 address

macroAI_DEFAULT

special recommended flags for getipnodebyname
#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)

macroAI_UNUSABLE

If the hints pointer is null or ai_flags is zero, getaddrinfo() automatically defaults to the AI_DEFAULT behavior. To override this default behavior, thereby causing unusable addresses to be included in the results, pass any nonzero value for ai_flags, by setting any desired flag values, or by setting AI_UNUSABLE if no other flags are desired.
#define AI_UNUSABLE 0x10000000
return addresses even if unusable (i.e. opposite of AI_DEFAULT)

macroNI_MAXHOST

Constants for getnameinfo()
#define NI_MAXHOST 1025

macroNI_MAXSERV

#define NI_MAXSERV 32

macroNI_NOFQDN

Flag values for getnameinfo()
#define NI_NOFQDN 0x00000001

macroNI_NUMERICHOST

#define NI_NUMERICHOST 0x00000002

macroNI_NAMEREQD

#define NI_NAMEREQD 0x00000004

macroNI_NUMERICSERV

#define NI_NUMERICSERV 0x00000008

macroNI_NUMERICSCOPE

#define NI_NUMERICSCOPE 0x00000100

macroNI_DGRAM

#define NI_DGRAM 0x00000010

macroNI_WITHSCOPEID

#define NI_WITHSCOPEID 0x00000020

macroSCOPE_DELIMITER

Scope delimit character
#define SCOPE_DELIMITER '%'

functionendhostent

void endhostent(void)
man page · May 12, 2006
endhostent(3) — get network host entry

functionendnetent

void endnetent(void)
man page · June 4, 1993
endnetent(3) — get network entry

functionendprotoent

void endprotoent(void)
man page · June 4, 1993
endprotoent(3) — get protocol entry

functionendservent

void endservent(void)
man page · July 9, 1995
endservent(3) — get service entry

functionfreeaddrinfo

void freeaddrinfo(struct addrinfo *)
man page · July 1, 2008
freeaddrinfo(3) — socket address structure to host and service name

functiongai_strerror

const char *gai_strerror(int)
man page · May 21, 2006
gai_strerror(3) — get error message string from EAI_xxx error code

functiongetaddrinfo

int getaddrinfo(
	const char * __restrict,
	const char * __restrict,
	const struct addrinfo * __restrict,
	struct addrinfo ** __restrict
)
man page · July 1, 2008
getaddrinfo(3) — socket address structure to host and service name

functiongethostbyaddr

struct hostent *gethostbyaddr(const void *, socklen_t, int)
man page · May 12, 2006
gethostbyaddr(3) — get network host entry

functiongethostbyname

struct hostent *gethostbyname(const char *)
man page · May 12, 2006
gethostbyname(3) — get network host entry

functiongethostent

struct hostent *gethostent(void)
man page · May 12, 2006
gethostent(3) — get network host entry

functiongetnameinfo

int getnameinfo(
	const struct sockaddr * __restrict,
	socklen_t,
	char * __restrict,
	socklen_t,
	char * __restrict,
	socklen_t,
	int
)
man page · February 28, 2007
getnameinfo(3) — socket address structure to hostname and service name

functiongetnetbyaddr

struct netent *getnetbyaddr(uint32_t, int)
man page · June 4, 1993
getnetbyaddr(3) — get network entry

functiongetnetbyname

struct netent *getnetbyname(const char *)
man page · June 4, 1993
getnetbyname(3) — get network entry

functiongetnetent

struct netent *getnetent(void)
man page · June 4, 1993
getnetent(3) — get network entry

functiongetprotobyname

struct protoent *getprotobyname(const char *)
man page · June 4, 1993
getprotobyname(3) — get protocol entry

functiongetprotobynumber

struct protoent *getprotobynumber(int)
man page · June 4, 1993
getprotobynumber(3) — get protocol entry

functiongetprotoent

struct protoent *getprotoent(void)
man page · June 4, 1993
getprotoent(3) — get protocol entry

functiongetservbyname

struct servent *getservbyname(const char *, const char *)
man page · July 9, 1995
getservbyname(3) — get service entry

functiongetservbyport

struct servent *getservbyport(int, const char *)
man page · July 9, 1995
getservbyport(3) — get service entry

functiongetservent

struct servent *getservent(void)
man page · July 9, 1995
getservent(3) — get service entry

functionsethostent

void sethostent(int)
man page · May 12, 2006
sethostent(3) — get network host entry

functionsetnetent

void setnetent(int)
void sethostfile(const char *);
man page · June 4, 1993
setnetent(3) — get network entry

functionsetprotoent

void setprotoent(int)
man page · June 4, 1993
setprotoent(3) — get protocol entry

functionsetservent

void setservent(int)
man page · July 9, 1995
setservent(3) — get service entry

functionfreehostent

void freehostent(struct hostent *)
man page · August 6, 2004
freehostent(3) — nodename-to-address and address-to-nodename translation

functiongethostbyname2

struct hostent *gethostbyname2(const char *, int)
man page · May 12, 2006
gethostbyname2(3) — get network host entry

functiongetipnodebyaddr

struct hostent *getipnodebyaddr(const void *, size_t, int, int *)
man page · August 6, 2004
getipnodebyaddr(3) — nodename-to-address and address-to-nodename translation

functiongetipnodebyname

struct hostent *getipnodebyname(const char *, int, int, int *)
man page · August 6, 2004
getipnodebyname(3) — nodename-to-address and address-to-nodename translation

functiongetrpcbyname

struct rpcent *getrpcbyname(const char *name)
man page · December 14, 1987
getrpcbyname(3) — get RPC entry

functiongetrpcbynumber

struct rpcent *getrpcbynumber(int number)
man page · December 14, 1987
getrpcbynumber(3) — get RPC entry

functiongetrpcent

struct rpcent *getrpcent(void)
man page · December 14, 1987
getrpcent(3) — get RPC entry

functionsetrpcent

void setrpcent(int stayopen)
man page · December 14, 1987
setrpcent(3) — get RPC entry

functionendrpcent

void endrpcent(void)
man page · December 14, 1987
endrpcent(3) — get RPC entry

functionherror

void herror(const char *)
man page · May 12, 2006
herror(3) — get network host entry

functionhstrerror

const char *hstrerror(int)
man page · May 12, 2006
hstrerror(3) — get network host entry

functioninnetgr

int innetgr(const char *, const char *, const char *, const char *)
man page · June 4, 1993
innetgr(3) — netgroup database operations

functiongetnetgrent

int getnetgrent(char **, char **, char **)
man page · June 4, 1993
getnetgrent(3) — netgroup database operations

functionendnetgrent

void endnetgrent(void)
man page · June 4, 1993
endnetgrent(3) — netgroup database operations

functionsetnetgrent

void setnetgrent(const char *)
man page · June 4, 1993
setnetgrent(3) — netgroup database operations