• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  *    conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *    of conditions and the following disclaimer in the documentation and/or other materials
12  *    provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  *    to endorse or promote products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _ADAPT_NETDB_H
32 #define _ADAPT_NETDB_H
33 
34 #include <sys/features.h>
35 #include <sys/types.h>
36 #include <netinet/in.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #define AI_PASSIVE      0x01
43 #define AI_CANONNAME    0x02
44 #define AI_NUMERICHOST  0x04
45 #define AI_V4MAPPED     0x08
46 #define AI_ALL          0x10
47 #define AI_ADDRCONFIG   0x20
48 #define AI_NUMERICSERV  0x400
49 
50 #define NI_NUMERICHOST  0x01
51 #define NI_NUMERICSERV  0x02
52 #define NI_NOFQDN       0x04
53 #define NI_NAMEREQD     0x08
54 #define NI_DGRAM        0x10
55 #define NI_NUMERICSCOPE 0x100
56 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
57 #define NI_MAXHOST 255
58 #define NI_MAXSERV 32
59 #endif
60 
61 #define EAI_BADFLAGS   -1
62 #define EAI_NONAME     -2
63 #define EAI_AGAIN      -3
64 #define EAI_FAIL       -4
65 #define EAI_FAMILY     -6
66 #define EAI_SOCKTYPE   -7
67 #define EAI_SERVICE    -8
68 #define EAI_MEMORY     -10
69 #define EAI_SYSTEM     -11
70 #define EAI_OVERFLOW   -12
71 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
72 #define EAI_NODATA     -5
73 #define EAI_ADDRFAMILY -9
74 #define EAI_INPROGRESS -100
75 #define EAI_CANCELED   -101
76 #define EAI_NOTCANCELED -102
77 #define EAI_ALLDONE    -103
78 #define EAI_INTR       -104
79 #define EAI_IDN_ENCODE -105
80 #endif
81 
82 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
83 #define HOST_NOT_FOUND 1
84 #define TRY_AGAIN      2
85 #define NO_RECOVERY    3
86 #define NO_DATA        4
87 #define NO_ADDRESS     NO_DATA
88 #endif
89 
90 struct addrinfo {
91     int ai_flags;
92     int ai_family;
93     int ai_socktype;
94     int ai_protocol;
95     socklen_t ai_addrlen;
96     struct sockaddr *ai_addr;
97     char *ai_canonname;
98     struct addrinfo *ai_next;
99 };
100 
101 int getaddrinfo(const char *__restrict nodename, const char *__restrict servname, \
102                  const struct addrinfo *__restrict hints, struct addrinfo **__restrict res);
103 void freeaddrinfo(struct addrinfo *res);
104 int getnameinfo(const struct sockaddr * __restrict sa, socklen_t salen, char * __restrict host, \
105                 socklen_t hostlen, char * __restrict serv, socklen_t servlen, int flags);
106 const char *gai_strerror(int errcode);
107 
108 struct netent {
109     char *n_name;
110     char **n_aliases;
111     int n_addrtype;
112     uint32_t n_net;
113 };
114 
115 struct hostent {
116     char *h_name;
117     char **h_aliases;
118     int h_addrtype;
119     int h_length;
120     char **h_addr_list;
121 };
122 #define h_addr h_addr_list[0]
123 
124 struct servent {
125     char *s_name;
126     char **s_aliases;
127     int s_port;
128     char *s_proto;
129 };
130 
131 struct protoent {
132     char *p_name;
133     char **p_aliases;
134     int p_proto;
135 };
136 
137 void sethostent(int stay_open);
138 void endhostent(void);
139 struct hostent *gethostent(void);
140 
141 void setnetent(int stay_open);
142 void endnetent(void);
143 struct netent *getnetent(void);
144 struct netent *getnetbyaddr(uint32_t net, int type);
145 struct netent *getnetbyname(const char *name);
146 
147 void setservent(int stay_open);
148 void endservent(void);
149 struct servent *getservent(void);
150 struct servent *getservbyname(const char *name, const char *proto);
151 struct servent *getservbyport(int port, const char *proto);
152 
153 void setprotoent(int stay_open);
154 void endprotoent(void);
155 struct protoent *getprotoent(void);
156 struct protoent *getprotobyname(const char *name);
157 struct protoent *getprotobynumber(int proto);
158 
159 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
160     || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
161     || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
162 struct hostent *gethostbyname(const char *name);
163 struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type);
164 int *__h_errno_location(void);
165 #define h_errno (*__h_errno_location())
166 #endif
167 
168 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
169 void herror(const char *str);
170 const char *hstrerror(int errnum);
171 int gethostbyname_r(const char * name, struct hostent * ret, char * buf, size_t buflen, \
172                     struct hostent ** result, int * h_errnop);
173 int gethostbyname2_r(const char * __restrict name, int af, struct hostent * __restrict result_buf, \
174                      char * __restrict buf, size_t buflen, struct hostent ** __restrict result, \
175                      int * __restrict h_errnop);
176 struct hostent *gethostbyname2(const char *name, int af);
177 int gethostbyaddr_r(const void * __restrict addr, __socklen_t len, int type, struct hostent * __restrict result_buf, \
178                     char * __restrict buf, size_t buflen, struct hostent ** __restrict result, \
179                     int * __restrict h_errnop);
180 int getservbyport_r(int port, const char * __restrict proto, struct servent * __restrict result_buf, \
181                     char * __restrict buf, size_t buflen, struct servent ** __restrict result);
182 int getservbyname_r(const char *name, const char *proto, struct servent *result_buf, char *buf, size_t buflen, \
183                     struct servent **result);
184 #endif
185 
186 #ifdef __cplusplus
187 }
188 #endif
189 
190 #endif /* !_ADAPT_NETDB_H */
191