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 predefined_host_set_host(const char* host, const char* ip); 81 int predefined_host_set_hosts(const char* host_ips); 82 int predefined_host_clear_all_hosts(void); 83 int predefined_host_remove_host(const char *host); 84 85 /* Legacy functions follow (marked OBsolete in SUS) */ 86 87 struct netent { 88 char *n_name; 89 char **n_aliases; 90 int n_addrtype; 91 uint32_t n_net; 92 }; 93 94 struct hostent { 95 char *h_name; 96 char **h_aliases; 97 int h_addrtype; 98 int h_length; 99 char **h_addr_list; 100 }; 101 #define h_addr h_addr_list[0] 102 103 struct servent { 104 char *s_name; 105 char **s_aliases; 106 int s_port; 107 char *s_proto; 108 }; 109 110 struct protoent { 111 char *p_name; 112 char **p_aliases; 113 int p_proto; 114 }; 115 116 void sethostent (int); 117 void endhostent (void); 118 struct hostent *gethostent (void); 119 120 void setnetent (int); 121 void endnetent (void); 122 struct netent *getnetent (void); 123 struct netent *getnetbyaddr (uint32_t, int); 124 struct netent *getnetbyname (const char *); 125 126 void setservent (int); 127 void endservent (void); 128 struct servent *getservent (void); 129 struct servent *getservbyname (const char *, const char *); 130 struct servent *getservbyport (int, const char *); 131 132 void setprotoent (int); 133 void endprotoent (void); 134 struct protoent *getprotoent (void); 135 struct protoent *getprotobyname (const char *); 136 struct protoent *getprotobynumber (int); 137 138 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ 139 || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ 140 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) 141 struct hostent *gethostbyname (const char *); 142 struct hostent *gethostbyaddr (const void *, socklen_t, int); 143 #ifdef __GNUC__ 144 __attribute__((const)) 145 #endif 146 int *__h_errno_location(void); 147 #define h_errno (*__h_errno_location()) 148 #define HOST_NOT_FOUND 1 149 #define TRY_AGAIN 2 150 #define NO_RECOVERY 3 151 #define NO_DATA 4 152 #define NO_ADDRESS NO_DATA 153 #endif 154 155 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 156 void herror(const char *); 157 const char *hstrerror(int); 158 int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *); 159 int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *); 160 struct hostent *gethostbyname2(const char *, int); 161 int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *); 162 int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **); 163 int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **); 164 #define EAI_NODATA -5 165 #define EAI_ADDRFAMILY -9 166 #define EAI_INPROGRESS -100 167 #define EAI_CANCELED -101 168 #define EAI_NOTCANCELED -102 169 #define EAI_ALLDONE -103 170 #define EAI_INTR -104 171 #define EAI_IDN_ENCODE -105 172 #define NI_MAXHOST 255 173 #define NI_MAXSERV 32 174 #endif 175 176 177 #ifdef __cplusplus 178 } 179 #endif 180 181 #endif 182