blob: d096c78183b5609c4e5932adbd8d6ed8e75f168e [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#ifndef _NETDB_H
2#define _NETDB_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
Rich Felkerc1a96582012-09-07 23:13:55 -04008#include <features.h>
Rich Felker9448b052013-07-22 11:22:36 -04009#include <netinet/in.h>
Rich Felker400c5e52012-09-06 22:44:55 -040010
Rich Felker419ae6d2012-05-22 21:52:08 -040011#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
Rich Felker0b44a032011-02-12 00:22:29 -050012#define __NEED_size_t
Rich Felker0b44a032011-02-12 00:22:29 -050013#include <bits/alltypes.h>
Rich Felker9448b052013-07-22 11:22:36 -040014#endif
Rich Felker0b44a032011-02-12 00:22:29 -050015
Rich Felkerbefa5862016-07-03 14:40:11 -040016struct addrinfo {
Rich Felker0b44a032011-02-12 00:22:29 -050017 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
Rich Felker0b44a032011-02-12 00:22:29 -050027#define AI_PASSIVE 0x01
28#define AI_CANONNAME 0x02
29#define AI_NUMERICHOST 0x04
30#define AI_V4MAPPED 0x08
31#define AI_ALL 0x10
32#define AI_ADDRCONFIG 0x20
33#define AI_NUMERICSERV 0x400
34
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
Rich Felkerbdad2fe2014-06-04 02:24:38 -040041#define NI_NUMERICSCOPE 0x100
Rich Felker0b44a032011-02-12 00:22:29 -050042
Rich Felker0b44a032011-02-12 00:22:29 -050043#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
Rich Felker400c5e52012-09-06 22:44:55 -040054int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -050055void freeaddrinfo (struct addrinfo *);
Rich Felker400c5e52012-09-06 22:44:55 -040056int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int);
Rich Felker0b44a032011-02-12 00:22:29 -050057const char *gai_strerror(int);
58
59
60/* Legacy functions follow (marked OBsolete in SUS) */
61
Rich Felkerbefa5862016-07-03 14:40:11 -040062struct netent {
Rich Felker0b44a032011-02-12 00:22:29 -050063 char *n_name;
64 char **n_aliases;
65 int n_addrtype;
66 uint32_t n_net;
67};
68
Rich Felkerbefa5862016-07-03 14:40:11 -040069struct hostent {
Rich Felker0b44a032011-02-12 00:22:29 -050070 char *h_name;
71 char **h_aliases;
72 int h_addrtype;
73 int h_length;
74 char **h_addr_list;
75};
76#define h_addr h_addr_list[0]
77
Rich Felkerbefa5862016-07-03 14:40:11 -040078struct servent {
Rich Felker0b44a032011-02-12 00:22:29 -050079 char *s_name;
80 char **s_aliases;
81 int s_port;
82 char *s_proto;
83};
84
Rich Felkerbefa5862016-07-03 14:40:11 -040085struct protoent {
Rich Felker0b44a032011-02-12 00:22:29 -050086 char *p_name;
87 char **p_aliases;
88 int p_proto;
89};
90
Rich Felker0b44a032011-02-12 00:22:29 -050091void sethostent (int);
92void endhostent (void);
93struct hostent *gethostent (void);
Rich Felker0b44a032011-02-12 00:22:29 -050094
95void setnetent (int);
96void endnetent (void);
97struct netent *getnetent (void);
98struct netent *getnetbyaddr (uint32_t, int);
99struct netent *getnetbyname (const char *);
100
101void setservent (int);
102void endservent (void);
103struct servent *getservent (void);
104struct servent *getservbyname (const char *, const char *);
105struct servent *getservbyport (int, const char *);
106
107void setprotoent (int);
108void endprotoent (void);
109struct protoent *getprotoent (void);
110struct protoent *getprotobyname (const char *);
111struct protoent *getprotobynumber (int);
112
Rich Felker3f80afc2012-08-15 15:35:32 -0400113#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
Rich Felkerb367ab12012-11-01 03:49:43 -0400114 || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
115 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
Rich Felker3777f5b2012-05-12 23:38:04 -0400116struct hostent *gethostbyname (const char *);
Rich Felker3777f5b2012-05-12 23:38:04 -0400117struct hostent *gethostbyaddr (const void *, socklen_t, int);
Rich Felkerbf453d62018-10-16 13:48:10 -0400118#ifdef __GNUC__
119__attribute__((const))
120#endif
Rich Felkere68c51a2012-05-12 23:45:07 -0400121int *__h_errno_location(void);
122#define h_errno (*__h_errno_location())
Rich Felker3f80afc2012-08-15 15:35:32 -0400123#define HOST_NOT_FOUND 1
124#define TRY_AGAIN 2
125#define NO_RECOVERY 3
126#define NO_DATA 4
Timo Teräsa0351ee2014-01-13 13:36:03 +0200127#define NO_ADDRESS NO_DATA
Rich Felker3f80afc2012-08-15 15:35:32 -0400128#endif
129
130#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
Rich Felker18144af2013-12-20 11:56:16 -0500131void herror(const char *);
Rich Felker3f80afc2012-08-15 15:35:32 -0400132const char *hstrerror(int);
133int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
134int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
135struct hostent *gethostbyname2(const char *, int);
136int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
137int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
138int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
Rich Felker7db6a872012-05-12 23:31:52 -0400139#define EAI_NODATA -5
140#define EAI_ADDRFAMILY -9
141#define EAI_INPROGRESS -100
142#define EAI_CANCELED -101
143#define EAI_NOTCANCELED -102
144#define EAI_ALLDONE -103
145#define EAI_INTR -104
146#define EAI_IDN_ENCODE -105
Rich Felker20052b92012-05-12 23:34:39 -0400147#define NI_MAXHOST 255
148#define NI_MAXSERV 32
Rich Felker0b44a032011-02-12 00:22:29 -0500149#endif
150
151
152#ifdef __cplusplus
153}
154#endif
155
156#endif