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