3 /* Copyright 1998 by the Massachusetts Institute of Technology.
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for any purpose and without
7 * fee is hereby granted, provided that the above copyright
8 * notice appear in all copies and that both that copyright
9 * notice and this permission notice appear in supporting
10 * documentation, and that the name of M.I.T. not be used in
11 * advertising or publicity pertaining to distribution of the
12 * software without specific, written prior permission.
13 * M.I.T. makes no representations about the suitability of
14 * this software for any purpose. It is provided "as is"
15 * without express or implied warranty.
21 #include <sys/types.h>
24 /* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
25 libc5-based Linux systems. Only include it on system that are known to
27 #include <sys/select.h>
34 #include <netinet/in.h>
37 #define ARES_SUCCESS 0
39 /* Server error codes (ARES_ENODATA indicates no relevant answer) */
40 #define ARES_ENODATA 1
41 #define ARES_EFORMERR 2
42 #define ARES_ESERVFAIL 3
43 #define ARES_ENOTFOUND 4
44 #define ARES_ENOTIMP 5
45 #define ARES_EREFUSED 6
47 /* Locally generated error codes */
48 #define ARES_EBADQUERY 7
49 #define ARES_EBADNAME 8
50 #define ARES_EBADFAMILY 9
51 #define ARES_EBADRESP 10
52 #define ARES_ECONNREFUSED 11
53 #define ARES_ETIMEOUT 12
56 #define ARES_ENOMEM 15
57 #define ARES_EDESTRUCTION 16
58 #define ARES_EBADSTR 17
61 #define ARES_FLAG_USEVC (1 << 0)
62 #define ARES_FLAG_PRIMARY (1 << 1)
63 #define ARES_FLAG_IGNTC (1 << 2)
64 #define ARES_FLAG_NORECURSE (1 << 3)
65 #define ARES_FLAG_STAYOPEN (1 << 4)
66 #define ARES_FLAG_NOSEARCH (1 << 5)
67 #define ARES_FLAG_NOALIASES (1 << 6)
68 #define ARES_FLAG_NOCHECKRESP (1 << 7)
70 /* Option mask values */
71 #define ARES_OPT_FLAGS (1 << 0)
72 #define ARES_OPT_TIMEOUT (1 << 1)
73 #define ARES_OPT_TRIES (1 << 2)
74 #define ARES_OPT_NDOTS (1 << 3)
75 #define ARES_OPT_UDP_PORT (1 << 4)
76 #define ARES_OPT_TCP_PORT (1 << 5)
77 #define ARES_OPT_SERVERS (1 << 6)
78 #define ARES_OPT_DOMAINS (1 << 7)
79 #define ARES_OPT_LOOKUPS (1 << 8)
86 unsigned short udp_port;
87 unsigned short tcp_port;
88 struct in_addr *servers;
97 struct ares_channeldata;
98 typedef struct ares_channeldata *ares_channel;
99 typedef void (*ares_callback)(void *arg, int status, unsigned char *abuf,
101 typedef void (*ares_host_callback)(void *arg, int status,
102 struct hostent *hostent);
104 int ares_init(ares_channel *channelptr);
105 int ares_init_options(ares_channel *channelptr, struct ares_options *options,
107 void ares_destroy(ares_channel channel);
108 void ares_cancel(ares_channel channel);
109 void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
110 ares_callback callback, void *arg);
111 void ares_query(ares_channel channel, const char *name, int dnsclass,
112 int type, ares_callback callback, void *arg);
113 void ares_search(ares_channel channel, const char *name, int dnsclass,
114 int type, ares_callback callback, void *arg);
115 void ares_gethostbyname(ares_channel channel, const char *name, int family,
116 ares_host_callback callback, void *arg);
117 void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
118 int family, ares_host_callback callback, void *arg);
120 int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
121 struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
123 void ares_process(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
125 int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id,
126 int rd, unsigned char **buf, int *buflen);
127 int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
128 int alen, char **s, long *enclen);
129 int ares_expand_string(const unsigned char *encoded, const unsigned char *abuf,
130 int alen, unsigned char **s, long *enclen);
131 int ares_parse_a_reply(const unsigned char *abuf, int alen,
132 struct hostent **host);
133 int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
134 int addrlen, int family, struct hostent **host);
135 void ares_free_string(void *str);
136 void ares_free_hostent(struct hostent *host);
137 const char *ares_strerror(int code);
138 void ares_free_errmem(char *mem);