1#ifndef _NETDB_H 2#define _NETDB_H 3 4#ifdef __cplusplus 5extern "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 16struct 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 27typedef int (*net_dnsquery_hook)(int, int, int); 28typedef int (*custom_dns_resolver)(const char *host, const char *serv, 29 const struct addrinfo *hint, struct addrinfo **res); 30 31enum { 32 QEURY_TYPE_NORMAL = 0, 33 QEURY_TYPE_NETSYS, 34}; 35 36struct 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 71int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict); 72int getaddrinfo_ext (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, 73 struct addrinfo **__restrict, struct queryparam *__restrict); 74void freeaddrinfo (struct addrinfo *); 75int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int); 76const char *gai_strerror(int); 77 78int setdnsresolvehook(custom_dns_resolver hookfunc); 79int removednsresolvehook(); 80int getaddrinfo_hook(const char* host, const char* serv, const struct addrinfo* hint, struct addrinfo** res); 81int predefined_host_set_host(const char* host, const char* ip); 82int predefined_host_set_hosts(const char* host_ips); 83int predefined_host_clear_all_hosts(void); 84int predefined_host_remove_host(const char *host); 85 86/* Legacy functions follow (marked OBsolete in SUS) */ 87 88struct netent { 89 char *n_name; 90 char **n_aliases; 91 int n_addrtype; 92 uint32_t n_net; 93}; 94 95struct 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 104struct servent { 105 char *s_name; 106 char **s_aliases; 107 int s_port; 108 char *s_proto; 109}; 110 111struct protoent { 112 char *p_name; 113 char **p_aliases; 114 int p_proto; 115}; 116 117void sethostent (int); 118void endhostent (void); 119struct hostent *gethostent (void); 120 121void setnetent (int); 122void endnetent (void); 123struct netent *getnetent (void); 124struct netent *getnetbyaddr (uint32_t, int); 125struct netent *getnetbyname (const char *); 126 127void setservent (int); 128void endservent (void); 129struct servent *getservent (void); 130struct servent *getservbyname (const char *, const char *); 131struct servent *getservbyport (int, const char *); 132 133void setprotoent (int); 134void endprotoent (void); 135struct protoent *getprotoent (void); 136struct protoent *getprotobyname (const char *); 137struct 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) 142struct hostent *gethostbyname (const char *); 143struct hostent *gethostbyaddr (const void *, socklen_t, int); 144#ifdef __GNUC__ 145__attribute__((const)) 146#endif 147int *__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) 157void herror(const char *); 158const char *hstrerror(int); 159int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *); 160int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *); 161struct hostent *gethostbyname2(const char *, int); 162int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *); 163int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **); 164int 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