SET service: accurate results for symmetric mode
[oweals/gnunet.git] / src / include / gnunet_resolver_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001-2013 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @file include/gnunet_resolver_service.h
23  * @brief functions related to doing DNS lookups
24  * @author Christian Grothoff
25  * @defgroup resolver asynchronous standard DNS lookups
26  * @{
27  */
28
29 #ifndef GNUNET_RESOLVER_SERVICE_H
30 #define GNUNET_RESOLVER_SERVICE_H
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 #include "gnunet_configuration_lib.h"
41 #include "gnunet_scheduler_lib.h"
42 #include "gnunet_time_lib.h"
43
44
45 /**
46  * Function called by the resolver for each address obtained from DNS.
47  *
48  * @param cls closure
49  * @param addr one of the addresses of the host, NULL for the last address
50  * @param addrlen length of @a addr
51  */
52 typedef void
53 (*GNUNET_RESOLVER_AddressCallback) (void *cls,
54                                     const struct sockaddr *addr,
55                                     socklen_t addrlen);
56
57
58 /**
59  * Handle to a request given to the resolver.  Can be used to cancel
60  * the request prior to the timeout or successful execution.
61  */
62 struct GNUNET_RESOLVER_RequestHandle;
63
64 /**
65  * Create the connection to the resolver service.
66  *
67  * @param cfg configuration to use
68  */
69 void
70 GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
71
72
73 /**
74  * Destroy the connection to the resolver service.
75  */
76 void
77 GNUNET_RESOLVER_disconnect (void);
78
79
80 /**
81  * Convert a string to one or more IP addresses.
82  *
83  * @param hostname the hostname to resolve
84  * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any"
85  * @param callback function to call with addresses
86  * @param callback_cls closure for @a callback
87  * @param timeout how long to try resolving
88  * @return handle that can be used to cancel the request, NULL on error
89  */
90 struct GNUNET_RESOLVER_RequestHandle *
91 GNUNET_RESOLVER_ip_get (const char *hostname,
92                         int af,
93                         struct GNUNET_TIME_Relative timeout,
94                         GNUNET_RESOLVER_AddressCallback callback,
95                         void *callback_cls);
96
97
98 /**
99  * Resolve our hostname to an IP address.
100  *
101  * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any"
102  * @param callback function to call with addresses
103  * @param cls closure for @a callback
104  * @param timeout how long to try resolving
105  * @return handle that can be used to cancel the request, NULL on error
106  */
107 struct GNUNET_RESOLVER_RequestHandle *
108 GNUNET_RESOLVER_hostname_resolve (int af,
109                                   struct GNUNET_TIME_Relative timeout,
110                                   GNUNET_RESOLVER_AddressCallback callback,
111                                   void *cls);
112
113
114 /**
115  * Function called by the resolver for each hostname obtained from DNS.
116  *
117  * @param cls closure
118  * @param hostname one of the names for the host, NULL
119  *        on the last call to the callback
120  */
121 typedef void
122 (*GNUNET_RESOLVER_HostnameCallback) (void *cls,
123                                      const char *hostname);
124
125 /**
126  * Get local fully qualified domain name
127  *
128  * @return local hostname, caller must free
129  */
130 char *
131 GNUNET_RESOLVER_local_fqdn_get (void);
132
133
134 /**
135  * Perform a reverse DNS lookup.
136  *
137  * @param sa host address
138  * @param salen length of @a sa
139  * @param do_resolve use #GNUNET_NO to return numeric hostname
140  * @param timeout how long to try resolving
141  * @param callback function to call with hostnames
142  * @param cls closure for @a callback
143  * @return handle that can be used to cancel the request, NULL on error
144  */
145 struct GNUNET_RESOLVER_RequestHandle *
146 GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa,
147                               socklen_t salen,
148                               int do_resolve,
149                               struct GNUNET_TIME_Relative timeout,
150                               GNUNET_RESOLVER_HostnameCallback callback,
151                               void *cls);
152
153
154 /**
155  * Cancel a request that is still pending with the resolver.
156  * Note that a client MUST NOT cancel a request that has
157  * been completed (i.e, the callback has been called to
158  * signal timeout or the final result).
159  *
160  * @param rh handle of request to cancel
161  */
162 void
163 GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh);
164
165
166 #if 0                           /* keep Emacsens' auto-indent happy */
167 {
168 #endif
169 #ifdef __cplusplus
170 }
171 #endif
172
173 /** @} */ /* end of group resolver */
174
175 /* ifndef GNUNET_RESOLVER_SERVICE_H */
176 #endif
177 /* end of gnunet_resolver_service.h */