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