xref: /haiku/headers/posix/netdb.h (revision 79bc16ba6e9a8e9d4a29fb63c08341256f1b953e)
1 /*
2  * Copyright 2023, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _NETDB_H_
6 #define _NETDB_H_
7 
8 #include <stdint.h>
9 #include <netinet/in.h>
10 
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 
17 struct hostent {
18 	char* h_name;
19 	char** h_aliases;
20 	int h_addrtype;
21 	int h_length;
22 	char** h_addr_list;
23 #define	h_addr	h_addr_list[0]
24 };
25 
26 struct netent {
27 	char* n_name;
28 	char** n_aliases;
29 	int n_addrtype;
30 	in_addr_t n_net;
31 };
32 
33 struct servent {
34 	char* s_name;
35 	char** s_aliases;
36 	int s_port;
37 	char* s_proto;
38 };
39 
40 struct protoent {
41 	char* p_name;
42 	char** p_aliases;
43 	int p_proto;
44 };
45 
46 struct addrinfo {
47 	int ai_flags;
48 	int ai_family;
49 	int ai_socktype;
50 	int ai_protocol;
51 	socklen_t ai_addrlen;
52 	char* ai_canonname;
53 	struct sockaddr* ai_addr;
54 	struct addrinfo* ai_next;
55 };
56 
57 
58 #if defined(_DEFAULT_SOURCE)
59 extern int * __h_errno(void);
60 #define	h_errno (*__h_errno())
61 
62 void herror(const char *);
63 const char *hstrerror(int);
64 
65 #define	NETDB_INTERNAL	-1
66 #define	NETDB_SUCCESS	0
67 #define	HOST_NOT_FOUND	1
68 #define	TRY_AGAIN		2
69 #define	NO_RECOVERY		3
70 #define	NO_DATA			4
71 #define	NO_ADDRESS		NO_DATA
72 #endif
73 
74 
75 /* getaddrinfo, getnameinfo */
76 #define	AI_PASSIVE		0x00000001
77 #define	AI_CANONNAME	0x00000002
78 #define AI_NUMERICHOST	0x00000004
79 #define AI_NUMERICSERV	0x00000008
80 
81 #define AI_ALL			0x00000100
82 #define AI_V4MAPPED_CFG	0x00000200
83 #define AI_ADDRCONFIG	0x00000400
84 #define AI_V4MAPPED		0x00000800
85 
86 #define	AI_MASK			\
87 	(AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | AI_ADDRCONFIG)
88 
89 
90 /* getnameinfo */
91 #if defined(_DEFAULT_SOURCE)
92 #define	NI_MAXHOST		1025
93 #define	NI_MAXSERV		32
94 
95 #define SCOPE_DELIMITER	'%'
96 #endif
97 
98 #define	NI_NOFQDN		0x00000001
99 #define	NI_NUMERICHOST	0x00000002
100 #define	NI_NAMEREQD		0x00000004
101 #define	NI_NUMERICSERV	0x00000008
102 #define	NI_DGRAM		0x00000010
103 #define NI_NUMERICSCOPE	0x00000040
104 
105 
106 /* getaddrinfo */
107 #define	EAI_ADDRFAMILY	1
108 #define	EAI_AGAIN	 	2
109 #define	EAI_BADFLAGS	3
110 #define	EAI_FAIL		4
111 #define	EAI_FAMILY		5
112 #define	EAI_MEMORY		6
113 #define	EAI_NODATA		7
114 #define	EAI_NONAME		8
115 #define	EAI_SERVICE		9
116 #define	EAI_SOCKTYPE	10
117 #define	EAI_SYSTEM		11
118 #define EAI_BADHINTS	12
119 #define EAI_PROTOCOL	13
120 #define EAI_OVERFLOW	14
121 #define EAI_MAX			15
122 
123 
124 void sethostent(int);
125 void endhostent(void);
126 struct hostent* gethostent(void);
127 
128 void setnetent(int);
129 void endnetent(void);
130 struct netent* getnetbyaddr(uint32_t, int);
131 struct netent* getnetbyname(const char *);
132 struct netent* getnetent(void);
133 
134 void setprotoent(int);
135 void endprotoent(void);
136 struct protoent* getprotoent(void);
137 struct protoent* getprotobyname(const char *);
138 struct protoent* getprotobynumber(int);
139 
140 void setservent(int);
141 void endservent(void);
142 struct servent* getservent(void);
143 struct servent* getservbyname(const char *, const char *);
144 struct servent* getservbyport(int, const char *);
145 
146 struct hostent* gethostbyaddr(const void *address, socklen_t length, int type);
147 struct hostent* gethostbyname(const char *name);
148 struct hostent* gethostbyname2(const char *name, int type);
149 
150 int getaddrinfo(const char *, const char *, const struct addrinfo *,
151 	struct addrinfo **);
152 int getnameinfo(const struct sockaddr *, socklen_t, char *, socklen_t,
153 	char *, socklen_t, int);
154 void freeaddrinfo(struct addrinfo *);
155 
156 const char* gai_strerror(int);
157 
158 
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 #endif /* _NETDB_H_ */
164