1 /*
2  * Copyright (c) 2019 Linaro Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #ifndef ZEPHYR_INCLUDE_POSIX_NETDB_H_
7 #define ZEPHYR_INCLUDE_POSIX_NETDB_H_
8 
9 #include <zephyr/net/socket.h>
10 
11 #ifndef NI_MAXSERV
12 /** Provide a reasonable size for apps using getnameinfo */
13 #define NI_MAXSERV 32
14 #endif
15 
16 #define EAI_BADFLAGS DNS_EAI_BADFLAGS
17 #define EAI_NONAME DNS_EAI_NONAME
18 #define EAI_AGAIN DNS_EAI_AGAIN
19 #define EAI_FAIL DNS_EAI_FAIL
20 #define EAI_NODATA DNS_EAI_NODATA
21 #define EAI_MEMORY DNS_EAI_MEMORY
22 #define EAI_SYSTEM DNS_EAI_SYSTEM
23 #define EAI_SERVICE DNS_EAI_SERVICE
24 #define EAI_SOCKTYPE DNS_EAI_SOCKTYPE
25 #define EAI_FAMILY DNS_EAI_FAMILY
26 #define EAI_OVERFLOW DNS_EAI_OVERFLOW
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 struct hostent {
33 	char *h_name;
34 	char **h_aliases;
35 	int h_addrtype;
36 	int h_length;
37 	char **h_addr_list;
38 };
39 
40 struct netent {
41 	char *n_name;
42 	char **n_aliases;
43 	int n_addrtype;
44 	uint32_t n_net;
45 };
46 
47 struct protoent {
48 	char *p_name;
49 	char **p_aliases;
50 	int p_proto;
51 };
52 
53 struct servent {
54 	char *s_name;
55 	char **s_aliases;
56 	int s_port;
57 	char *s_proto;
58 };
59 
60 #define addrinfo zsock_addrinfo
61 
62 void endhostent(void);
63 void endnetent(void);
64 void endprotoent(void);
65 void endservent(void);
66 void freeaddrinfo(struct zsock_addrinfo *ai);
67 const char *gai_strerror(int errcode);
68 int getaddrinfo(const char *host, const char *service, const struct zsock_addrinfo *hints,
69 		struct zsock_addrinfo **res);
70 struct hostent *gethostent(void);
71 int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen,
72 		char *serv, socklen_t servlen, int flags);
73 struct netent *getnetbyaddr(uint32_t net, int type);
74 struct netent *getnetbyname(const char *name);
75 struct netent *getnetent(void);
76 struct protoent *getprotobyname(const char *name);
77 struct protoent *getprotobynumber(int proto);
78 struct protoent *getprotoent(void);
79 struct servent *getservbyname(const char *name, const char *proto);
80 struct servent *getservbyport(int port, const char *proto);
81 struct servent *getservent(void);
82 void sethostent(int stayopen);
83 void setnetent(int stayopen);
84 void setprotoent(int stayopen);
85 void setservent(int stayopen);
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif	/* ZEPHYR_INCLUDE_POSIX_NETDB_H_ */
92