gnunet_resolver_service.h 5.1 KB

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