SET service: accurate results for symmetric mode
[oweals/gnunet.git] / src / include / gnunet_dnsstub_lib.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012 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_dnsstub_lib.h
23  * @brief API for helper library to send DNS requests to DNS resolver
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_DNSSTUB_LIB_H
27 #define GNUNET_DNSSTUB_LIB_H
28
29 #include "gnunet_common.h"
30 #include "gnunet_tun_lib.h"
31
32 /**
33  * Opaque handle to the stub resolver.
34  */
35 struct GNUNET_DNSSTUB_Context;
36
37 /**
38  * Opaque handle to a socket doing UDP requests.
39  */
40 struct GNUNET_DNSSTUB_RequestSocket;
41
42
43 /**
44  * Start a DNS stub resolver.
45  *
46  * @param dns_ip target IP address to use
47  * @return NULL on error
48  */
49 struct GNUNET_DNSSTUB_Context *
50 GNUNET_DNSSTUB_start (const char *dns_ip);
51
52
53 /**
54  * Cleanup DNSSTUB resolver.
55  *
56  * @param ctx stub resolver to clean up
57  */
58 void
59 GNUNET_DNSSTUB_stop (struct GNUNET_DNSSTUB_Context *ctx);
60
61
62 /**
63  * Function called with the result of a DNS resolution.
64  *
65  * @param cls closure
66  * @param rs socket that received the response
67  * @param dns dns response, never NULL
68  * @param dns_len number of bytes in 'dns'
69  */
70 typedef void (*GNUNET_DNSSTUB_ResultCallback)(void *cls,
71                                               struct GNUNET_DNSSTUB_RequestSocket *rs,
72                                               const struct GNUNET_TUN_DnsHeader *dns,
73                                               size_t dns_len);
74
75
76 /**
77  * Perform DNS resolution using given address.
78  *
79  * @param ctx stub resolver to use
80  * @param sa the socket address
81  * @param sa_len the socket length
82  * @param request DNS request to transmit
83  * @param request_len number of bytes in msg
84  * @param rc function to call with result
85  * @param rc_cls closure for 'rc'
86  * @return socket used for the request, NULL on error
87  */
88 struct GNUNET_DNSSTUB_RequestSocket *
89 GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx,
90                         const struct sockaddr *sa,
91                         socklen_t sa_len,
92                         const void *request,
93                         size_t request_len,
94                         GNUNET_DNSSTUB_ResultCallback rc,
95                         void *rc_cls);
96
97
98 /**
99  * Perform DNS resolution using our default IP from init.
100  *
101  * @param ctx stub resolver to use
102  * @param request DNS request to transmit
103  * @param request_len number of bytes in msg
104  * @param rc function to call with result
105  * @param rc_cls closure for 'rc'
106  * @return socket used for the request, NULL on error
107  */
108 struct GNUNET_DNSSTUB_RequestSocket *
109 GNUNET_DNSSTUB_resolve2 (struct GNUNET_DNSSTUB_Context *ctx,
110                          const void *request,
111                          size_t request_len,
112                          GNUNET_DNSSTUB_ResultCallback rc,
113                          void *rc_cls);
114
115
116 /**
117  * Cancel DNS resolution.
118  *
119  * @param rs resolution to cancel
120  */
121 void
122 GNUNET_DNSSTUB_resolve_cancel (struct GNUNET_DNSSTUB_RequestSocket *rs);
123
124 #endif