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