2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file include/gnunet_dnsstub_lib.h
23 * @brief API for helper library to send DNS requests to DNS resolver
24 * @author Christian Grothoff
26 #ifndef GNUNET_DNSSTUB_LIB_H
27 #define GNUNET_DNSSTUB_LIB_H
29 #include "gnunet_common.h"
30 #include "gnunet_tun_lib.h"
33 * Opaque handle to the stub resolver.
35 struct GNUNET_DNSSTUB_Context;
38 * Opaque handle to a socket doing UDP requests.
40 struct GNUNET_DNSSTUB_RequestSocket;
44 * Start a DNS stub resolver.
46 * @param dns_ip target IP address to use
47 * @return NULL on error
49 struct GNUNET_DNSSTUB_Context *
50 GNUNET_DNSSTUB_start (const char *dns_ip);
54 * Cleanup DNSSTUB resolver.
56 * @param ctx stub resolver to clean up
59 GNUNET_DNSSTUB_stop (struct GNUNET_DNSSTUB_Context *ctx);
63 * Function called with the result of a DNS resolution.
66 * @param rs socket that received the response
67 * @param dns dns response, never NULL
68 * @param dns_len number of bytes in 'dns'
70 typedef void (*GNUNET_DNSSTUB_ResultCallback)(void *cls,
71 struct GNUNET_DNSSTUB_RequestSocket *rs,
72 const struct GNUNET_TUN_DnsHeader *dns,
77 * Perform DNS resolution using given address.
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
88 struct GNUNET_DNSSTUB_RequestSocket *
89 GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx,
90 const struct sockaddr *sa,
94 GNUNET_DNSSTUB_ResultCallback rc,
99 * Perform DNS resolution using our default IP from init.
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
108 struct GNUNET_DNSSTUB_RequestSocket *
109 GNUNET_DNSSTUB_resolve2 (struct GNUNET_DNSSTUB_Context *ctx,
112 GNUNET_DNSSTUB_ResultCallback rc,
117 * Cancel DNS resolution.
119 * @param rs resolution to cancel
122 GNUNET_DNSSTUB_resolve_cancel (struct GNUNET_DNSSTUB_RequestSocket *rs);