blob: 82c78dc8991826a04b1276f6967f48fd43f4ff1e [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 Felker419ae6d2012-05-22 21:52:08 -04008#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
Rich Felker0b44a032011-02-12 00:22:29 -05009#define __NEED_size_t
10#endif
11
12#define __NEED_socklen_t
13#define __NEED_uint32_t
14
15#include <bits/alltypes.h>
16
17struct addrinfo
18{
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 IPPORT_RESERVED 1024
30
31#define AI_PASSIVE 0x01
32#define AI_CANONNAME 0x02
33#define AI_NUMERICHOST 0x04
34#define AI_V4MAPPED 0x08
35#define AI_ALL 0x10
36#define AI_ADDRCONFIG 0x20
37#define AI_NUMERICSERV 0x400
38
39
40#define NI_NUMERICHOST 0x01
41#define NI_NUMERICSERV 0x02
42#define NI_NOFQDN 0x04
43#define NI_NAMEREQD 0x08
44#define NI_DGRAM 0x10
45/*#define NI_NUMERICSCOPE */
46
Rich Felker0b44a032011-02-12 00:22:29 -050047#define EAI_BADFLAGS -1
48#define EAI_NONAME -2
49#define EAI_AGAIN -3
50#define EAI_FAIL -4
51#define EAI_FAMILY -6
52#define EAI_SOCKTYPE -7
53#define EAI_SERVICE -8
54#define EAI_MEMORY -10
55#define EAI_SYSTEM -11
56#define EAI_OVERFLOW -12
57
58int getaddrinfo (const char *, const char *, const struct addrinfo *, struct addrinfo **);
59void freeaddrinfo (struct addrinfo *);
60int getnameinfo (const struct sockaddr *, socklen_t, char *, socklen_t, char *, socklen_t, int);
61const char *gai_strerror(int);
62
63
64/* Legacy functions follow (marked OBsolete in SUS) */
65
66struct netent
67{
68 char *n_name;
69 char **n_aliases;
70 int n_addrtype;
71 uint32_t n_net;
72};
73
74struct hostent
75{
76 char *h_name;
77 char **h_aliases;
78 int h_addrtype;
79 int h_length;
80 char **h_addr_list;
81};
82#define h_addr h_addr_list[0]
83
84struct servent
85{
86 char *s_name;
87 char **s_aliases;
88 int s_port;
89 char *s_proto;
90};
91
92struct protoent
93{
94 char *p_name;
95 char **p_aliases;
96 int p_proto;
97};
98
Rich Felker0b44a032011-02-12 00:22:29 -050099void sethostent (int);
100void endhostent (void);
101struct hostent *gethostent (void);
Rich Felker0b44a032011-02-12 00:22:29 -0500102
103void setnetent (int);
104void endnetent (void);
105struct netent *getnetent (void);
106struct netent *getnetbyaddr (uint32_t, int);
107struct netent *getnetbyname (const char *);
108
109void setservent (int);
110void endservent (void);
111struct servent *getservent (void);
112struct servent *getservbyname (const char *, const char *);
113struct servent *getservbyport (int, const char *);
114
115void setprotoent (int);
116void endprotoent (void);
117struct protoent *getprotoent (void);
118struct protoent *getprotobyname (const char *);
119struct protoent *getprotobynumber (int);
120
Rich Felker419ae6d2012-05-22 21:52:08 -0400121#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
Rich Felker0b44a032011-02-12 00:22:29 -0500122const char *hstrerror(int);
Rich Felker3777f5b2012-05-12 23:38:04 -0400123struct hostent *gethostbyname (const char *);
Rich Felker0b44a032011-02-12 00:22:29 -0500124int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
125int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
126struct hostent *gethostbyname2(const char *, int);
Rich Felker3777f5b2012-05-12 23:38:04 -0400127struct hostent *gethostbyaddr (const void *, socklen_t, int);
Rich Felker0b44a032011-02-12 00:22:29 -0500128int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
129int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
130int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
Rich Felkere68c51a2012-05-12 23:45:07 -0400131#ifdef __GNUC__
132__attribute__((const))
133#endif
134int *__h_errno_location(void);
135#define h_errno (*__h_errno_location())
Rich Felker7db6a872012-05-12 23:31:52 -0400136#define EAI_NODATA -5
137#define EAI_ADDRFAMILY -9
138#define EAI_INPROGRESS -100
139#define EAI_CANCELED -101
140#define EAI_NOTCANCELED -102
141#define EAI_ALLDONE -103
142#define EAI_INTR -104
143#define EAI_IDN_ENCODE -105
Rich Felker20052b92012-05-12 23:34:39 -0400144#define NI_MAXHOST 255
145#define NI_MAXSERV 32
Rich Felker3777f5b2012-05-12 23:38:04 -0400146#define HOST_NOT_FOUND 1
147#define TRY_AGAIN 2
148#define NO_RECOVERY 3
149#define NO_DATA 4
Rich Felker0b44a032011-02-12 00:22:29 -0500150#endif
151
152
153#ifdef __cplusplus
154}
155#endif
156
157#endif