Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 1 | #ifndef _NETDB_H |
| 2 | #define _NETDB_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
Rich Felker | c1a9658 | 2012-09-07 23:13:55 -0400 | [diff] [blame] | 8 | #include <features.h> |
Rich Felker | 9448b05 | 2013-07-22 11:22:36 -0400 | [diff] [blame] | 9 | #include <netinet/in.h> |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 10 | |
Rich Felker | 419ae6d | 2012-05-22 21:52:08 -0400 | [diff] [blame] | 11 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 12 | #define __NEED_size_t |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 13 | #include <bits/alltypes.h> |
Rich Felker | 9448b05 | 2013-07-22 11:22:36 -0400 | [diff] [blame] | 14 | #endif |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 15 | |
Rich Felker | befa586 | 2016-07-03 14:40:11 -0400 | [diff] [blame^] | 16 | struct addrinfo { |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 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 | #define IPPORT_RESERVED 1024 |
| 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 |
Rich Felker | bdad2fe | 2014-06-04 02:24:38 -0400 | [diff] [blame] | 43 | #define NI_NUMERICSCOPE 0x100 |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 44 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 45 | #define EAI_BADFLAGS -1 |
| 46 | #define EAI_NONAME -2 |
| 47 | #define EAI_AGAIN -3 |
| 48 | #define EAI_FAIL -4 |
| 49 | #define EAI_FAMILY -6 |
| 50 | #define EAI_SOCKTYPE -7 |
| 51 | #define EAI_SERVICE -8 |
| 52 | #define EAI_MEMORY -10 |
| 53 | #define EAI_SYSTEM -11 |
| 54 | #define EAI_OVERFLOW -12 |
| 55 | |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 56 | int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 57 | void freeaddrinfo (struct addrinfo *); |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 58 | int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 59 | const char *gai_strerror(int); |
| 60 | |
| 61 | |
| 62 | /* Legacy functions follow (marked OBsolete in SUS) */ |
| 63 | |
Rich Felker | befa586 | 2016-07-03 14:40:11 -0400 | [diff] [blame^] | 64 | struct netent { |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 65 | char *n_name; |
| 66 | char **n_aliases; |
| 67 | int n_addrtype; |
| 68 | uint32_t n_net; |
| 69 | }; |
| 70 | |
Rich Felker | befa586 | 2016-07-03 14:40:11 -0400 | [diff] [blame^] | 71 | struct hostent { |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 72 | char *h_name; |
| 73 | char **h_aliases; |
| 74 | int h_addrtype; |
| 75 | int h_length; |
| 76 | char **h_addr_list; |
| 77 | }; |
| 78 | #define h_addr h_addr_list[0] |
| 79 | |
Rich Felker | befa586 | 2016-07-03 14:40:11 -0400 | [diff] [blame^] | 80 | struct servent { |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 81 | char *s_name; |
| 82 | char **s_aliases; |
| 83 | int s_port; |
| 84 | char *s_proto; |
| 85 | }; |
| 86 | |
Rich Felker | befa586 | 2016-07-03 14:40:11 -0400 | [diff] [blame^] | 87 | struct protoent { |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 88 | char *p_name; |
| 89 | char **p_aliases; |
| 90 | int p_proto; |
| 91 | }; |
| 92 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 93 | void sethostent (int); |
| 94 | void endhostent (void); |
| 95 | struct hostent *gethostent (void); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 96 | |
| 97 | void setnetent (int); |
| 98 | void endnetent (void); |
| 99 | struct netent *getnetent (void); |
| 100 | struct netent *getnetbyaddr (uint32_t, int); |
| 101 | struct netent *getnetbyname (const char *); |
| 102 | |
| 103 | void setservent (int); |
| 104 | void endservent (void); |
| 105 | struct servent *getservent (void); |
| 106 | struct servent *getservbyname (const char *, const char *); |
| 107 | struct servent *getservbyport (int, const char *); |
| 108 | |
| 109 | void setprotoent (int); |
| 110 | void endprotoent (void); |
| 111 | struct protoent *getprotoent (void); |
| 112 | struct protoent *getprotobyname (const char *); |
| 113 | struct protoent *getprotobynumber (int); |
| 114 | |
Rich Felker | 3f80afc | 2012-08-15 15:35:32 -0400 | [diff] [blame] | 115 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ |
Rich Felker | b367ab1 | 2012-11-01 03:49:43 -0400 | [diff] [blame] | 116 | || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ |
| 117 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) |
Rich Felker | 3777f5b | 2012-05-12 23:38:04 -0400 | [diff] [blame] | 118 | struct hostent *gethostbyname (const char *); |
Rich Felker | 3777f5b | 2012-05-12 23:38:04 -0400 | [diff] [blame] | 119 | struct hostent *gethostbyaddr (const void *, socklen_t, int); |
Rich Felker | e68c51a | 2012-05-12 23:45:07 -0400 | [diff] [blame] | 120 | int *__h_errno_location(void); |
| 121 | #define h_errno (*__h_errno_location()) |
Rich Felker | 3f80afc | 2012-08-15 15:35:32 -0400 | [diff] [blame] | 122 | #define HOST_NOT_FOUND 1 |
| 123 | #define TRY_AGAIN 2 |
| 124 | #define NO_RECOVERY 3 |
| 125 | #define NO_DATA 4 |
Timo Teräs | a0351ee | 2014-01-13 13:36:03 +0200 | [diff] [blame] | 126 | #define NO_ADDRESS NO_DATA |
Rich Felker | 3f80afc | 2012-08-15 15:35:32 -0400 | [diff] [blame] | 127 | #endif |
| 128 | |
| 129 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
Rich Felker | 18144af | 2013-12-20 11:56:16 -0500 | [diff] [blame] | 130 | void herror(const char *); |
Rich Felker | 3f80afc | 2012-08-15 15:35:32 -0400 | [diff] [blame] | 131 | const char *hstrerror(int); |
| 132 | int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *); |
| 133 | int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *); |
| 134 | struct hostent *gethostbyname2(const char *, int); |
| 135 | int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, 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 **); |
Rich Felker | 7db6a87 | 2012-05-12 23:31:52 -0400 | [diff] [blame] | 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 |
Rich Felker | 20052b9 | 2012-05-12 23:34:39 -0400 | [diff] [blame] | 146 | #define NI_MAXHOST 255 |
| 147 | #define NI_MAXSERV 32 |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 148 | #endif |
| 149 | |
| 150 | |
| 151 | #ifdef __cplusplus |
| 152 | } |
| 153 | #endif |
| 154 | |
| 155 | #endif |