master
1#ifndef _NETDB_H
2#define _NETDB_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <features.h>
9#include <netinet/in.h>
10
11#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
12#define __NEED_size_t
13#include <bits/alltypes.h>
14#endif
15
16struct addrinfo {
17 int ai_flags;
18 int ai_family;
19 int ai_socktype;
20 int ai_protocol;
21 socklen_t ai_addrlen;
22 struct sockaddr *ai_addr;
23 char *ai_canonname;
24 struct addrinfo *ai_next;
25};
26
27#define AI_PASSIVE 0x01
28#define AI_CANONNAME 0x02
29#define AI_NUMERICHOST 0x04
30#define AI_V4MAPPED 0x08
31#define AI_ALL 0x10
32#define AI_ADDRCONFIG 0x20
33#define AI_NUMERICSERV 0x400
34
35
36#define NI_NUMERICHOST 0x01
37#define NI_NUMERICSERV 0x02
38#define NI_NOFQDN 0x04
39#define NI_NAMEREQD 0x08
40#define NI_DGRAM 0x10
41#define NI_NUMERICSCOPE 0x100
42
43#define EAI_BADFLAGS -1
44#define EAI_NONAME -2
45#define EAI_AGAIN -3
46#define EAI_FAIL -4
47#define EAI_NODATA -5
48#define EAI_FAMILY -6
49#define EAI_SOCKTYPE -7
50#define EAI_SERVICE -8
51#define EAI_MEMORY -10
52#define EAI_SYSTEM -11
53#define EAI_OVERFLOW -12
54
55int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict);
56void freeaddrinfo (struct addrinfo *);
57int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int);
58const char *gai_strerror(int);
59
60
61/* Legacy functions follow (marked OBsolete in SUS) */
62
63struct netent {
64 char *n_name;
65 char **n_aliases;
66 int n_addrtype;
67 uint32_t n_net;
68};
69
70struct hostent {
71 char *h_name;
72 char **h_aliases;
73 int h_addrtype;
74 int h_length;
75 char **h_addr_list;
76};
77#define h_addr h_addr_list[0]
78
79struct servent {
80 char *s_name;
81 char **s_aliases;
82 int s_port;
83 char *s_proto;
84};
85
86struct protoent {
87 char *p_name;
88 char **p_aliases;
89 int p_proto;
90};
91
92void sethostent (int);
93void endhostent (void);
94struct hostent *gethostent (void);
95
96void setnetent (int);
97void endnetent (void);
98struct netent *getnetent (void);
99struct netent *getnetbyaddr (uint32_t, int);
100struct netent *getnetbyname (const char *);
101
102void setservent (int);
103void endservent (void);
104struct servent *getservent (void);
105struct servent *getservbyname (const char *, const char *);
106struct servent *getservbyport (int, const char *);
107
108void setprotoent (int);
109void endprotoent (void);
110struct protoent *getprotoent (void);
111struct protoent *getprotobyname (const char *);
112struct protoent *getprotobynumber (int);
113
114#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
115 || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
116 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
117struct hostent *gethostbyname (const char *);
118struct hostent *gethostbyaddr (const void *, socklen_t, int);
119#ifdef __GNUC__
120__attribute__((const))
121#endif
122#ifdef __wasilibc_unmodified_upstream
123int *__h_errno_location(void);
124#define h_errno (*__h_errno_location())
125#elif (defined __wasilibc_use_wasip2)
126extern _Thread_local int h_errno;
127#define h_errno h_errno
128#endif
129#define HOST_NOT_FOUND 1
130#define TRY_AGAIN 2
131#define NO_RECOVERY 3
132#define NO_DATA 4
133#define NO_ADDRESS NO_DATA
134#endif
135
136#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
137void herror(const char *);
138const char *hstrerror(int);
139int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
140int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
141struct hostent *gethostbyname2(const char *, int);
142int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
143int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
144int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
145#define EAI_NODATA -5
146#define EAI_ADDRFAMILY -9
147#define EAI_INPROGRESS -100
148#define EAI_CANCELED -101
149#define EAI_NOTCANCELED -102
150#define EAI_ALLDONE -103
151#define EAI_INTR -104
152#define EAI_IDN_ENCODE -105
153#define NI_MAXHOST 255
154#define NI_MAXSERV 32
155#endif
156
157
158#ifdef __cplusplus
159}
160#endif
161
162#endif