• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef	_NETDB_H
2 #define	_NETDB_H
3 
4 #ifdef __cplusplus
5 extern "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 
16 struct 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 typedef int (*net_dnsquery_hook)(int, int, int);
28 typedef int (*custom_dns_resolver)(const char *host, const char *serv,
29 	const struct addrinfo *hint, struct addrinfo **res);
30 
31 enum {
32 	QEURY_TYPE_NORMAL = 0,
33 	QEURY_TYPE_NETSYS,
34 };
35 
36 struct queryparam {
37 	int qp_type;
38 	int qp_netid;
39 	int qp_mark;
40 	int qp_flag;
41 	net_dnsquery_hook qhook;
42 };
43 
44 #define AI_PASSIVE      0x01
45 #define AI_CANONNAME    0x02
46 #define AI_NUMERICHOST  0x04
47 #define AI_V4MAPPED     0x08
48 #define AI_ALL          0x10
49 #define AI_ADDRCONFIG   0x20
50 #define AI_NUMERICSERV  0x400
51 
52 
53 #define NI_NUMERICHOST  0x01
54 #define NI_NUMERICSERV  0x02
55 #define NI_NOFQDN       0x04
56 #define NI_NAMEREQD     0x08
57 #define NI_DGRAM        0x10
58 #define NI_NUMERICSCOPE 0x100
59 
60 #define EAI_BADFLAGS   -1
61 #define EAI_NONAME     -2
62 #define EAI_AGAIN      -3
63 #define EAI_FAIL       -4
64 #define EAI_FAMILY     -6
65 #define EAI_SOCKTYPE   -7
66 #define EAI_SERVICE    -8
67 #define EAI_MEMORY     -10
68 #define EAI_SYSTEM     -11
69 #define EAI_OVERFLOW   -12
70 
71 int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict);
72 int getaddrinfo_ext (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict,
73 					 struct addrinfo **__restrict, struct queryparam *__restrict);
74 void freeaddrinfo (struct addrinfo *);
75 int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int);
76 const char *gai_strerror(int);
77 
78 int setdnsresolvehook(custom_dns_resolver hookfunc);
79 int removednsresolvehook();
80 int getaddrinfo_hook(const char* host, const char* serv, const struct addrinfo* hint, struct addrinfo** res);
81 int predefined_host_set_host(const char* host, const char* ip);
82 int predefined_host_set_hosts(const char* host_ips);
83 int predefined_host_clear_all_hosts(void);
84 int predefined_host_remove_host(const char *host);
85 
86 /* Legacy functions follow (marked OBsolete in SUS) */
87 
88 struct netent {
89 	char *n_name;
90 	char **n_aliases;
91 	int n_addrtype;
92 	uint32_t n_net;
93 };
94 
95 struct hostent {
96 	char *h_name;
97 	char **h_aliases;
98 	int h_addrtype;
99 	int h_length;
100 	char **h_addr_list;
101 };
102 #define h_addr h_addr_list[0]
103 
104 struct servent {
105 	char *s_name;
106 	char **s_aliases;
107 	int s_port;
108 	char *s_proto;
109 };
110 
111 struct protoent {
112 	char *p_name;
113 	char **p_aliases;
114 	int p_proto;
115 };
116 
117 void sethostent (int);
118 void endhostent (void);
119 struct hostent *gethostent (void);
120 
121 void setnetent (int);
122 void endnetent (void);
123 struct netent *getnetent (void);
124 struct netent *getnetbyaddr (uint32_t, int);
125 struct netent *getnetbyname (const char *);
126 
127 void setservent (int);
128 void endservent (void);
129 struct servent *getservent (void);
130 struct servent *getservbyname (const char *, const char *);
131 struct servent *getservbyport (int, const char *);
132 
133 void setprotoent (int);
134 void endprotoent (void);
135 struct protoent *getprotoent (void);
136 struct protoent *getprotobyname (const char *);
137 struct protoent *getprotobynumber (int);
138 
139 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
140  || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
141  || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
142 struct hostent *gethostbyname (const char *);
143 struct hostent *gethostbyaddr (const void *, socklen_t, int);
144 #ifdef __GNUC__
145 __attribute__((const))
146 #endif
147 int *__h_errno_location(void);
148 #define h_errno (*__h_errno_location())
149 #define HOST_NOT_FOUND 1
150 #define TRY_AGAIN      2
151 #define NO_RECOVERY    3
152 #define NO_DATA        4
153 #define NO_ADDRESS     NO_DATA
154 #endif
155 
156 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
157 void herror(const char *);
158 const char *hstrerror(int);
159 int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
160 int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
161 struct hostent *gethostbyname2(const char *, int);
162 int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
163 int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
164 int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
165 #define EAI_NODATA     -5
166 #define EAI_ADDRFAMILY -9
167 #define EAI_INPROGRESS -100
168 #define EAI_CANCELED   -101
169 #define EAI_NOTCANCELED -102
170 #define EAI_ALLDONE    -103
171 #define EAI_INTR       -104
172 #define EAI_IDN_ENCODE -105
173 #define NI_MAXHOST 255
174 #define NI_MAXSERV 32
175 #endif
176 
177 
178 #ifdef __cplusplus
179 }
180 #endif
181 
182 #endif
183