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