blob: 3cda7114e8c24724efbe919505fbf0c839d55644 [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 Felker400c5e52012-09-06 22:44:55 -04009
Rich Felker419ae6d2012-05-22 21:52:08 -040010#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
Rich Felker0b44a032011-02-12 00:22:29 -050011#define __NEED_size_t
12#endif
13
14#define __NEED_socklen_t
15#define __NEED_uint32_t
16
17#include <bits/alltypes.h>
18
19struct addrinfo
20{
21 int ai_flags;
22 int ai_family;
23 int ai_socktype;
24 int ai_protocol;
25 socklen_t ai_addrlen;
26 struct sockaddr *ai_addr;
27 char *ai_canonname;
28 struct addrinfo *ai_next;
29};
30
31#define IPPORT_RESERVED 1024
32
33#define AI_PASSIVE 0x01
34#define AI_CANONNAME 0x02
35#define AI_NUMERICHOST 0x04
36#define AI_V4MAPPED 0x08
37#define AI_ALL 0x10
38#define AI_ADDRCONFIG 0x20
39#define AI_NUMERICSERV 0x400
40
41
42#define NI_NUMERICHOST 0x01
43#define NI_NUMERICSERV 0x02
44#define NI_NOFQDN 0x04
45#define NI_NAMEREQD 0x08
46#define NI_DGRAM 0x10
47/*#define NI_NUMERICSCOPE */
48
Rich Felker0b44a032011-02-12 00:22:29 -050049#define EAI_BADFLAGS -1
50#define EAI_NONAME -2
51#define EAI_AGAIN -3
52#define EAI_FAIL -4
53#define EAI_FAMILY -6
54#define EAI_SOCKTYPE -7
55#define EAI_SERVICE -8
56#define EAI_MEMORY -10
57#define EAI_SYSTEM -11
58#define EAI_OVERFLOW -12
59
Rich Felker400c5e52012-09-06 22:44:55 -040060int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -050061void freeaddrinfo (struct addrinfo *);
Rich Felker400c5e52012-09-06 22:44:55 -040062int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int);
Rich Felker0b44a032011-02-12 00:22:29 -050063const char *gai_strerror(int);
64
65
66/* Legacy functions follow (marked OBsolete in SUS) */
67
68struct netent
69{
70 char *n_name;
71 char **n_aliases;
72 int n_addrtype;
73 uint32_t n_net;
74};
75
76struct hostent
77{
78 char *h_name;
79 char **h_aliases;
80 int h_addrtype;
81 int h_length;
82 char **h_addr_list;
83};
84#define h_addr h_addr_list[0]
85
86struct servent
87{
88 char *s_name;
89 char **s_aliases;
90 int s_port;
91 char *s_proto;
92};
93
94struct protoent
95{
96 char *p_name;
97 char **p_aliases;
98 int p_proto;
99};
100
Rich Felker0b44a032011-02-12 00:22:29 -0500101void sethostent (int);
102void endhostent (void);
103struct hostent *gethostent (void);
Rich Felker0b44a032011-02-12 00:22:29 -0500104
105void setnetent (int);
106void endnetent (void);
107struct netent *getnetent (void);
108struct netent *getnetbyaddr (uint32_t, int);
109struct netent *getnetbyname (const char *);
110
111void setservent (int);
112void endservent (void);
113struct servent *getservent (void);
114struct servent *getservbyname (const char *, const char *);
115struct servent *getservbyport (int, const char *);
116
117void setprotoent (int);
118void endprotoent (void);
119struct protoent *getprotoent (void);
120struct protoent *getprotobyname (const char *);
121struct protoent *getprotobynumber (int);
122
Rich Felker3f80afc2012-08-15 15:35:32 -0400123#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
Rich Felkerb367ab12012-11-01 03:49:43 -0400124 || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
125 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
Rich Felker3777f5b2012-05-12 23:38:04 -0400126struct hostent *gethostbyname (const char *);
Rich Felker3777f5b2012-05-12 23:38:04 -0400127struct hostent *gethostbyaddr (const void *, socklen_t, int);
Rich Felkere68c51a2012-05-12 23:45:07 -0400128#ifdef __GNUC__
129__attribute__((const))
130#endif
131int *__h_errno_location(void);
132#define h_errno (*__h_errno_location())
Rich Felker3f80afc2012-08-15 15:35:32 -0400133#define HOST_NOT_FOUND 1
134#define TRY_AGAIN 2
135#define NO_RECOVERY 3
136#define NO_DATA 4
137#endif
138
139#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
140const char *hstrerror(int);
141int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
142int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
143struct hostent *gethostbyname2(const char *, int);
144int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
145int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
146int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
Rich Felker7db6a872012-05-12 23:31:52 -0400147#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
Rich Felker20052b92012-05-12 23:34:39 -0400155#define NI_MAXHOST 255
156#define NI_MAXSERV 32
Rich Felker0b44a032011-02-12 00:22:29 -0500157#endif
158
159
160#ifdef __cplusplus
161}
162#endif
163
164#endif