blob: 8a7013ad0126454733b394a644639aa374ab0c10 [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
16struct addrinfo
17{
18 int ai_flags;
19 int ai_family;
20 int ai_socktype;
21 int ai_protocol;
22 socklen_t ai_addrlen;
23 struct sockaddr *ai_addr;
24 char *ai_canonname;
25 struct addrinfo *ai_next;
26};
27
28#define IPPORT_RESERVED 1024
29
30#define AI_PASSIVE 0x01
31#define AI_CANONNAME 0x02
32#define AI_NUMERICHOST 0x04
33#define AI_V4MAPPED 0x08
34#define AI_ALL 0x10
35#define AI_ADDRCONFIG 0x20
36#define AI_NUMERICSERV 0x400
37
38
39#define NI_NUMERICHOST 0x01
40#define NI_NUMERICSERV 0x02
41#define NI_NOFQDN 0x04
42#define NI_NAMEREQD 0x08
43#define NI_DGRAM 0x10
44/*#define NI_NUMERICSCOPE */
45
Rich Felker0b44a032011-02-12 00:22:29 -050046#define EAI_BADFLAGS -1
47#define EAI_NONAME -2
48#define EAI_AGAIN -3
49#define EAI_FAIL -4
50#define EAI_FAMILY -6
51#define EAI_SOCKTYPE -7
52#define EAI_SERVICE -8
53#define EAI_MEMORY -10
54#define EAI_SYSTEM -11
55#define EAI_OVERFLOW -12
56
Rich Felker400c5e52012-09-06 22:44:55 -040057int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -050058void freeaddrinfo (struct addrinfo *);
Rich Felker400c5e52012-09-06 22:44:55 -040059int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int);
Rich Felker0b44a032011-02-12 00:22:29 -050060const char *gai_strerror(int);
61
62
63/* Legacy functions follow (marked OBsolete in SUS) */
64
65struct netent
66{
67 char *n_name;
68 char **n_aliases;
69 int n_addrtype;
70 uint32_t n_net;
71};
72
73struct hostent
74{
75 char *h_name;
76 char **h_aliases;
77 int h_addrtype;
78 int h_length;
79 char **h_addr_list;
80};
81#define h_addr h_addr_list[0]
82
83struct servent
84{
85 char *s_name;
86 char **s_aliases;
87 int s_port;
88 char *s_proto;
89};
90
91struct protoent
92{
93 char *p_name;
94 char **p_aliases;
95 int p_proto;
96};
97
Rich Felker0b44a032011-02-12 00:22:29 -050098void sethostent (int);
99void endhostent (void);
100struct hostent *gethostent (void);
Rich Felker0b44a032011-02-12 00:22:29 -0500101
102void setnetent (int);
103void endnetent (void);
104struct netent *getnetent (void);
105struct netent *getnetbyaddr (uint32_t, int);
106struct netent *getnetbyname (const char *);
107
108void setservent (int);
109void endservent (void);
110struct servent *getservent (void);
111struct servent *getservbyname (const char *, const char *);
112struct servent *getservbyport (int, const char *);
113
114void setprotoent (int);
115void endprotoent (void);
116struct protoent *getprotoent (void);
117struct protoent *getprotobyname (const char *);
118struct protoent *getprotobynumber (int);
119
Rich Felker3f80afc2012-08-15 15:35:32 -0400120#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
Rich Felkerb367ab12012-11-01 03:49:43 -0400121 || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
122 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
Rich Felker3777f5b2012-05-12 23:38:04 -0400123struct hostent *gethostbyname (const char *);
Rich Felker3777f5b2012-05-12 23:38:04 -0400124struct hostent *gethostbyaddr (const void *, socklen_t, int);
Rich Felkere68c51a2012-05-12 23:45:07 -0400125#ifdef __GNUC__
126__attribute__((const))
127#endif
128int *__h_errno_location(void);
129#define h_errno (*__h_errno_location())
Rich Felker3f80afc2012-08-15 15:35:32 -0400130#define HOST_NOT_FOUND 1
131#define TRY_AGAIN 2
132#define NO_RECOVERY 3
133#define NO_DATA 4
134#endif
135
136#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
137const char *hstrerror(int);
138int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
139int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
140struct hostent *gethostbyname2(const char *, int);
141int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
142int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
143int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
Rich Felker7db6a872012-05-12 23:31:52 -0400144#define EAI_NODATA -5
145#define EAI_ADDRFAMILY -9
146#define EAI_INPROGRESS -100
147#define EAI_CANCELED -101
148#define EAI_NOTCANCELED -102
149#define EAI_ALLDONE -103
150#define EAI_INTR -104
151#define EAI_IDN_ENCODE -105
Rich Felker20052b92012-05-12 23:34:39 -0400152#define NI_MAXHOST 255
153#define NI_MAXSERV 32
Rich Felker0b44a032011-02-12 00:22:29 -0500154#endif
155
156
157#ifdef __cplusplus
158}
159#endif
160
161#endif