The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
Loading...
Searching...
No Matches
netdb.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
netinet/in.h
>
4
#include <
sys/socket.h
>
5
6
/**
7
* @file netdb.h
8
* @brief names of hosts and services: getaddrinfo and the older calls.
9
*
10
* a host name is looked up in /etc/hosts first, then with DNS (the name
11
* servers in /etc/resolv.conf, which dhcp writes). only IPv4 addresses (A
12
* records). the service names are a built-in table of the common ones.
13
* the values are Linux's.
14
*/
15
16
struct
addrinfo
17
{
18
int
ai_flags
;
19
int
ai_family
;
20
int
ai_socktype
;
21
int
ai_protocol
;
22
socklen_t
ai_addrlen
;
23
struct
sockaddr
*
ai_addr
;
24
char
*
ai_canonname
;
25
struct
addrinfo
*
ai_next
;
26
};
27
28
// ai_flags
29
#define AI_PASSIVE 0x0001
// no node: the address to bind to (any)
30
#define AI_CANONNAME 0x0002
// the first result gets the canonical name
31
#define AI_NUMERICHOST 0x0004
// node must be an address; no lookup
32
#define AI_V4MAPPED 0x0008
33
#define AI_ALL 0x0010
34
#define AI_ADDRCONFIG 0x0020
35
#define AI_NUMERICSERV 0x0400
// service must be a number
36
37
// the errors of getaddrinfo and getnameinfo
38
#define EAI_BADFLAGS -1
39
#define EAI_NONAME -2
// no such name
40
#define EAI_AGAIN -3
// no answer now; it may work later
41
#define EAI_FAIL -4
42
#define EAI_FAMILY -6
43
#define EAI_SOCKTYPE -7
44
#define EAI_SERVICE -8
45
#define EAI_MEMORY -10
46
#define EAI_SYSTEM -11
// see errno
47
#define EAI_OVERFLOW -12
48
49
// getnameinfo
50
#define NI_MAXHOST 1025
51
#define NI_MAXSERV 32
52
#define NI_NUMERICHOST 0x01
53
#define NI_NUMERICSERV 0x02
54
#define NI_NOFQDN 0x04
55
#define NI_NAMEREQD 0x08
56
#define NI_DGRAM 0x10
57
58
/**
59
* the addresses for a host and a service.
60
* @param node a host name or address; NULL for the local host, or with
61
* AI_PASSIVE the address that takes any.
62
* @param service a port number or name ("http"), or NULL for port 0.
63
* @param hints the family (AF_UNSPEC or AF_INET), the socket type (0 for
64
* both SOCK_STREAM and SOCK_DGRAM) and the AI_ flags; may be NULL.
65
* @param res receives a list; free it with freeaddrinfo.
66
* @return 0, or an EAI_ error.
67
*/
68
int
getaddrinfo
(
const
char
*node,
const
char
*service,
const
struct
addrinfo
*hints,
69
struct
addrinfo
**res);
70
71
void
freeaddrinfo
(
struct
addrinfo
*res);
72
73
/**
74
* the text of an EAI_ error.
75
*/
76
const
char
*
gai_strerror
(
int
error
);
77
78
/**
79
* the host and service of an address: the name from /etc/hosts, else the
80
* address as text (there are no reverse DNS lookups); the service name
81
* from the table, else the number.
82
* @return 0, or an EAI_ error (EAI_NONAME with NI_NAMEREQD and no name).
83
*/
84
int
getnameinfo
(
const
struct
sockaddr
*addr,
socklen_t
addrlen,
char
*host,
socklen_t
hostlen,
85
char
*serv,
socklen_t
servlen,
int
flags
);
86
87
struct
hostent
88
{
89
char
*
h_name
;
90
char
**
h_aliases
;
91
int
h_addrtype
;
92
int
h_length
;
93
char
**
h_addr_list
;
94
};
95
#define h_addr h_addr_list[0]
96
97
struct
servent
98
{
99
char
*
s_name
;
100
char
**
s_aliases
;
101
int
s_port
;
// network byte order
102
char
*
s_proto
;
103
};
104
105
// h_errno
106
#define HOST_NOT_FOUND 1
107
#define TRY_AGAIN 2
108
#define NO_RECOVERY 3
109
#define NO_DATA 4
110
111
int
*
__h_errno_location
(
void
);
112
#define h_errno (*__h_errno_location())
113
114
/**
115
* the older lookup: the IPv4 addresses of a name, in a buffer of the
116
* calling thread. sets h_errno on an error.
117
* @return the entry, or NULL.
118
*/
119
struct
hostent
*
gethostbyname
(
const
char
*name);
120
121
/**
122
* a service by name or by port (network byte order); proto "tcp", "udp"
123
* or NULL. in a buffer of the calling thread.
124
*/
125
struct
servent
*
getservbyname
(
const
char
*name,
const
char
*proto);
126
struct
servent
*
getservbyport
(
int
port,
const
char
*proto);
127
128
const
char
*
hstrerror
(
int
error
);
flags
uint8_t flags
Definition
idt.c:3
in.h
IPv4 addresses and ports, and the IP protocols.
error
uint32_t error
Definition
isr.h:3
getservbyport
struct servent * getservbyport(int port, const char *proto)
hstrerror
const char * hstrerror(int error)
getaddrinfo
int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
the addresses for a host and a service.
freeaddrinfo
void freeaddrinfo(struct addrinfo *res)
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 ...
__h_errno_location
int * __h_errno_location(void)
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.
gai_strerror
const char * gai_strerror(int error)
the text of an EAI_ error.
gethostbyname
struct hostent * gethostbyname(const char *name)
the older lookup: the IPv4 addresses of a name, in a buffer of the calling thread.
socket.h
sockets: Unix domain stream sockets, with file descriptor passing, and IPv4 sockets (TCP; UDP,...
socklen_t
unsigned int socklen_t
Definition
socket.h:21
addrinfo
Definition
netdb.h:17
addrinfo::ai_addr
struct sockaddr * ai_addr
Definition
netdb.h:23
addrinfo::ai_canonname
char * ai_canonname
Definition
netdb.h:24
addrinfo::ai_socktype
int ai_socktype
Definition
netdb.h:20
addrinfo::ai_protocol
int ai_protocol
Definition
netdb.h:21
addrinfo::ai_addrlen
socklen_t ai_addrlen
Definition
netdb.h:22
addrinfo::ai_next
struct addrinfo * ai_next
Definition
netdb.h:25
addrinfo::ai_flags
int ai_flags
Definition
netdb.h:18
addrinfo::ai_family
int ai_family
Definition
netdb.h:19
hostent
Definition
netdb.h:88
hostent::h_addrtype
int h_addrtype
Definition
netdb.h:91
hostent::h_name
char * h_name
Definition
netdb.h:89
hostent::h_addr_list
char ** h_addr_list
Definition
netdb.h:93
hostent::h_length
int h_length
Definition
netdb.h:92
hostent::h_aliases
char ** h_aliases
Definition
netdb.h:90
servent
Definition
netdb.h:98
servent::s_name
char * s_name
Definition
netdb.h:99
servent::s_proto
char * s_proto
Definition
netdb.h:102
servent::s_aliases
char ** s_aliases
Definition
netdb.h:100
servent::s_port
int s_port
Definition
netdb.h:101
sockaddr
Definition
socket.h:25
src
libc
include
netdb.h
Generated by
1.18.0