gnunet_resolver_service.h 5.1 KB

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