The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
netdb.h File Reference

names of hosts and services: getaddrinfo and the older calls. More...

#include <netinet/in.h>
#include <sys/socket.h>

Go to the source code of this file.

Data Structures

struct  addrinfo
struct  hostent
struct  servent

Macros

#define AI_PASSIVE   0x0001
#define AI_CANONNAME   0x0002
#define AI_NUMERICHOST   0x0004
#define AI_V4MAPPED   0x0008
#define AI_ALL   0x0010
#define AI_ADDRCONFIG   0x0020
#define AI_NUMERICSERV   0x0400
#define EAI_BADFLAGS   -1
#define EAI_NONAME   -2
#define EAI_AGAIN   -3
#define EAI_FAIL   -4
#define EAI_FAMILY   -6
#define EAI_SOCKTYPE   -7
#define EAI_SERVICE   -8
#define EAI_MEMORY   -10
#define EAI_SYSTEM   -11
#define EAI_OVERFLOW   -12
#define NI_MAXHOST   1025
#define NI_MAXSERV   32
#define NI_NUMERICHOST   0x01
#define NI_NUMERICSERV   0x02
#define NI_NOFQDN   0x04
#define NI_NAMEREQD   0x08
#define NI_DGRAM   0x10
#define h_addr   h_addr_list[0]
#define HOST_NOT_FOUND   1
#define TRY_AGAIN   2
#define NO_RECOVERY   3
#define NO_DATA   4
#define h_errno   (*__h_errno_location())

Functions

int getaddrinfo (const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
 the addresses for a host and a service.
void freeaddrinfo (struct addrinfo *res)
const char * gai_strerror (int error)
 the text of an EAI_ error.
int getnameinfo (const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
 the host and service of an address: the name from /etc/hosts, else the address as text (there are no reverse DNS lookups); the service name from the table, else the number.
int * __h_errno_location (void)
struct hostent * gethostbyname (const char *name)
 the older lookup: the IPv4 addresses of a name, in a buffer of the calling thread.
struct servent * getservbyname (const char *name, const char *proto)
 a service by name or by port (network byte order); proto "tcp", "udp" or NULL.
struct servent * getservbyport (int port, const char *proto)
const char * hstrerror (int error)

Detailed Description

names of hosts and services: getaddrinfo and the older calls.

a host name is looked up in /etc/hosts first, then with DNS (the name servers in /etc/resolv.conf, which dhcp writes). only IPv4 addresses (A records). the service names are a built-in table of the common ones. the values are Linux's.

Macro Definition Documentation

◆ AI_PASSIVE

#define AI_PASSIVE   0x0001

◆ AI_CANONNAME

#define AI_CANONNAME   0x0002

◆ AI_NUMERICHOST

#define AI_NUMERICHOST   0x0004

◆ AI_V4MAPPED

#define AI_V4MAPPED   0x0008

◆ AI_ALL

#define AI_ALL   0x0010

◆ AI_ADDRCONFIG

#define AI_ADDRCONFIG   0x0020

◆ AI_NUMERICSERV

#define AI_NUMERICSERV   0x0400

◆ EAI_BADFLAGS

#define EAI_BADFLAGS   -1

◆ EAI_NONAME

#define EAI_NONAME   -2

◆ EAI_AGAIN

#define EAI_AGAIN   -3

◆ EAI_FAIL

#define EAI_FAIL   -4

◆ EAI_FAMILY

#define EAI_FAMILY   -6

◆ EAI_SOCKTYPE

#define EAI_SOCKTYPE   -7

◆ EAI_SERVICE

#define EAI_SERVICE   -8

◆ EAI_MEMORY

#define EAI_MEMORY   -10

◆ EAI_SYSTEM

#define EAI_SYSTEM   -11

◆ EAI_OVERFLOW

#define EAI_OVERFLOW   -12

◆ NI_MAXHOST

#define NI_MAXHOST   1025

◆ NI_MAXSERV

#define NI_MAXSERV   32

◆ NI_NUMERICHOST

#define NI_NUMERICHOST   0x01

◆ NI_NUMERICSERV

#define NI_NUMERICSERV   0x02

◆ NI_NOFQDN

#define NI_NOFQDN   0x04

◆ NI_NAMEREQD

#define NI_NAMEREQD   0x08

◆ NI_DGRAM

#define NI_DGRAM   0x10

◆ h_addr

#define h_addr   h_addr_list[0]

◆ HOST_NOT_FOUND

#define HOST_NOT_FOUND   1

◆ TRY_AGAIN

#define TRY_AGAIN   2

◆ NO_RECOVERY

#define NO_RECOVERY   3

◆ NO_DATA

#define NO_DATA   4

◆ h_errno

#define h_errno   (*__h_errno_location())

Function Documentation

◆ getaddrinfo()

int getaddrinfo ( const char * node,
const char * service,
const struct addrinfo * hints,
struct addrinfo ** res )

the addresses for a host and a service.

Parameters
nodea host name or address; NULL for the local host, or with AI_PASSIVE the address that takes any.
servicea port number or name ("http"), or NULL for port 0.
hintsthe family (AF_UNSPEC or AF_INET), the socket type (0 for both SOCK_STREAM and SOCK_DGRAM) and the AI_ flags; may be NULL.
resreceives a list; free it with freeaddrinfo.
Returns
0, or an EAI_ error.

◆ freeaddrinfo()

void freeaddrinfo ( struct addrinfo * res)

◆ gai_strerror()

const char * gai_strerror ( int error)

the text of an EAI_ error.

◆ getnameinfo()

int getnameinfo ( const struct sockaddr * addr,
socklen_t addrlen,
char * host,
socklen_t hostlen,
char * serv,
socklen_t servlen,
int flags )

the host and service of an address: the name from /etc/hosts, else the address as text (there are no reverse DNS lookups); the service name from the table, else the number.

Returns
0, or an EAI_ error (EAI_NONAME with NI_NAMEREQD and no name).

◆ __h_errno_location()

int * __h_errno_location ( void )

◆ gethostbyname()

struct hostent * gethostbyname ( const char * name)

the older lookup: the IPv4 addresses of a name, in a buffer of the calling thread.

sets h_errno on an error.

Returns
the entry, or NULL.

◆ getservbyname()

struct servent * getservbyname ( const char * name,
const char * proto )

a service by name or by port (network byte order); proto "tcp", "udp" or NULL.

in a buffer of the calling thread.

◆ getservbyport()

struct servent * getservbyport ( int port,
const char * proto )

◆ hstrerror()

const char * hstrerror ( int error)