The manual
ginnOS
The reference: libc, the libraries and the kernel
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
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 */
68int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints,
69 struct addrinfo **res);
70
71void freeaddrinfo(struct addrinfo *res);
72
73/**
74 * the text of an EAI_ error.
75 */
76const 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 */
84int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen,
85 char *serv, socklen_t servlen, int flags);
86
87struct hostent
88{
89 char *h_name;
90 char **h_aliases;
94};
95#define h_addr h_addr_list[0]
96
97struct 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
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 */
119struct 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 */
125struct servent *getservbyname(const char *name, const char *proto);
126struct servent *getservbyport(int port, const char *proto);
127
128const char *hstrerror(int error);
uint8_t flags
Definition idt.c:3
IPv4 addresses and ports, and the IP protocols.
uint32_t error
Definition isr.h:3
struct servent * getservbyport(int port, const char *proto)
const char * hstrerror(int error)
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)
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 ...
int * __h_errno_location(void)
struct servent * getservbyname(const char *name, const char *proto)
a service by name or by port (network byte order); proto "tcp", "udp" or NULL.
const char * gai_strerror(int error)
the text of an EAI_ error.
struct hostent * gethostbyname(const char *name)
the older lookup: the IPv4 addresses of a name, in a buffer of the calling thread.
sockets: Unix domain stream sockets, with file descriptor passing, and IPv4 sockets (TCP; UDP,...
unsigned int socklen_t
Definition socket.h:21
Definition netdb.h:17
struct sockaddr * ai_addr
Definition netdb.h:23
char * ai_canonname
Definition netdb.h:24
int ai_socktype
Definition netdb.h:20
int ai_protocol
Definition netdb.h:21
socklen_t ai_addrlen
Definition netdb.h:22
struct addrinfo * ai_next
Definition netdb.h:25
int ai_flags
Definition netdb.h:18
int ai_family
Definition netdb.h:19
Definition netdb.h:88
int h_addrtype
Definition netdb.h:91
char * h_name
Definition netdb.h:89
char ** h_addr_list
Definition netdb.h:93
int h_length
Definition netdb.h:92
char ** h_aliases
Definition netdb.h:90
Definition netdb.h:98
char * s_name
Definition netdb.h:99
char * s_proto
Definition netdb.h:102
char ** s_aliases
Definition netdb.h:100
int s_port
Definition netdb.h:101
Definition socket.h:25