ares_parse_caa_reply.3 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. .\"
  2. .\" Copyright 2020 Danny Sonnenschein <[email protected]>
  3. .\"
  4. .\" Permission to use, copy, modify, and distribute this
  5. .\" software and its documentation for any purpose and without
  6. .\" fee is hereby granted, provided that the above copyright
  7. .\" notice appear in all copies and that both that copyright
  8. .\" notice and this permission notice appear in supporting
  9. .\" documentation, and that the name of M.I.T. not be used in
  10. .\" advertising or publicity pertaining to distribution of the
  11. .\" software without specific, written prior permission.
  12. .\" M.I.T. makes no representations about the suitability of
  13. .\" this software for any purpose. It is provided "as is"
  14. .\" without express or implied warranty.
  15. .\"
  16. .TH ARES_PARSE_CAA_REPLY 3 "16 September 2020"
  17. .SH NAME
  18. ares_parse_caa_reply \- Parse a reply to a DNS query of type CAA
  19. .SH SYNOPSIS
  20. .nf
  21. #include <ares.h>
  22. int ares_parse_caa_reply(const unsigned char* \fIabuf\fP, int \fIalen\fP,
  23. struct ares_caa_reply **\fIcaa_out\fP);
  24. .fi
  25. .SH DESCRIPTION
  26. The
  27. .BR "ares_parse_caa_reply"
  28. function parses the response to a query of type CAA into a
  29. linked list (one element per sub-string) of
  30. .IR "struct ares_caa_reply"
  31. The parameters
  32. .I abuf
  33. and
  34. .I alen
  35. give the contents of the response. The result is stored in allocated
  36. memory and a pointer to it stored into the variable pointed to by
  37. .IR caa_out .
  38. It is the caller's responsibility to free the resulting
  39. .IR caa_out
  40. structure when it is no longer needed using the function
  41. .B ares_free_data(3)
  42. .PP
  43. The structure
  44. .I ares_caa_reply(3)
  45. contains the following fields:
  46. .sp
  47. .in +4n
  48. .nf
  49. struct ares_caa_reply {
  50. struct ares_caa_reply *next;
  51. int critical;
  52. unsigned char *property;
  53. size_t plength; /* plength excludes null */
  54. unsigned char *value;
  55. size_t length; /* length excludes null */
  56. };
  57. .fi
  58. .in
  59. .PP
  60. .SH RETURN VALUES
  61. .BR "ares_parse_caa_reply"
  62. can return any of the following values:
  63. .TP 15
  64. .B ARES_SUCCESS
  65. The response was successfully parsed.
  66. .TP 15
  67. .B ARES_EBADRESP
  68. The response was malformatted.
  69. .TP 15
  70. .B ARES_ENODATA
  71. The response did not contain an answer to the query.
  72. .TP 15
  73. .B ARES_ENOMEM
  74. Memory was exhausted.
  75. .SH EXAMPLE
  76. .nf
  77. #include <arpa/inet.h>
  78. #include <time.h>
  79. #include <sys/time.h>
  80. #include <netdb.h>
  81. #include <unistd.h>
  82. #include <stdio.h>
  83. #include <stdlib.h>
  84. #include "ares.h"
  85. static void dns_callback(void *arg,
  86. int status,
  87. int timeouts,
  88. unsigned char *abuf,
  89. int alen)
  90. {
  91. struct ares_caa_reply *caa_out;
  92. int err;
  93. err = ares_parse_caa_reply (abuf, alen, &caa_out);
  94. if (err == ARES_SUCCESS)
  95. {
  96. struct ares_caa_reply *caa_curr;
  97. for (caa_curr=caa_out; caa_curr; caa_curr=caa_curr->next)
  98. printf ("%s. CAA %i %s \\"%s\\"\\n", arg,
  99. caa_curr->critical,
  100. caa_curr->property,
  101. caa_curr->value);
  102. }
  103. else
  104. {
  105. printf ("err=%i\\n", err);
  106. }
  107. ares_free_data (caa_out);
  108. }
  109. static void main_loop(ares_channel *channel)
  110. {
  111. int nfds, count;
  112. fd_set readers, writers;
  113. struct timeval tv, *tvp;
  114. while (1)
  115. {
  116. FD_ZERO (&readers);
  117. FD_ZERO (&writers);
  118. nfds = ares_fds (*channel, &readers, &writers);
  119. if (nfds == 0)
  120. break;
  121. tvp = ares_timeout (*channel, NULL, &tv);
  122. count = select (nfds, &readers, &writers, NULL, tvp);
  123. ares_process (*channel, &readers, &writers);
  124. }
  125. }
  126. int main(int argc, char **argv)
  127. {
  128. const char *sversion;
  129. int iversion;
  130. int err;
  131. sversion = ares_version (&iversion);
  132. printf ("c-ares version %s\\n", sversion);
  133. char *domain = "wikipedia.org";
  134. if (argc > 1)
  135. domain = argv[1];
  136. ares_channel channel;
  137. if ((err = ares_init (&channel)) != ARES_SUCCESS)
  138. {
  139. printf ("ares_init() failed (%i)\\n", err);
  140. exit (EXIT_FAILURE);
  141. }
  142. ares_query (channel, domain,
  143. 1, /* ns_c_in */
  144. 257, /* T_CAA */
  145. dns_callback, domain);
  146. main_loop (&channel);
  147. ares_destroy (channel);
  148. exit (EXIT_SUCCESS);
  149. }
  150. .fi
  151. .SH AVAILABILITY
  152. This function was first introduced in c-ares version 1.17.0.
  153. .SH SEE ALSO
  154. .BR ares_query (3)
  155. .BR ares_free_data (3)
  156. .SH AUTHOR
  157. Written by Danny Sonnenschein <[email protected]>, on behalf of platynum, https://platynum.ch