| 1 |
#ifndef _NETDB_H |
| 2 |
#define _NETDB_H |
| 3 |
|
| 4 |
#include <wasi/version.h> |
| 5 |
|
| 6 |
#ifdef __cplusplus |
| 7 |
extern "C" { |
| 8 |
#endif |
| 9 |
|
| 10 |
#include <features.h> |
| 11 |
#include <netinet/in.h> |
| 12 |
|
| 13 |
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 14 |
#define __NEED_size_t |
| 15 |
#include <bits/alltypes.h> |
| 16 |
#endif |
| 17 |
|
| 18 |
struct addrinfo { |
| 19 |
int ai_flags; |
| 20 |
int ai_family; |
| 21 |
int ai_socktype; |
| 22 |
int ai_protocol; |
| 23 |
socklen_t ai_addrlen; |
| 24 |
struct sockaddr *ai_addr; |
| 25 |
char *ai_canonname; |
| 26 |
struct addrinfo *ai_next; |
| 27 |
}; |
| 28 |
|
| 29 |
#define AI_PASSIVE 0x01 |
| 30 |
#define AI_CANONNAME 0x02 |
| 31 |
#define AI_NUMERICHOST 0x04 |
| 32 |
#define AI_V4MAPPED 0x08 |
| 33 |
#define AI_ALL 0x10 |
| 34 |
#define AI_ADDRCONFIG 0x20 |
| 35 |
#define AI_NUMERICSERV 0x400 |
| 36 |
|
| 37 |
|
| 38 |
#define NI_NUMERICHOST 0x01 |
| 39 |
#define NI_NUMERICSERV 0x02 |
| 40 |
#define NI_NOFQDN 0x04 |
| 41 |
#define NI_NAMEREQD 0x08 |
| 42 |
#define NI_DGRAM 0x10 |
| 43 |
#define NI_NUMERICSCOPE 0x100 |
| 44 |
|
| 45 |
#define EAI_BADFLAGS -1 |
| 46 |
#define EAI_NONAME -2 |
| 47 |
#define EAI_AGAIN -3 |
| 48 |
#define EAI_FAIL -4 |
| 49 |
#define EAI_NODATA -5 |
| 50 |
#define EAI_FAMILY -6 |
| 51 |
#define EAI_SOCKTYPE -7 |
| 52 |
#define EAI_SERVICE -8 |
| 53 |
#define EAI_MEMORY -10 |
| 54 |
#define EAI_SYSTEM -11 |
| 55 |
#define EAI_OVERFLOW -12 |
| 56 |
|
| 57 |
int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict); |
| 58 |
void freeaddrinfo (struct addrinfo *); |
| 59 |
int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int); |
| 60 |
const char *gai_strerror(int); |
| 61 |
|
| 62 |
|
| 63 |
/* Legacy functions follow (marked OBsolete in SUS) */ |
| 64 |
|
| 65 |
struct netent { |
| 66 |
char *n_name; |
| 67 |
char **n_aliases; |
| 68 |
int n_addrtype; |
| 69 |
uint32_t n_net; |
| 70 |
}; |
| 71 |
|
| 72 |
struct hostent { |
| 73 |
char *h_name; |
| 74 |
char **h_aliases; |
| 75 |
int h_addrtype; |
| 76 |
int h_length; |
| 77 |
char **h_addr_list; |
| 78 |
}; |
| 79 |
#define h_addr h_addr_list[0] |
| 80 |
|
| 81 |
struct servent { |
| 82 |
char *s_name; |
| 83 |
char **s_aliases; |
| 84 |
int s_port; |
| 85 |
char *s_proto; |
| 86 |
}; |
| 87 |
|
| 88 |
struct protoent { |
| 89 |
char *p_name; |
| 90 |
char **p_aliases; |
| 91 |
int p_proto; |
| 92 |
}; |
| 93 |
|
| 94 |
void sethostent (int); |
| 95 |
void endhostent (void); |
| 96 |
struct hostent *gethostent (void); |
| 97 |
|
| 98 |
void setnetent (int); |
| 99 |
void endnetent (void); |
| 100 |
struct netent *getnetent (void); |
| 101 |
struct netent *getnetbyaddr (uint32_t, int); |
| 102 |
struct netent *getnetbyname (const char *); |
| 103 |
|
| 104 |
void setservent (int); |
| 105 |
void endservent (void); |
| 106 |
struct servent *getservent (void); |
| 107 |
struct servent *getservbyname (const char *, const char *); |
| 108 |
struct servent *getservbyport (int, const char *); |
| 109 |
|
| 110 |
void setprotoent (int); |
| 111 |
void endprotoent (void); |
| 112 |
struct protoent *getprotoent (void); |
| 113 |
struct protoent *getprotobyname (const char *); |
| 114 |
struct protoent *getprotobynumber (int); |
| 115 |
|
| 116 |
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ |
| 117 |
|| (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ |
| 118 |
|| (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) |
| 119 |
struct hostent *gethostbyname (const char *); |
| 120 |
struct hostent *gethostbyaddr (const void *, socklen_t, int); |
| 121 |
#ifdef __GNUC__ |
| 122 |
__attribute__((const)) |
| 123 |
#endif |
| 124 |
#ifdef __wasilibc_unmodified_upstream |
| 125 |
int *__h_errno_location(void); |
| 126 |
#define h_errno (*__h_errno_location()) |
| 127 |
#elif !(defined __wasip1__) |
| 128 |
extern _Thread_local int h_errno; |
| 129 |
#define h_errno h_errno |
| 130 |
#endif |
| 131 |
#define HOST_NOT_FOUND 1 |
| 132 |
#define TRY_AGAIN 2 |
| 133 |
#define NO_RECOVERY 3 |
| 134 |
#define NO_DATA 4 |
| 135 |
#define NO_ADDRESS NO_DATA |
| 136 |
#endif |
| 137 |
|
| 138 |
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 139 |
void herror(const char *); |
| 140 |
const char *hstrerror(int); |
| 141 |
int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *); |
| 142 |
int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *); |
| 143 |
struct hostent *gethostbyname2(const char *, int); |
| 144 |
int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *); |
| 145 |
int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **); |
| 146 |
int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **); |
| 147 |
#define EAI_NODATA -5 |
| 148 |
#define EAI_ADDRFAMILY -9 |
| 149 |
#define EAI_INPROGRESS -100 |
| 150 |
#define EAI_CANCELED -101 |
| 151 |
#define EAI_NOTCANCELED -102 |
| 152 |
#define EAI_ALLDONE -103 |
| 153 |
#define EAI_INTR -104 |
| 154 |
#define EAI_IDN_ENCODE -105 |
| 155 |
#define NI_MAXHOST 255 |
| 156 |
#define NI_MAXSERV 32 |
| 157 |
#endif |
| 158 |
|
| 159 |
|
| 160 |
#ifdef __cplusplus |
| 161 |
} |
| 162 |
#endif |
| 163 |
|
| 164 |
#endif |