f24bf5c5e83f140a94e843f4b1d08dd516a1bf66
[oweals/gnunet.git] / src / include / gnunet_resolver_service.h
1 /*
2      This file is part of GNUnet.
3      (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 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 2, 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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file include/gnunet_resolver_service.h
23  * @brief functions related to doing DNS lookups
24  * @author Christian Grothoff
25  */
26
27 #ifndef GNUNET_RESOLVER_SERVICE_H
28 #define GNUNET_RESOLVER_SERVICE_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "gnunet_configuration_lib.h"
39 #include "gnunet_scheduler_lib.h"
40 #include "gnunet_time_lib.h"
41
42
43 /**
44  * Function called by the resolver for each address obtained from DNS.
45  *
46  * @param cls closure
47  * @param addr one of the addresses of the host, NULL for the last address
48  * @param addrlen length of the address
49  */
50 typedef void (*GNUNET_RESOLVER_AddressCallback) (void *cls,
51                                                  const struct sockaddr * addr,
52                                                  socklen_t addrlen);
53
54
55 /**
56  * Handle to a request given to the resolver.  Can be used to cancel
57  * the request prior to the timeout or successful execution.
58  */
59 struct GNUNET_RESOLVER_RequestHandle;
60
61 /**
62  * Create the connection to the resolver service.
63  *
64  * @param cfg configuration to use
65  */
66 void GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *c);
67
68
69 /**
70  * Destroy the connection to the resolver service.
71  */
72 void GNUNET_RESOLVER_disconnect (void);
73
74
75 /**
76  * Convert a string to one or more IP addresses.
77  *
78  * @param hostname the hostname to resolve
79  * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
80  * @param callback function to call with addresses
81  * @param callback_cls closure for callback
82  * @param timeout how long to try resolving
83  * @return handle that can be used to cancel the request, NULL on error
84  */
85 struct GNUNET_RESOLVER_RequestHandle *GNUNET_RESOLVER_ip_get (const char
86                                                               *hostname,
87                                                               int domain,
88                                                               struct
89                                                               GNUNET_TIME_Relative
90                                                               timeout,
91                                                               GNUNET_RESOLVER_AddressCallback
92                                                               callback,
93                                                               void
94                                                               *callback_cls);
95
96
97 /**
98  * Resolve our hostname to an IP address.
99  *
100  * @param cfg configuration to use
101  * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
102  * @param callback function to call with addresses
103  * @param cls closure for 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 *GNUNET_RESOLVER_hostname_resolve (int
108                                                                         domain,
109                                                                         struct
110                                                                         GNUNET_TIME_Relative
111                                                                         timeout,
112                                                                         GNUNET_RESOLVER_AddressCallback
113                                                                         callback,
114                                                                         void
115                                                                         *cls);
116
117
118 /**
119  * Function called by the resolver for each hostname obtained from DNS.
120  *
121  * @param cls closure
122  * @param hostname one of the names for the host, NULL
123  *        on the last call to the callback
124  */
125 typedef void (*GNUNET_RESOLVER_HostnameCallback) (void *cls,
126                                                   const char *hostname);
127
128 /**
129  * Get local fully qualified domain name
130  *
131  * @return local hostname, caller must free
132  */
133 char *GNUNET_RESOLVER_local_fqdn_get (void);
134
135
136 /**
137  * Perform a reverse DNS lookup.
138  *
139  * @param cfg configuration to use
140  * @param sa host address
141  * @param salen length of host address
142  * @param do_resolve use GNUNET_NO to return numeric hostname
143  * @param timeout how long to try resolving
144  * @param callback function to call with hostnames
145  * @param cls closure for callback
146  * @return handle that can be used to cancel the request, NULL on error
147  */
148 struct GNUNET_RESOLVER_RequestHandle *GNUNET_RESOLVER_hostname_get (const struct
149                                                                     sockaddr
150                                                                     *sa,
151                                                                     socklen_t
152                                                                     salen,
153                                                                     int
154                                                                     do_resolve,
155                                                                     struct
156                                                                     GNUNET_TIME_Relative
157                                                                     timeout,
158                                                                     GNUNET_RESOLVER_HostnameCallback
159                                                                     callback,
160                                                                     void *cls);
161
162
163 /**
164  * Cancel a request that is still pending with the resolver.
165  * Note that a client MUST NOT cancel a request that has
166  * been completed (i.e, the callback has been called to
167  * signal timeout or the final result).
168  *
169  * @param rh handle of request to cancel
170  */
171 void GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh);
172
173
174 #if 0                           /* keep Emacsens' auto-indent happy */
175 {
176 #endif
177 #ifdef __cplusplus
178 }
179 #endif
180
181 /* ifndef GNUNET_RESOLVER_SERVICE_H */
182 #endif
183 /* end of gnunet_resolver_service.h */