Merge branch 'develop' of https://github.com/verisign/getdns into develop

This commit is contained in:
Glen Wiley 2013-12-12 07:45:27 -05:00
commit 46b584117a
30 changed files with 1452 additions and 1024 deletions

View File

@ -20,37 +20,57 @@ void this_callbackfn(struct getdns_context *this_context,
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) /* This is a callback with data */
{
/* Be sure the search returned something */
uint32_t * this_error = NULL;
this_ret = getdns_dict_get_int(this_response, "status", this_error); // Ignore any error
if (*this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
uint32_t this_error;
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", *this_error);
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.\n", this_error);
getdns_dict_destroy(this_response);
return;
}
struct getdns_list * just_the_addresses_ptr;
this_ret = getdns_dict_get_list(this_response, "just_address_answers", &just_the_addresses_ptr);
if (this_ret != GETDNS_RETURN_GOOD) // This check is really not needed, but prevents a compiler error under "pedantic"
struct getdns_list *replies_tree;
this_ret = getdns_dict_get_list(this_response, "replies_tree", &replies_tree); // Ignore any error
size_t num_replies;
this_ret = getdns_list_get_length(replies_tree, &num_replies); // Ignore any error
/* Go through each reply */
for ( size_t reply_count = 0; reply_count < num_replies; ++reply_count)
{
fprintf(stderr, "Trying to get the answers failed: %d", this_ret);
return;
}
size_t * num_addresses_ptr = NULL;
this_ret = getdns_list_get_length(just_the_addresses_ptr, num_addresses_ptr); // Ignore any error
/* Go through each record */
for ( size_t rec_count = 0; rec_count <= *num_addresses_ptr; ++rec_count )
{
struct getdns_dict * this_address;
this_ret = getdns_list_get_dict(just_the_addresses_ptr, rec_count, &this_address); // Ignore any error
struct getdns_dict * this_reply;
this_ret = getdns_list_get_dict(replies_tree, reply_count, &this_reply); // Ignore any error
/* Just print the address */
struct getdns_bindata * this_address_data;
this_ret = getdns_dict_get_bindata(this_address, "address_data", &this_address_data); // Ignore any error
printf("The address is %s", getdns_display_ip_address(this_address_data));
struct getdns_list* reply_answers;
this_ret = getdns_dict_get_list(this_reply, "answer", &reply_answers); // Ignore any error
size_t num_answers;
this_ret = getdns_list_get_length(reply_answers, &num_answers); // Ignore any error
/* Go through each answer */
for ( size_t answer_count = 0; answer_count < num_answers; ++answer_count)
{
struct getdns_dict * this_rr;
this_ret = getdns_list_get_dict(reply_answers, answer_count, &this_rr);
/* Get the RDATA type */
uint32_t this_type;
this_ret = getdns_dict_get_int(this_rr, "type", &this_type); // Ignore any error
if (this_type == GETDNS_RRTYPE_PTR)
{
struct getdns_dict *this_rdata;
this_ret = getdns_dict_get_dict(this_rr, "rdata", &this_rdata); // Ignore any error
struct getdns_bindata * this_dname;
this_ret = getdns_dict_get_bindata(this_rdata, "rdata_raw", &this_dname);
char *this_dname_str = getdns_convert_dns_name_to_fqdn(this_dname->data);
printf("The dname is %s\n", this_dname_str);
free(this_dname_str);
}
}
}
}
else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.", this_transaction_id);
else
fprintf(stderr, "The callback got a callback_type of %d. Exiting.", this_callback_type);
getdns_dict_destroy(this_response);
}
int main()
@ -69,16 +89,18 @@ int main()
if (this_event_base == NULL)
{
fprintf(stderr, "Trying to create the event base failed.");
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
(void)getdns_extension_set_libevent_base(this_context, this_event_base);
/* Set up the getdns call */
struct getdns_dict * this_addr_to_look_up = getdns_dict_create();
// TODO: check the return value above
struct getdns_bindata * this_type = { 4, 0x49507634 };
getdns_return_t this_ret = getdns_dict_set_bindata(this_addr_to_look_up, "address_type", this_type);
struct getdns_bindata * this_ipv4_addr = { 4, 0x08080808 };
this_ret = getdns_dict_set_bindata(this_addr_to_look_up, "address_data", this_ipv4_addr;
struct getdns_bindata this_type = { 5, (void *)"IPv4" };
getdns_return_t this_ret = getdns_dict_set_bindata(this_addr_to_look_up, "address_type", &this_type);
UNUSED_PARAM(this_ret);
struct getdns_bindata this_ipv4_addr = { 4, (void *)"\x08\x08\x08\x08" };
this_ret = getdns_dict_set_bindata(this_addr_to_look_up, "address_data", &this_ipv4_addr);
char* this_userarg = "somestring"; // Could add things here to help identify this call
getdns_transaction_t this_transaction_id = 0;
@ -87,7 +109,13 @@ int main()
NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
fprintf(stderr, "A bad IP address was used: %s. Exiting.", this_ipv4_addr);
char *ip_address_str = getdns_display_ip_address(&this_ipv4_addr);
fprintf(stderr, "A bad IP address was used: %s. Exiting.\n", ip_address_str);
free(ip_address_str);
getdns_dict_destroy(this_addr_to_look_up);
event_base_free(this_event_base);
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
@ -99,6 +127,7 @@ int main()
}
/* Clean up */
getdns_dict_destroy(this_addr_to_look_up);
event_base_free(this_event_base);
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);

View File

@ -20,37 +20,42 @@ void this_callbackfn(struct getdns_context *this_context,
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) /* This is a callback with data */
{
/* Be sure the search returned something */
uint32_t * this_error = NULL;
this_ret = getdns_dict_get_int(this_response, "status", this_error); // Ignore any error
if (*this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
uint32_t this_error;
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", *this_error);
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.\n", this_error);
getdns_dict_destroy(this_response);
return;
}
struct getdns_list * just_the_addresses_ptr;
this_ret = getdns_dict_get_list(this_response, "just_address_answers", &just_the_addresses_ptr);
if (this_ret != GETDNS_RETURN_GOOD) // This check is really not needed, but prevents a compiler error under "pedantic"
{
fprintf(stderr, "Trying to get the answers failed: %d", this_ret);
fprintf(stderr, "Trying to get the answers failed: %d\n", this_ret);
getdns_dict_destroy(this_response);
return;
}
size_t * num_addresses_ptr = NULL;
this_ret = getdns_list_get_length(just_the_addresses_ptr, num_addresses_ptr); // Ignore any error
size_t num_addresses;
this_ret = getdns_list_get_length(just_the_addresses_ptr, &num_addresses); // Ignore any error
/* Go through each record */
for ( size_t rec_count = 0; rec_count <= *num_addresses_ptr; ++rec_count )
for ( size_t rec_count = 0; rec_count < num_addresses; ++rec_count )
{
struct getdns_dict * this_address;
this_ret = getdns_list_get_dict(just_the_addresses_ptr, rec_count, &this_address); // Ignore any error
/* Just print the address */
struct getdns_bindata * this_address_data;
this_ret = getdns_dict_get_bindata(this_address, "address_data", &this_address_data); // Ignore any error
printf("The address is %s", getdns_display_ip_address(this_address_data));
char *this_address_str = getdns_display_ip_address(this_address_data);
printf("The address is %s\n", this_address_str);
free(this_address_str);
}
}
else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.", this_transaction_id);
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.\n", this_transaction_id);
else
fprintf(stderr, "The callback got a callback_type of %d. Exiting.", this_callback_type);
fprintf(stderr, "The callback got a callback_type of %d. Exiting.\n", this_callback_type);
getdns_dict_destroy(this_response);
}
int main()
@ -68,7 +73,8 @@ int main()
this_event_base = event_base_new();
if (this_event_base == NULL)
{
fprintf(stderr, "Trying to create the event base failed.");
fprintf(stderr, "Trying to create the event base failed.\n");
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
(void)getdns_extension_set_libevent_base(this_context, this_event_base);
@ -82,7 +88,9 @@ int main()
NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name);
fprintf(stderr, "A bad domain name was used: %s. Exiting.\n", this_name);
event_base_free(this_event_base);
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
@ -93,6 +101,7 @@ int main()
// TODO: check the return value above
}
/* Clean up */
event_base_free(this_event_base);
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);

View File

@ -13,7 +13,7 @@ int main()
getdns_return_t context_create_return = getdns_context_create(&this_context, 1);
if (context_create_return != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to create the context failed: %d", context_create_return);
fprintf(stderr, "Trying to create the context failed: %d\n", context_create_return);
return(GETDNS_RETURN_GENERIC_ERROR);
}
/* Set up the getdns_sync_request call */
@ -24,7 +24,9 @@ int main()
this_ret = getdns_dict_set_int(this_extensions, "return_both_v4_and_v6", GETDNS_EXTENSION_TRUE);
if (this_ret != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to set an extension do both IPv4 and IPv6 failed: %d", this_ret);
fprintf(stderr, "Trying to set an extension do both IPv4 and IPv6 failed: %d\n", this_ret);
getdns_dict_destroy(this_extensions);
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
struct getdns_dict * this_response = NULL;
@ -34,37 +36,46 @@ int main()
this_extensions, &this_response);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name);
fprintf(stderr, "A bad domain name was used: %s. Exiting.\n", this_name);
getdns_dict_destroy(this_response);
getdns_dict_destroy(this_extensions);
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
{
/* Be sure the search returned something */
uint32_t * this_error = NULL;
this_ret = getdns_dict_get_int(this_response, "status", this_error); // Ignore any error
if (*this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
uint32_t this_error;
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", *this_error);
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.\n", this_error);
getdns_dict_destroy(this_response);
getdns_dict_destroy(this_extensions);
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
struct getdns_list * just_the_addresses_ptr;
this_ret = getdns_dict_get_list(this_response, "just_address_answers", &just_the_addresses_ptr); // Ignore any error
size_t * num_addresses_ptr = NULL;
this_ret = getdns_list_get_length(just_the_addresses_ptr, num_addresses_ptr); // Ignore any error
size_t num_addresses;
this_ret = getdns_list_get_length(just_the_addresses_ptr, &num_addresses); // Ignore any error
/* Go through each record */
for ( size_t rec_count = 0; rec_count <= *num_addresses_ptr; ++rec_count )
for ( size_t rec_count = 0; rec_count < num_addresses; ++rec_count )
{
struct getdns_dict * this_address;
this_ret = getdns_list_get_dict(just_the_addresses_ptr, rec_count, &this_address); // Ignore any error
/* Just print the address */
struct getdns_bindata * this_address_data;
this_ret = getdns_dict_get_bindata(this_address, "address_data", &this_address_data); // Ignore any error
printf("The address is %s", getdns_display_ip_address(this_address_data));
char *this_address_str = getdns_display_ip_address(this_address_data);
printf("The address is %s\n", this_address_str);
free(this_address_str);
}
}
/* Clean up */
getdns_context_destroy(this_context);
getdns_dict_destroy(this_response);
getdns_dict_destroy(this_extensions);
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
}

View File

@ -20,25 +20,27 @@ void this_callbackfn(struct getdns_context *this_context,
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) /* This is a callback with data */
{
/* Be sure the search returned something */
uint32_t * this_error = NULL;
this_ret = getdns_dict_get_int(this_response, "status", this_error); // Ignore any error
if (*this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
uint32_t this_error;
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", *this_error);
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.\n", this_error);
getdns_dict_destroy(this_response);
return;
}
/* Find all the answers returned */
struct getdns_list * these_answers;
this_ret = getdns_dict_get_list(this_response, "replies-tree", &these_answers);
this_ret = getdns_dict_get_list(this_response, "replies_tree", &these_answers);
if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME)
{
fprintf(stderr, "Weird: the response had no error, but also no replies-tree. Exiting.");
fprintf(stderr, "Weird: the response had no error, but also no replies_tree. Exiting.\n");
getdns_dict_destroy(this_response);
return;
}
size_t * num_answers_ptr = NULL;
this_ret = getdns_list_get_length(these_answers, num_answers_ptr);
size_t num_answers;
this_ret = getdns_list_get_length(these_answers, &num_answers);
/* Go through each answer */
for ( size_t rec_count = 0; rec_count <= *num_answers_ptr; ++rec_count )
for ( size_t rec_count = 0; rec_count < num_answers; ++rec_count )
{
struct getdns_dict * this_record;
this_ret = getdns_list_get_dict(these_answers, rec_count, &this_record); // Ignore any error
@ -46,50 +48,57 @@ void this_callbackfn(struct getdns_context *this_context,
struct getdns_list * this_answer;
this_ret = getdns_dict_get_list(this_record, "answer", &this_answer); // Ignore any error
/* Get each RR in the answer section */
size_t * num_rrs_ptr = NULL;
this_ret = getdns_list_get_length(this_answer, num_rrs_ptr);
for ( size_t rr_count = 0; rr_count <= *num_rrs_ptr; ++rr_count )
size_t num_rrs;
this_ret = getdns_list_get_length(this_answer, &num_rrs);
for ( size_t rr_count = 0; rr_count < num_rrs; ++rr_count )
{
struct getdns_dict * this_rr = NULL;
struct getdns_dict *this_rr = NULL;
this_ret = getdns_list_get_dict(this_answer, rr_count, &this_rr); // Ignore any error
/* Get the RDATA */
struct getdns_dict * this_rdata = NULL;
this_ret = getdns_dict_get_dict(this_rr, "rdata", &this_rdata); // Ignore any error
/* Get the RDATA type */
uint32_t * this_type = NULL;
this_ret = getdns_dict_get_int(this_rdata, "type", this_type); // Ignore any error
uint32_t this_type;
this_ret = getdns_dict_get_int(this_rr, "type", &this_type); // Ignore any error
/* If it is type A or AAAA, print the value */
if (*this_type == GETDNS_RRTYPE_A)
if (this_type == GETDNS_RRTYPE_A)
{
struct getdns_bindata * this_a_record = NULL;
this_ret = getdns_dict_get_bindata(this_rdata, "ipv4_address", &this_a_record);
if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME)
{
fprintf(stderr, "Weird: the A record at %d in record at %d had no address. Exiting.",
fprintf(stderr, "Weird: the A record at %d in record at %d had no address. Exiting.\n",
(int) rr_count, (int) rec_count);
getdns_dict_destroy(this_response);
return;
}
printf("The IPv4 address is %s", getdns_display_ip_address(this_a_record));
char *this_address_str = getdns_display_ip_address(this_a_record);
printf("The IPv4 address is %s\n", this_address_str);
free(this_address_str);
}
else if (*this_type == GETDNS_RRTYPE_AAAA)
else if (this_type == GETDNS_RRTYPE_AAAA)
{
struct getdns_bindata * this_aaaa_record = NULL;
this_ret = getdns_dict_get_bindata(this_rdata, "ipv6_address", &this_aaaa_record);
if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME)
{
fprintf(stderr, "Weird: the AAAA record at %d in record at %d had no address. Exiting.",
fprintf(stderr, "Weird: the AAAA record at %d in record at %d had no address. Exiting.\n",
(int) rr_count, (int) rec_count);
getdns_dict_destroy(this_response);
return;
}
printf("The IPv6 address is %s", getdns_display_ip_address(this_aaaa_record));
char *this_address_str = getdns_display_ip_address(this_aaaa_record);
printf("The IPv6 address is %s\n", this_address_str);
free(this_address_str);
}
}
}
}
else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.", this_transaction_id);
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.\n", this_transaction_id);
else
fprintf(stderr, "The callback got a callback_type of %d. Exiting.", this_callback_type);
fprintf(stderr, "The callback got a callback_type of %d. Exiting.\n", this_callback_type);
getdns_dict_destroy(this_response);
}
int main()
@ -99,7 +108,7 @@ int main()
getdns_return_t context_create_return = getdns_context_create(&this_context, 1);
if (context_create_return != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to create the context failed: %d", context_create_return);
fprintf(stderr, "Trying to create the context failed: %d\n", context_create_return);
return(GETDNS_RETURN_GENERIC_ERROR);
}
/* Create an event base and put it in the context using the unknown function name */
@ -107,7 +116,8 @@ int main()
this_event_base = event_base_new();
if (this_event_base == NULL)
{
fprintf(stderr, "Trying to create the event base failed.");
fprintf(stderr, "Trying to create the event base failed.\n");
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
(void)getdns_extension_set_libevent_base(this_context, this_event_base);
@ -121,7 +131,9 @@ int main()
NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name);
fprintf(stderr, "A bad domain name was used: %s. Exiting.\n", this_name);
event_base_free(this_event_base);
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
@ -132,6 +144,7 @@ int main()
// TODO: check the return value above
}
/* Clean up */
event_base_free(this_event_base);
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);

BIN
spec/getdns-0.371.tgz Normal file

Binary file not shown.

View File

@ -1,4 +1,4 @@
/* Created at 2013-12-06-16-00-32*/
/* Created at 2013-12-11-23-50-41*/
#ifndef GETDNS_H
#define GETDNS_H

View File

@ -1405,37 +1405,42 @@ function.</p>
<span class="k">if</span> <span class="p">(</span><span class="n">this_callback_type</span> <span class="o">==</span> <span class="n">GETDNS_CALLBACK_COMPLETE</span><span class="p">)</span> <span class="cm">/* This is a callback with data */</span>
<span class="p">{</span>
<span class="cm">/* Be sure the search returned something */</span>
<span class="kt">uint32_t</span> <span class="o">*</span> <span class="n">this_error</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_int</span><span class="p">(</span><span class="n">this_response</span><span class="p">,</span> <span class="s">&quot;status&quot;</span><span class="p">,</span> <span class="n">this_error</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="k">if</span> <span class="p">(</span><span class="o">*</span><span class="n">this_error</span> <span class="o">!=</span> <span class="n">GETDNS_RESPSTATUS_GOOD</span><span class="p">)</span> <span class="c1">// If the search didn&#39;t return &quot;good&quot;</span>
<span class="kt">uint32_t</span> <span class="n">this_error</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_int</span><span class="p">(</span><span class="n">this_response</span><span class="p">,</span> <span class="s">&quot;status&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_error</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="k">if</span> <span class="p">(</span><span class="n">this_error</span> <span class="o">!=</span> <span class="n">GETDNS_RESPSTATUS_GOOD</span><span class="p">)</span> <span class="c1">// If the search didn&#39;t return &quot;good&quot;</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The search had no results, and a return value of %d. Exiting.&quot;</span><span class="p">,</span> <span class="o">*</span><span class="n">this_error</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The search had no results, and a return value of %d. Exiting.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_error</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_response</span><span class="p">);</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">struct</span> <span class="n">getdns_list</span> <span class="o">*</span> <span class="n">just_the_addresses_ptr</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_list</span><span class="p">(</span><span class="n">this_response</span><span class="p">,</span> <span class="s">&quot;just_address_answers&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">just_the_addresses_ptr</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">this_ret</span> <span class="o">!=</span> <span class="n">GETDNS_RETURN_GOOD</span><span class="p">)</span> <span class="c1">// This check is really not needed, but prevents a compiler error under &quot;pedantic&quot;</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Trying to get the answers failed: %d&quot;</span><span class="p">,</span> <span class="n">this_ret</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Trying to get the answers failed: %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_ret</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_response</span><span class="p">);</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">size_t</span> <span class="o">*</span> <span class="n">num_addresses_ptr</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_list_get_length</span><span class="p">(</span><span class="n">just_the_addresses_ptr</span><span class="p">,</span> <span class="n">num_addresses_ptr</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="kt">size_t</span> <span class="n">num_addresses</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_list_get_length</span><span class="p">(</span><span class="n">just_the_addresses_ptr</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">num_addresses</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="cm">/* Go through each record */</span>
<span class="k">for</span> <span class="p">(</span> <span class="kt">size_t</span> <span class="n">rec_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">rec_count</span> <span class="o">&lt;=</span> <span class="o">*</span><span class="n">num_addresses_ptr</span><span class="p">;</span> <span class="o">++</span><span class="n">rec_count</span> <span class="p">)</span>
<span class="k">for</span> <span class="p">(</span> <span class="kt">size_t</span> <span class="n">rec_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">rec_count</span> <span class="o">&lt;</span> <span class="n">num_addresses</span><span class="p">;</span> <span class="o">++</span><span class="n">rec_count</span> <span class="p">)</span>
<span class="p">{</span>
<span class="k">struct</span> <span class="n">getdns_dict</span> <span class="o">*</span> <span class="n">this_address</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_list_get_dict</span><span class="p">(</span><span class="n">just_the_addresses_ptr</span><span class="p">,</span> <span class="n">rec_count</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_address</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="cm">/* Just print the address */</span>
<span class="k">struct</span> <span class="n">getdns_bindata</span> <span class="o">*</span> <span class="n">this_address_data</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_bindata</span><span class="p">(</span><span class="n">this_address</span><span class="p">,</span> <span class="s">&quot;address_data&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_address_data</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="n">printf</span><span class="p">(</span><span class="s">&quot;The address is %s&quot;</span><span class="p">,</span> <span class="n">getdns_display_ip_address</span><span class="p">(</span><span class="n">this_address_data</span><span class="p">));</span>
<span class="kt">char</span> <span class="o">*</span><span class="n">this_address_str</span> <span class="o">=</span> <span class="n">getdns_display_ip_address</span><span class="p">(</span><span class="n">this_address_data</span><span class="p">);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">&quot;The address is %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_address_str</span><span class="p">);</span>
<span class="n">free</span><span class="p">(</span><span class="n">this_address_str</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">this_callback_type</span> <span class="o">==</span> <span class="n">GETDNS_CALLBACK_CANCEL</span><span class="p">)</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The callback with ID %&quot;</span><span class="n">PRIu64</span><span class="s">&quot; was cancelled. Exiting.&quot;</span><span class="p">,</span> <span class="n">this_transaction_id</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The callback with ID %&quot;</span><span class="n">PRIu64</span><span class="s">&quot; was cancelled. Exiting.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_transaction_id</span><span class="p">);</span>
<span class="k">else</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The callback got a callback_type of %d. Exiting.&quot;</span><span class="p">,</span> <span class="n">this_callback_type</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The callback got a callback_type of %d. Exiting.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_callback_type</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_response</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
@ -1453,7 +1458,8 @@ function.</p>
<span class="n">this_event_base</span> <span class="o">=</span> <span class="n">event_base_new</span><span class="p">();</span>
<span class="k">if</span> <span class="p">(</span><span class="n">this_event_base</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Trying to create the event base failed.&quot;</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Trying to create the event base failed.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="n">getdns_context_destroy</span><span class="p">(</span><span class="n">this_context</span><span class="p">);</span>
<span class="k">return</span><span class="p">(</span><span class="n">GETDNS_RETURN_GENERIC_ERROR</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">getdns_extension_set_libevent_base</span><span class="p">(</span><span class="n">this_context</span><span class="p">,</span> <span class="n">this_event_base</span><span class="p">);</span>
@ -1467,7 +1473,9 @@ function.</p>
<span class="nb">NULL</span><span class="p">,</span> <span class="n">this_userarg</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_transaction_id</span><span class="p">,</span> <span class="n">this_callbackfn</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">dns_request_return</span> <span class="o">==</span> <span class="n">GETDNS_RETURN_BAD_DOMAIN_NAME</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;A bad domain name was used: %s. Exiting.&quot;</span><span class="p">,</span> <span class="n">this_name</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;A bad domain name was used: %s. Exiting.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_name</span><span class="p">);</span>
<span class="n">event_base_free</span><span class="p">(</span><span class="n">this_event_base</span><span class="p">);</span>
<span class="n">getdns_context_destroy</span><span class="p">(</span><span class="n">this_context</span><span class="p">);</span>
<span class="k">return</span><span class="p">(</span><span class="n">GETDNS_RETURN_GENERIC_ERROR</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
@ -1478,6 +1486,7 @@ function.</p>
<span class="c1">// TODO: check the return value above</span>
<span class="p">}</span>
<span class="cm">/* Clean up */</span>
<span class="n">event_base_free</span><span class="p">(</span><span class="n">this_event_base</span><span class="p">);</span>
<span class="n">getdns_context_destroy</span><span class="p">(</span><span class="n">this_context</span><span class="p">);</span>
<span class="cm">/* Assuming we get here, leave gracefully */</span>
<span class="n">exit</span><span class="p">(</span><span class="n">EXIT_SUCCESS</span><span class="p">);</span>
@ -1514,25 +1523,27 @@ their TTLs.</p>
<span class="k">if</span> <span class="p">(</span><span class="n">this_callback_type</span> <span class="o">==</span> <span class="n">GETDNS_CALLBACK_COMPLETE</span><span class="p">)</span> <span class="cm">/* This is a callback with data */</span>
<span class="p">{</span>
<span class="cm">/* Be sure the search returned something */</span>
<span class="kt">uint32_t</span> <span class="o">*</span> <span class="n">this_error</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_int</span><span class="p">(</span><span class="n">this_response</span><span class="p">,</span> <span class="s">&quot;status&quot;</span><span class="p">,</span> <span class="n">this_error</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="k">if</span> <span class="p">(</span><span class="o">*</span><span class="n">this_error</span> <span class="o">!=</span> <span class="n">GETDNS_RESPSTATUS_GOOD</span><span class="p">)</span> <span class="c1">// If the search didn&#39;t return &quot;good&quot;</span>
<span class="kt">uint32_t</span> <span class="n">this_error</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_int</span><span class="p">(</span><span class="n">this_response</span><span class="p">,</span> <span class="s">&quot;status&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_error</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="k">if</span> <span class="p">(</span><span class="n">this_error</span> <span class="o">!=</span> <span class="n">GETDNS_RESPSTATUS_GOOD</span><span class="p">)</span> <span class="c1">// If the search didn&#39;t return &quot;good&quot;</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The search had no results, and a return value of %d. Exiting.&quot;</span><span class="p">,</span> <span class="o">*</span><span class="n">this_error</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The search had no results, and a return value of %d. Exiting.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_error</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_response</span><span class="p">);</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="cm">/* Find all the answers returned */</span>
<span class="k">struct</span> <span class="n">getdns_list</span> <span class="o">*</span> <span class="n">these_answers</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_list</span><span class="p">(</span><span class="n">this_response</span><span class="p">,</span> <span class="s">&quot;replies-tree&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">these_answers</span><span class="p">);</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_list</span><span class="p">(</span><span class="n">this_response</span><span class="p">,</span> <span class="s">&quot;replies_tree&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">these_answers</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">this_ret</span> <span class="o">==</span> <span class="n">GETDNS_RETURN_NO_SUCH_DICT_NAME</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Weird: the response had no error, but also no replies-tree. Exiting.&quot;</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Weird: the response had no error, but also no replies_tree. Exiting.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_response</span><span class="p">);</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">size_t</span> <span class="o">*</span> <span class="n">num_answers_ptr</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_list_get_length</span><span class="p">(</span><span class="n">these_answers</span><span class="p">,</span> <span class="n">num_answers_ptr</span><span class="p">);</span>
<span class="kt">size_t</span> <span class="n">num_answers</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_list_get_length</span><span class="p">(</span><span class="n">these_answers</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">num_answers</span><span class="p">);</span>
<span class="cm">/* Go through each answer */</span>
<span class="k">for</span> <span class="p">(</span> <span class="kt">size_t</span> <span class="n">rec_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">rec_count</span> <span class="o">&lt;=</span> <span class="o">*</span><span class="n">num_answers_ptr</span><span class="p">;</span> <span class="o">++</span><span class="n">rec_count</span> <span class="p">)</span>
<span class="k">for</span> <span class="p">(</span> <span class="kt">size_t</span> <span class="n">rec_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">rec_count</span> <span class="o">&lt;</span> <span class="n">num_answers</span><span class="p">;</span> <span class="o">++</span><span class="n">rec_count</span> <span class="p">)</span>
<span class="p">{</span>
<span class="k">struct</span> <span class="n">getdns_dict</span> <span class="o">*</span> <span class="n">this_record</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_list_get_dict</span><span class="p">(</span><span class="n">these_answers</span><span class="p">,</span> <span class="n">rec_count</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_record</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
@ -1540,50 +1551,57 @@ their TTLs.</p>
<span class="k">struct</span> <span class="n">getdns_list</span> <span class="o">*</span> <span class="n">this_answer</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_list</span><span class="p">(</span><span class="n">this_record</span><span class="p">,</span> <span class="s">&quot;answer&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_answer</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="cm">/* Get each RR in the answer section */</span>
<span class="kt">size_t</span> <span class="o">*</span> <span class="n">num_rrs_ptr</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_list_get_length</span><span class="p">(</span><span class="n">this_answer</span><span class="p">,</span> <span class="n">num_rrs_ptr</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span> <span class="kt">size_t</span> <span class="n">rr_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">rr_count</span> <span class="o">&lt;=</span> <span class="o">*</span><span class="n">num_rrs_ptr</span><span class="p">;</span> <span class="o">++</span><span class="n">rr_count</span> <span class="p">)</span>
<span class="kt">size_t</span> <span class="n">num_rrs</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_list_get_length</span><span class="p">(</span><span class="n">this_answer</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">num_rrs</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span> <span class="kt">size_t</span> <span class="n">rr_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">rr_count</span> <span class="o">&lt;</span> <span class="n">num_rrs</span><span class="p">;</span> <span class="o">++</span><span class="n">rr_count</span> <span class="p">)</span>
<span class="p">{</span>
<span class="k">struct</span> <span class="n">getdns_dict</span> <span class="o">*</span> <span class="n">this_rr</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">getdns_dict</span> <span class="o">*</span><span class="n">this_rr</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_list_get_dict</span><span class="p">(</span><span class="n">this_answer</span><span class="p">,</span> <span class="n">rr_count</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_rr</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="cm">/* Get the RDATA */</span>
<span class="k">struct</span> <span class="n">getdns_dict</span> <span class="o">*</span> <span class="n">this_rdata</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_dict</span><span class="p">(</span><span class="n">this_rr</span><span class="p">,</span> <span class="s">&quot;rdata&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_rdata</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="cm">/* Get the RDATA type */</span>
<span class="kt">uint32_t</span> <span class="o">*</span> <span class="n">this_type</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_int</span><span class="p">(</span><span class="n">this_rdata</span><span class="p">,</span> <span class="s">&quot;type&quot;</span><span class="p">,</span> <span class="n">this_type</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="kt">uint32_t</span> <span class="n">this_type</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_int</span><span class="p">(</span><span class="n">this_rr</span><span class="p">,</span> <span class="s">&quot;type&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_type</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="cm">/* If it is type A or AAAA, print the value */</span>
<span class="k">if</span> <span class="p">(</span><span class="o">*</span><span class="n">this_type</span> <span class="o">==</span> <span class="n">GETDNS_RRTYPE_A</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">this_type</span> <span class="o">==</span> <span class="n">GETDNS_RRTYPE_A</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">struct</span> <span class="n">getdns_bindata</span> <span class="o">*</span> <span class="n">this_a_record</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_bindata</span><span class="p">(</span><span class="n">this_rdata</span><span class="p">,</span> <span class="s">&quot;ipv4_address&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_a_record</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">this_ret</span> <span class="o">==</span> <span class="n">GETDNS_RETURN_NO_SUCH_DICT_NAME</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Weird: the A record at %d in record at %d had no address. Exiting.&quot;</span><span class="p">,</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Weird: the A record at %d in record at %d had no address. Exiting.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
<span class="p">(</span><span class="kt">int</span><span class="p">)</span> <span class="n">rr_count</span><span class="p">,</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span> <span class="n">rec_count</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_response</span><span class="p">);</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">&quot;The IPv4 address is %s&quot;</span><span class="p">,</span> <span class="n">getdns_display_ip_address</span><span class="p">(</span><span class="n">this_a_record</span><span class="p">));</span>
<span class="kt">char</span> <span class="o">*</span><span class="n">this_address_str</span> <span class="o">=</span> <span class="n">getdns_display_ip_address</span><span class="p">(</span><span class="n">this_a_record</span><span class="p">);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">&quot;The IPv4 address is %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_address_str</span><span class="p">);</span>
<span class="n">free</span><span class="p">(</span><span class="n">this_address_str</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="o">*</span><span class="n">this_type</span> <span class="o">==</span> <span class="n">GETDNS_RRTYPE_AAAA</span><span class="p">)</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">this_type</span> <span class="o">==</span> <span class="n">GETDNS_RRTYPE_AAAA</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">struct</span> <span class="n">getdns_bindata</span> <span class="o">*</span> <span class="n">this_aaaa_record</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_bindata</span><span class="p">(</span><span class="n">this_rdata</span><span class="p">,</span> <span class="s">&quot;ipv6_address&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_aaaa_record</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">this_ret</span> <span class="o">==</span> <span class="n">GETDNS_RETURN_NO_SUCH_DICT_NAME</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Weird: the AAAA record at %d in record at %d had no address. Exiting.&quot;</span><span class="p">,</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Weird: the AAAA record at %d in record at %d had no address. Exiting.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span>
<span class="p">(</span><span class="kt">int</span><span class="p">)</span> <span class="n">rr_count</span><span class="p">,</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span> <span class="n">rec_count</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_response</span><span class="p">);</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">&quot;The IPv6 address is %s&quot;</span><span class="p">,</span> <span class="n">getdns_display_ip_address</span><span class="p">(</span><span class="n">this_aaaa_record</span><span class="p">));</span>
<span class="kt">char</span> <span class="o">*</span><span class="n">this_address_str</span> <span class="o">=</span> <span class="n">getdns_display_ip_address</span><span class="p">(</span><span class="n">this_aaaa_record</span><span class="p">);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">&quot;The IPv6 address is %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_address_str</span><span class="p">);</span>
<span class="n">free</span><span class="p">(</span><span class="n">this_address_str</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">this_callback_type</span> <span class="o">==</span> <span class="n">GETDNS_CALLBACK_CANCEL</span><span class="p">)</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The callback with ID %&quot;</span><span class="n">PRIu64</span><span class="s">&quot; was cancelled. Exiting.&quot;</span><span class="p">,</span> <span class="n">this_transaction_id</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The callback with ID %&quot;</span><span class="n">PRIu64</span><span class="s">&quot; was cancelled. Exiting.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_transaction_id</span><span class="p">);</span>
<span class="k">else</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The callback got a callback_type of %d. Exiting.&quot;</span><span class="p">,</span> <span class="n">this_callback_type</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The callback got a callback_type of %d. Exiting.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_callback_type</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_response</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
@ -1593,7 +1611,7 @@ their TTLs.</p>
<span class="kt">getdns_return_t</span> <span class="n">context_create_return</span> <span class="o">=</span> <span class="n">getdns_context_create</span><span class="p">(</span><span class="o">&amp;</span><span class="n">this_context</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">context_create_return</span> <span class="o">!=</span> <span class="n">GETDNS_RETURN_GOOD</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Trying to create the context failed: %d&quot;</span><span class="p">,</span> <span class="n">context_create_return</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Trying to create the context failed: %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">context_create_return</span><span class="p">);</span>
<span class="k">return</span><span class="p">(</span><span class="n">GETDNS_RETURN_GENERIC_ERROR</span><span class="p">);</span>
<span class="p">}</span>
<span class="cm">/* Create an event base and put it in the context using the unknown function name */</span>
@ -1601,7 +1619,8 @@ their TTLs.</p>
<span class="n">this_event_base</span> <span class="o">=</span> <span class="n">event_base_new</span><span class="p">();</span>
<span class="k">if</span> <span class="p">(</span><span class="n">this_event_base</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Trying to create the event base failed.&quot;</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Trying to create the event base failed.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="n">getdns_context_destroy</span><span class="p">(</span><span class="n">this_context</span><span class="p">);</span>
<span class="k">return</span><span class="p">(</span><span class="n">GETDNS_RETURN_GENERIC_ERROR</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="n">getdns_extension_set_libevent_base</span><span class="p">(</span><span class="n">this_context</span><span class="p">,</span> <span class="n">this_event_base</span><span class="p">);</span>
@ -1615,7 +1634,9 @@ their TTLs.</p>
<span class="nb">NULL</span><span class="p">,</span> <span class="n">this_userarg</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_transaction_id</span><span class="p">,</span> <span class="n">this_callbackfn</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">dns_request_return</span> <span class="o">==</span> <span class="n">GETDNS_RETURN_BAD_DOMAIN_NAME</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;A bad domain name was used: %s. Exiting.&quot;</span><span class="p">,</span> <span class="n">this_name</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;A bad domain name was used: %s. Exiting.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_name</span><span class="p">);</span>
<span class="n">event_base_free</span><span class="p">(</span><span class="n">this_event_base</span><span class="p">);</span>
<span class="n">getdns_context_destroy</span><span class="p">(</span><span class="n">this_context</span><span class="p">);</span>
<span class="k">return</span><span class="p">(</span><span class="n">GETDNS_RETURN_GENERIC_ERROR</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
@ -1626,6 +1647,7 @@ their TTLs.</p>
<span class="c1">// TODO: check the return value above</span>
<span class="p">}</span>
<span class="cm">/* Clean up */</span>
<span class="n">event_base_free</span><span class="p">(</span><span class="n">this_event_base</span><span class="p">);</span>
<span class="n">getdns_context_destroy</span><span class="p">(</span><span class="n">this_context</span><span class="p">);</span>
<span class="cm">/* Assuming we get here, leave gracefully */</span>
<span class="n">exit</span><span class="p">(</span><span class="n">EXIT_SUCCESS</span><span class="p">);</span>
@ -1686,7 +1708,7 @@ as it is for the synchronous example, it is just done in <code>main()</code>.</p
<span class="kt">getdns_return_t</span> <span class="n">context_create_return</span> <span class="o">=</span> <span class="n">getdns_context_create</span><span class="p">(</span><span class="o">&amp;</span><span class="n">this_context</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">context_create_return</span> <span class="o">!=</span> <span class="n">GETDNS_RETURN_GOOD</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Trying to create the context failed: %d&quot;</span><span class="p">,</span> <span class="n">context_create_return</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Trying to create the context failed: %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">context_create_return</span><span class="p">);</span>
<span class="k">return</span><span class="p">(</span><span class="n">GETDNS_RETURN_GENERIC_ERROR</span><span class="p">);</span>
<span class="p">}</span>
<span class="cm">/* Set up the getdns_sync_request call */</span>
@ -1697,7 +1719,9 @@ as it is for the synchronous example, it is just done in <code>main()</code>.</p
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_set_int</span><span class="p">(</span><span class="n">this_extensions</span><span class="p">,</span> <span class="s">&quot;return_both_v4_and_v6&quot;</span><span class="p">,</span> <span class="n">GETDNS_EXTENSION_TRUE</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">this_ret</span> <span class="o">!=</span> <span class="n">GETDNS_RETURN_GOOD</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Trying to set an extension do both IPv4 and IPv6 failed: %d&quot;</span><span class="p">,</span> <span class="n">this_ret</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;Trying to set an extension do both IPv4 and IPv6 failed: %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_ret</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_extensions</span><span class="p">);</span>
<span class="n">getdns_context_destroy</span><span class="p">(</span><span class="n">this_context</span><span class="p">);</span>
<span class="k">return</span><span class="p">(</span><span class="n">GETDNS_RETURN_GENERIC_ERROR</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">struct</span> <span class="n">getdns_dict</span> <span class="o">*</span> <span class="n">this_response</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
@ -1707,37 +1731,46 @@ as it is for the synchronous example, it is just done in <code>main()</code>.</p
<span class="n">this_extensions</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_response</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">dns_request_return</span> <span class="o">==</span> <span class="n">GETDNS_RETURN_BAD_DOMAIN_NAME</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;A bad domain name was used: %s. Exiting.&quot;</span><span class="p">,</span> <span class="n">this_name</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;A bad domain name was used: %s. Exiting.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_name</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_response</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_extensions</span><span class="p">);</span>
<span class="n">getdns_context_destroy</span><span class="p">(</span><span class="n">this_context</span><span class="p">);</span>
<span class="k">return</span><span class="p">(</span><span class="n">GETDNS_RETURN_GENERIC_ERROR</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="cm">/* Be sure the search returned something */</span>
<span class="kt">uint32_t</span> <span class="o">*</span> <span class="n">this_error</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_int</span><span class="p">(</span><span class="n">this_response</span><span class="p">,</span> <span class="s">&quot;status&quot;</span><span class="p">,</span> <span class="n">this_error</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="k">if</span> <span class="p">(</span><span class="o">*</span><span class="n">this_error</span> <span class="o">!=</span> <span class="n">GETDNS_RESPSTATUS_GOOD</span><span class="p">)</span> <span class="c1">// If the search didn&#39;t return &quot;good&quot;</span>
<span class="kt">uint32_t</span> <span class="n">this_error</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_int</span><span class="p">(</span><span class="n">this_response</span><span class="p">,</span> <span class="s">&quot;status&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_error</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="k">if</span> <span class="p">(</span><span class="n">this_error</span> <span class="o">!=</span> <span class="n">GETDNS_RESPSTATUS_GOOD</span><span class="p">)</span> <span class="c1">// If the search didn&#39;t return &quot;good&quot;</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The search had no results, and a return value of %d. Exiting.&quot;</span><span class="p">,</span> <span class="o">*</span><span class="n">this_error</span><span class="p">);</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">&quot;The search had no results, and a return value of %d. Exiting.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_error</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_response</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_extensions</span><span class="p">);</span>
<span class="n">getdns_context_destroy</span><span class="p">(</span><span class="n">this_context</span><span class="p">);</span>
<span class="k">return</span><span class="p">(</span><span class="n">GETDNS_RETURN_GENERIC_ERROR</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">struct</span> <span class="n">getdns_list</span> <span class="o">*</span> <span class="n">just_the_addresses_ptr</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_list</span><span class="p">(</span><span class="n">this_response</span><span class="p">,</span> <span class="s">&quot;just_address_answers&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">just_the_addresses_ptr</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="kt">size_t</span> <span class="o">*</span> <span class="n">num_addresses_ptr</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_list_get_length</span><span class="p">(</span><span class="n">just_the_addresses_ptr</span><span class="p">,</span> <span class="n">num_addresses_ptr</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="kt">size_t</span> <span class="n">num_addresses</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_list_get_length</span><span class="p">(</span><span class="n">just_the_addresses_ptr</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">num_addresses</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="cm">/* Go through each record */</span>
<span class="k">for</span> <span class="p">(</span> <span class="kt">size_t</span> <span class="n">rec_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">rec_count</span> <span class="o">&lt;=</span> <span class="o">*</span><span class="n">num_addresses_ptr</span><span class="p">;</span> <span class="o">++</span><span class="n">rec_count</span> <span class="p">)</span>
<span class="k">for</span> <span class="p">(</span> <span class="kt">size_t</span> <span class="n">rec_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">rec_count</span> <span class="o">&lt;</span> <span class="n">num_addresses</span><span class="p">;</span> <span class="o">++</span><span class="n">rec_count</span> <span class="p">)</span>
<span class="p">{</span>
<span class="k">struct</span> <span class="n">getdns_dict</span> <span class="o">*</span> <span class="n">this_address</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_list_get_dict</span><span class="p">(</span><span class="n">just_the_addresses_ptr</span><span class="p">,</span> <span class="n">rec_count</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_address</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="cm">/* Just print the address */</span>
<span class="k">struct</span> <span class="n">getdns_bindata</span> <span class="o">*</span> <span class="n">this_address_data</span><span class="p">;</span>
<span class="n">this_ret</span> <span class="o">=</span> <span class="n">getdns_dict_get_bindata</span><span class="p">(</span><span class="n">this_address</span><span class="p">,</span> <span class="s">&quot;address_data&quot;</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">this_address_data</span><span class="p">);</span> <span class="c1">// Ignore any error</span>
<span class="n">printf</span><span class="p">(</span><span class="s">&quot;The address is %s&quot;</span><span class="p">,</span> <span class="n">getdns_display_ip_address</span><span class="p">(</span><span class="n">this_address_data</span><span class="p">));</span>
<span class="kt">char</span> <span class="o">*</span><span class="n">this_address_str</span> <span class="o">=</span> <span class="n">getdns_display_ip_address</span><span class="p">(</span><span class="n">this_address_data</span><span class="p">);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">&quot;The address is %s</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">this_address_str</span><span class="p">);</span>
<span class="n">free</span><span class="p">(</span><span class="n">this_address_str</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="cm">/* Clean up */</span>
<span class="n">getdns_context_destroy</span><span class="p">(</span><span class="n">this_context</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_response</span><span class="p">);</span>
<span class="n">getdns_dict_destroy</span><span class="p">(</span><span class="n">this_extensions</span><span class="p">);</span>
<span class="n">getdns_context_destroy</span><span class="p">(</span><span class="n">this_context</span><span class="p">);</span>
<span class="cm">/* Assuming we get here, leave gracefully */</span>
<span class="n">exit</span><span class="p">(</span><span class="n">EXIT_SUCCESS</span><span class="p">);</span>
<span class="p">}</span>
@ -2120,7 +2153,7 @@ getdns_context_set_extended_memory_functions(
void (*free)(void *userarg, void *ptr)
);</div>
<p class=cont>The given extended memory management functions will be used for creating the response dicts.
The value of <code>userarg</code> argument will be passed to the custom <code>malloc<code>, <code>realloc</code>, and <code>free</code>.
The value of <code>userarg</code> argument will be passed to the custom <code>malloc</code>, <code>realloc</code>, and <code>free</code>.
The response dicts inherit the custom memory management functions and the value for <code>userarg</code> from the context and will deallocate themselves (and their members) with the custom deallocator.</p>
<h2>8.10 <a id="ContextCodes">Context Codes</a></h2>
@ -2165,7 +2198,7 @@ The response dicts inherit the custom memory management functions and the value
<h1>9. The Generated Files</h1>
<p>There is <a href="getdns-0.370.tgz">a tarball</a> that includes the .h files,
<p>There is <a href="getdns-0.371.tgz">a tarball</a> that includes the .h files,
the examples, and so on. The examples all make, even though there is no API implementation, based
on a pseudo-implementation in the tarball; see make-examples-PLATFORM.sh. Note that this currently builds fine
on the Macintosh and Ubuntu; help is definitely appreciated on making the build process

View File

@ -969,6 +969,7 @@ getdns_return_t
getdns_cancel_callback(struct getdns_context *context,
getdns_transaction_t transaction_id)
{
RETURN_IF_NULL(context, GETDNS_RETURN_BAD_CONTEXT);
return getdns_context_cancel_request(context, transaction_id, 1);
} /* getdns_cancel_callback */

View File

@ -716,4 +716,10 @@ getdns_pretty_print_dict(struct getdns_dict *dict)
return ret;
} /* getdns_pretty_print_dict */
getdns_return_t
getdns_dict_remove_name(struct getdns_dict *this_dict, char *name)
{
return GETDNS_RETURN_GENERIC_ERROR;
}
/* dict.c */

View File

@ -19,7 +19,7 @@ CC=gcc
CFLAGS=@CFLAGS@ -Wall -I$(srcdir)/ -I$(srcdir)/../ -I/usr/local/include -std=c99
LDFLAGS=@LDFLAGS@ -L. -L.. -L/usr/local/lib
LDLIBS=-lgetdns @LIBS@
PROGRAMS=example_simple_answers example_tree example_all_functions example_synchronous
PROGRAMS=example-all-functions example-simple-answers example-tree example-synchronous example-reverse
.SUFFIXES: .c .o .a .lo .h
@ -30,17 +30,20 @@ default: all
all: $(PROGRAMS)
example_simple_answers: example_simple_answers.o
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ example_simple_answers.o
example-all-functions: example-all-functions.o
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ example-all-functions.o
example_tree: example_tree.o
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ example_tree.o
example-simple-answers: example-simple-answers.o
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ example-simple-answers.o
example_all_functions: example_all_functions.o
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ example_all_functions.o
example-tree: example-tree.o
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ example-tree.o
example_synchronous: example_synchronous.o
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ example_synchronous.o
example-synchronous: example-synchronous.o
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ example-synchronous.o
example-reverse: example-reverse.o
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ example-reverse.o
clean:
rm -f *.o $(PROGRAMS)

View File

@ -0,0 +1,339 @@
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <getdns_libevent.h>
#define UNUSED_PARAM(x) ((void)(x))
/* The return values */
getdns_return_t retregular;
char * retcharstar;
/* The args */
int boolarg;
char * charstararg;
getdns_callback_t callbackarg;
uint16_t regulararg;
uint16_t *regularptrarg;
getdns_transaction_t txidarg;
getdns_transaction_t * txidptrarg;
getdns_data_type * datatypeptrarg;
struct getdns_bindata ** bindataptrarg;
struct getdns_dict * dictarg;
struct getdns_bindata * bindataarg;
struct getdns_list * listarg;
struct getdns_dict ** dictptrarg;
struct getdns_list ** listptrarg;
size_t sizetarg;
size_t * sizetptrarg;
struct getdns_context *contextarg = NULL;
uint8_t uint8arg;
uint16_t uint16arg;
uint32_t uint32arg;
uint8_t * uint8ptrarg;
uint16_t * uint16ptrarg;
uint32_t * uint32ptrarg;
void * arrayarg;
void * userarg;
void * allocfunctionarg(size_t foo) {UNUSED_PARAM(foo); return NULL; }
void * reallocfunctionarg(void* foo, size_t bar)
{UNUSED_PARAM(foo); UNUSED_PARAM(bar); return NULL; }
void deallocfunctionarg(void* foo) {UNUSED_PARAM(foo);}
void * extendedallocfunctionarg(void* userarg, size_t foo)
{UNUSED_PARAM(userarg); UNUSED_PARAM(foo); return NULL; }
void * extendedreallocfunctionarg(void* userarg, void* foo, size_t bar)
{UNUSED_PARAM(userarg); UNUSED_PARAM(foo); UNUSED_PARAM(bar); return NULL; }
void extendeddeallocfunctionarg(void* userarg, void* foo)
{UNUSED_PARAM(userarg); UNUSED_PARAM(foo);}
void setcallbackfunctionarg(struct getdns_context *foo1, uint16_t foo2)
{UNUSED_PARAM(foo1);UNUSED_PARAM(foo2);}
int main()
{
retregular = getdns_general(
contextarg,
charstararg,
uint16arg,
dictarg,
arrayarg,
txidptrarg,
callbackarg
);
retregular = getdns_address(
contextarg,
charstararg,
dictarg,
arrayarg,
txidptrarg,
callbackarg
);
retregular = getdns_hostname(
contextarg,
dictarg,
dictarg,
arrayarg,
txidptrarg,
callbackarg
);
retregular = getdns_service(
contextarg,
charstararg,
dictarg,
arrayarg,
txidptrarg,
callbackarg
);
retregular = getdns_context_create(
&contextarg,
boolarg
);
retregular = getdns_context_create_with_memory_functions(
&contextarg,
boolarg,
allocfunctionarg,
reallocfunctionarg,
deallocfunctionarg
);
retregular = getdns_context_create_with_extended_memory_functions(
&contextarg,
boolarg,
userarg,
extendedallocfunctionarg,
extendedreallocfunctionarg,
extendeddeallocfunctionarg
);
getdns_context_destroy(
contextarg
);
retregular = getdns_cancel_callback(
contextarg,
txidarg
);
retregular = getdns_general_sync(
contextarg,
charstararg,
uint16arg,
dictarg,
&dictarg
);
retregular = getdns_address_sync(
contextarg,
charstararg,
dictarg,
&dictarg
);
retregular = getdns_hostname_sync(
contextarg,
dictarg,
dictarg,
&dictarg
);
retregular = getdns_service_sync(
contextarg,
charstararg,
dictarg,
&dictarg
);
retregular = getdns_list_get_length(listarg, sizetptrarg);
retregular = getdns_list_get_data_type(listarg, sizetarg, datatypeptrarg);
retregular = getdns_list_get_dict(listarg, sizetarg, dictptrarg);
retregular = getdns_list_get_list(listarg, sizetarg, listptrarg);
retregular = getdns_list_get_bindata(listarg, sizetarg, bindataptrarg);
retregular = getdns_list_get_int(listarg, sizetarg, uint32ptrarg);
retregular = getdns_dict_get_names(dictarg, listptrarg);
retregular = getdns_dict_get_data_type(dictarg, charstararg, datatypeptrarg);
retregular = getdns_dict_get_dict(dictarg, charstararg, dictptrarg);
retregular = getdns_dict_get_list(dictarg, charstararg, listptrarg);
retregular = getdns_dict_get_bindata(dictarg, charstararg, bindataptrarg);
retregular = getdns_dict_get_int(dictarg, charstararg, uint32ptrarg);
listarg = getdns_list_create();
listarg = getdns_list_create_with_context(contextarg);
listarg = getdns_list_create_with_memory_functions(
allocfunctionarg,
reallocfunctionarg,
deallocfunctionarg
);
listarg = getdns_list_create_with_extended_memory_functions(
userarg,
extendedallocfunctionarg,
extendedreallocfunctionarg,
extendeddeallocfunctionarg
);
getdns_list_destroy(listarg);
retregular = getdns_list_set_dict(listarg, sizetarg, dictarg);
retregular = getdns_list_set_list(listarg, sizetarg, listarg);
retregular = getdns_list_set_bindata(listarg, sizetarg, bindataarg);
retregular = getdns_list_set_int(listarg, sizetarg, uint32arg);
dictarg = getdns_dict_create();
dictarg = getdns_dict_create_with_context(contextarg);
dictarg = getdns_dict_create_with_memory_functions(
allocfunctionarg,
reallocfunctionarg,
deallocfunctionarg
);
dictarg = getdns_dict_create_with_extended_memory_functions(
userarg,
extendedallocfunctionarg,
extendedreallocfunctionarg,
extendeddeallocfunctionarg
);
getdns_dict_destroy(dictarg);
retregular = getdns_dict_set_dict(dictarg, charstararg, dictarg);
retregular = getdns_dict_set_list(dictarg, charstararg, listarg);
retregular = getdns_dict_set_bindata(dictarg, charstararg, bindataarg);
retregular = getdns_dict_set_int(dictarg, charstararg, uint32arg);
retregular = getdns_dict_remove_name(dictarg, charstararg);
retcharstar = getdns_convert_fqdn_to_dns_name(
charstararg
);
retcharstar = getdns_convert_dns_name_to_fqdn(
charstararg
);
retcharstar = getdns_convert_ulabel_to_alabel(
charstararg
);
retcharstar = getdns_convert_alabel_to_ulabel(
charstararg
);
retregular = getdns_validate_dnssec(
bindataarg,
listarg,
listarg
);
retcharstar = getdns_pretty_print_dict(
dictarg
);
retcharstar = getdns_display_ip_address(
bindataarg
);
retregular = getdns_context_set_context_update_callback(
contextarg,
setcallbackfunctionarg
);
retregular = getdns_context_set_resolution_type(
contextarg,
regulararg
);
retregular = getdns_context_set_namespaces(
contextarg,
sizetarg,
regularptrarg
);
retregular = getdns_context_set_dns_transport(
contextarg,
regulararg
);
retregular = getdns_context_set_limit_outstanding_queries(
contextarg,
uint16arg
);
retregular = getdns_context_set_timeout(
contextarg,
uint16arg
);
retregular = getdns_context_set_follow_redirects(
contextarg,
regulararg
);
retregular = getdns_context_set_dns_root_servers(
contextarg,
listarg
);
retregular = getdns_context_set_append_name(
contextarg,
regulararg
);
retregular = getdns_context_set_suffix(
contextarg,
listarg
);
retregular = getdns_context_set_dnssec_trust_anchors(
contextarg,
listarg
);
retregular = getdns_context_set_dnssec_allowed_skew(
contextarg,
uint16arg
);
retregular = getdns_context_set_stub_resolution(
contextarg,
listarg
);
retregular = getdns_context_set_edns_maximum_udp_payload_size(
contextarg,
uint16arg
);
retregular = getdns_context_set_edns_extended_rcode(
contextarg,
uint8arg
);
retregular = getdns_context_set_edns_version(
contextarg,
uint8arg
);
retregular = getdns_context_set_edns_do_bit(
contextarg,
uint8arg
);
retregular = getdns_context_set_memory_functions(
contextarg,
allocfunctionarg,
reallocfunctionarg,
deallocfunctionarg
);
retregular = getdns_context_set_extended_memory_functions(
contextarg,
userarg,
extendedallocfunctionarg,
extendedreallocfunctionarg,
extendeddeallocfunctionarg
);
return(0); } /* End of main() */

View File

@ -0,0 +1,134 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <getdns_libevent.h>
#define UNUSED_PARAM(x) ((void)(x))
/* Set up the callback function, which will also do the processing of the results */
void this_callbackfn(struct getdns_context *this_context,
uint16_t this_callback_type,
struct getdns_dict *this_response,
void *this_userarg,
getdns_transaction_t this_transaction_id)
{
UNUSED_PARAM(this_userarg); /* Not looking at the userarg for this example */
UNUSED_PARAM(this_context); /* Not looking at the context for this example */
getdns_return_t this_ret; /* Holder for all function returns */
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) /* This is a callback with data */
{
/* Be sure the search returned something */
uint32_t this_error;
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.\n", this_error);
getdns_dict_destroy(this_response);
return;
}
struct getdns_list *replies_tree;
this_ret = getdns_dict_get_list(this_response, "replies_tree", &replies_tree); // Ignore any error
size_t num_replies;
this_ret = getdns_list_get_length(replies_tree, &num_replies); // Ignore any error
/* Go through each reply */
for ( size_t reply_count = 0; reply_count < num_replies; ++reply_count)
{
struct getdns_dict * this_reply;
this_ret = getdns_list_get_dict(replies_tree, reply_count, &this_reply); // Ignore any error
/* Just print the address */
struct getdns_list* reply_answers;
this_ret = getdns_dict_get_list(this_reply, "answer", &reply_answers); // Ignore any error
size_t num_answers;
this_ret = getdns_list_get_length(reply_answers, &num_answers); // Ignore any error
/* Go through each answer */
for ( size_t answer_count = 0; answer_count < num_answers; ++answer_count)
{
struct getdns_dict * this_rr;
this_ret = getdns_list_get_dict(reply_answers, answer_count, &this_rr);
/* Get the RDATA type */
uint32_t this_type;
this_ret = getdns_dict_get_int(this_rr, "type", &this_type); // Ignore any error
if (this_type == GETDNS_RRTYPE_PTR)
{
struct getdns_dict *this_rdata;
this_ret = getdns_dict_get_dict(this_rr, "rdata", &this_rdata); // Ignore any error
struct getdns_bindata * this_dname;
this_ret = getdns_dict_get_bindata(this_rdata, "rdata_raw", &this_dname);
char *this_dname_str = getdns_convert_dns_name_to_fqdn(this_dname->data);
printf("The dname is %s\n", this_dname_str);
free(this_dname_str);
}
}
}
}
else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.", this_transaction_id);
else
fprintf(stderr, "The callback got a callback_type of %d. Exiting.", this_callback_type);
getdns_dict_destroy(this_response);
}
int main()
{
/* Create the DNS context for this call */
struct getdns_context *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, 1);
if (context_create_return != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to create the context failed: %d", context_create_return);
return(GETDNS_RETURN_GENERIC_ERROR);
}
/* Create an event base and put it in the context using the unknown function name */
struct event_base *this_event_base;
this_event_base = event_base_new();
if (this_event_base == NULL)
{
fprintf(stderr, "Trying to create the event base failed.");
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
(void)getdns_extension_set_libevent_base(this_context, this_event_base);
/* Set up the getdns call */
struct getdns_dict * this_addr_to_look_up = getdns_dict_create();
// TODO: check the return value above
struct getdns_bindata this_type = { 5, (void *)"IPv4" };
getdns_return_t this_ret = getdns_dict_set_bindata(this_addr_to_look_up, "address_type", &this_type);
UNUSED_PARAM(this_ret);
struct getdns_bindata this_ipv4_addr = { 4, (void *)"\x08\x08\x08\x08" };
this_ret = getdns_dict_set_bindata(this_addr_to_look_up, "address_data", &this_ipv4_addr);
char* this_userarg = "somestring"; // Could add things here to help identify this call
getdns_transaction_t this_transaction_id = 0;
/* Make the call */
getdns_return_t dns_request_return = getdns_hostname(this_context, this_addr_to_look_up,
NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
char *ip_address_str = getdns_display_ip_address(&this_ipv4_addr);
fprintf(stderr, "A bad IP address was used: %s. Exiting.\n", ip_address_str);
free(ip_address_str);
getdns_dict_destroy(this_addr_to_look_up);
event_base_free(this_event_base);
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
{
/* Call the event loop */
int dispatch_return = event_base_dispatch(this_event_base);
UNUSED_PARAM(dispatch_return);
// TODO: check the return value above
}
/* Clean up */
getdns_dict_destroy(this_addr_to_look_up);
event_base_free(this_event_base);
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
}

View File

@ -0,0 +1,108 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <getdns_libevent.h>
#define UNUSED_PARAM(x) ((void)(x))
/* Set up the callback function, which will also do the processing of the results */
void this_callbackfn(struct getdns_context *this_context,
uint16_t this_callback_type,
struct getdns_dict *this_response,
void *this_userarg,
getdns_transaction_t this_transaction_id)
{
UNUSED_PARAM(this_userarg); /* Not looking at the userarg for this example */
UNUSED_PARAM(this_context); /* Not looking at the context for this example */
getdns_return_t this_ret; /* Holder for all function returns */
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) /* This is a callback with data */
{
/* Be sure the search returned something */
uint32_t this_error;
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.\n", this_error);
getdns_dict_destroy(this_response);
return;
}
struct getdns_list * just_the_addresses_ptr;
this_ret = getdns_dict_get_list(this_response, "just_address_answers", &just_the_addresses_ptr);
if (this_ret != GETDNS_RETURN_GOOD) // This check is really not needed, but prevents a compiler error under "pedantic"
{
fprintf(stderr, "Trying to get the answers failed: %d\n", this_ret);
getdns_dict_destroy(this_response);
return;
}
size_t num_addresses;
this_ret = getdns_list_get_length(just_the_addresses_ptr, &num_addresses); // Ignore any error
/* Go through each record */
for ( size_t rec_count = 0; rec_count < num_addresses; ++rec_count )
{
struct getdns_dict * this_address;
this_ret = getdns_list_get_dict(just_the_addresses_ptr, rec_count, &this_address); // Ignore any error
/* Just print the address */
struct getdns_bindata * this_address_data;
this_ret = getdns_dict_get_bindata(this_address, "address_data", &this_address_data); // Ignore any error
char *this_address_str = getdns_display_ip_address(this_address_data);
printf("The address is %s\n", this_address_str);
free(this_address_str);
}
}
else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.\n", this_transaction_id);
else
fprintf(stderr, "The callback got a callback_type of %d. Exiting.\n", this_callback_type);
getdns_dict_destroy(this_response);
}
int main()
{
/* Create the DNS context for this call */
struct getdns_context *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, 1);
if (context_create_return != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to create the context failed: %d", context_create_return);
return(GETDNS_RETURN_GENERIC_ERROR);
}
/* Create an event base and put it in the context using the unknown function name */
struct event_base *this_event_base;
this_event_base = event_base_new();
if (this_event_base == NULL)
{
fprintf(stderr, "Trying to create the event base failed.\n");
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
(void)getdns_extension_set_libevent_base(this_context, this_event_base);
/* Set up the getdns call */
const char * this_name = "www.example.com";
char* this_userarg = "somestring"; // Could add things here to help identify this call
getdns_transaction_t this_transaction_id = 0;
/* Make the call */
getdns_return_t dns_request_return = getdns_address(this_context, this_name,
NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
fprintf(stderr, "A bad domain name was used: %s. Exiting.\n", this_name);
event_base_free(this_event_base);
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
{
/* Call the event loop */
int dispatch_return = event_base_dispatch(this_event_base);
UNUSED_PARAM(dispatch_return);
// TODO: check the return value above
}
/* Clean up */
event_base_free(this_event_base);
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
}

View File

@ -0,0 +1,81 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <getdns_core_only.h>
int main()
{
getdns_return_t this_ret; /* Holder for all function returns */
/* Create the DNS context for this call */
struct getdns_context *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, 1);
if (context_create_return != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to create the context failed: %d\n", context_create_return);
return(GETDNS_RETURN_GENERIC_ERROR);
}
/* Set up the getdns_sync_request call */
const char * this_name = "www.example.com";
uint8_t this_request_type = GETDNS_RRTYPE_A;
/* Get the A and AAAA records */
struct getdns_dict * this_extensions = getdns_dict_create();
this_ret = getdns_dict_set_int(this_extensions, "return_both_v4_and_v6", GETDNS_EXTENSION_TRUE);
if (this_ret != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to set an extension do both IPv4 and IPv6 failed: %d\n", this_ret);
getdns_dict_destroy(this_extensions);
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
struct getdns_dict * this_response = NULL;
/* Make the call */
getdns_return_t dns_request_return = getdns_general_sync(this_context, this_name, this_request_type,
this_extensions, &this_response);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
fprintf(stderr, "A bad domain name was used: %s. Exiting.\n", this_name);
getdns_dict_destroy(this_response);
getdns_dict_destroy(this_extensions);
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
{
/* Be sure the search returned something */
uint32_t this_error;
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.\n", this_error);
getdns_dict_destroy(this_response);
getdns_dict_destroy(this_extensions);
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
struct getdns_list * just_the_addresses_ptr;
this_ret = getdns_dict_get_list(this_response, "just_address_answers", &just_the_addresses_ptr); // Ignore any error
size_t num_addresses;
this_ret = getdns_list_get_length(just_the_addresses_ptr, &num_addresses); // Ignore any error
/* Go through each record */
for ( size_t rec_count = 0; rec_count < num_addresses; ++rec_count )
{
struct getdns_dict * this_address;
this_ret = getdns_list_get_dict(just_the_addresses_ptr, rec_count, &this_address); // Ignore any error
/* Just print the address */
struct getdns_bindata * this_address_data;
this_ret = getdns_dict_get_bindata(this_address, "address_data", &this_address_data); // Ignore any error
char *this_address_str = getdns_display_ip_address(this_address_data);
printf("The address is %s\n", this_address_str);
free(this_address_str);
}
}
/* Clean up */
getdns_dict_destroy(this_response);
getdns_dict_destroy(this_extensions);
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
}

151
src/example/example-tree.c Normal file
View File

@ -0,0 +1,151 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <getdns_libevent.h>
#define UNUSED_PARAM(x) ((void)(x))
/* Set up the callback function, which will also do the processing of the results */
void this_callbackfn(struct getdns_context *this_context,
getdns_return_t this_callback_type,
struct getdns_dict *this_response,
void *this_userarg,
getdns_transaction_t this_transaction_id)
{
UNUSED_PARAM(this_userarg); /* Not looking at the userarg for this example */
UNUSED_PARAM(this_context); /* Not looking at the context for this example */
getdns_return_t this_ret; /* Holder for all function returns */
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) /* This is a callback with data */
{
/* Be sure the search returned something */
uint32_t this_error;
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.\n", this_error);
getdns_dict_destroy(this_response);
return;
}
/* Find all the answers returned */
struct getdns_list * these_answers;
this_ret = getdns_dict_get_list(this_response, "replies_tree", &these_answers);
if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME)
{
fprintf(stderr, "Weird: the response had no error, but also no replies_tree. Exiting.\n");
getdns_dict_destroy(this_response);
return;
}
size_t num_answers;
this_ret = getdns_list_get_length(these_answers, &num_answers);
/* Go through each answer */
for ( size_t rec_count = 0; rec_count < num_answers; ++rec_count )
{
struct getdns_dict * this_record;
this_ret = getdns_list_get_dict(these_answers, rec_count, &this_record); // Ignore any error
/* Get the answer section */
struct getdns_list * this_answer;
this_ret = getdns_dict_get_list(this_record, "answer", &this_answer); // Ignore any error
/* Get each RR in the answer section */
size_t num_rrs;
this_ret = getdns_list_get_length(this_answer, &num_rrs);
for ( size_t rr_count = 0; rr_count < num_rrs; ++rr_count )
{
struct getdns_dict *this_rr = NULL;
this_ret = getdns_list_get_dict(this_answer, rr_count, &this_rr); // Ignore any error
/* Get the RDATA */
struct getdns_dict * this_rdata = NULL;
this_ret = getdns_dict_get_dict(this_rr, "rdata", &this_rdata); // Ignore any error
/* Get the RDATA type */
uint32_t this_type;
this_ret = getdns_dict_get_int(this_rr, "type", &this_type); // Ignore any error
/* If it is type A or AAAA, print the value */
if (this_type == GETDNS_RRTYPE_A)
{
struct getdns_bindata * this_a_record = NULL;
this_ret = getdns_dict_get_bindata(this_rdata, "ipv4_address", &this_a_record);
if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME)
{
fprintf(stderr, "Weird: the A record at %d in record at %d had no address. Exiting.\n",
(int) rr_count, (int) rec_count);
getdns_dict_destroy(this_response);
return;
}
char *this_address_str = getdns_display_ip_address(this_a_record);
printf("The IPv4 address is %s\n", this_address_str);
free(this_address_str);
}
else if (this_type == GETDNS_RRTYPE_AAAA)
{
struct getdns_bindata * this_aaaa_record = NULL;
this_ret = getdns_dict_get_bindata(this_rdata, "ipv6_address", &this_aaaa_record);
if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME)
{
fprintf(stderr, "Weird: the AAAA record at %d in record at %d had no address. Exiting.\n",
(int) rr_count, (int) rec_count);
getdns_dict_destroy(this_response);
return;
}
char *this_address_str = getdns_display_ip_address(this_aaaa_record);
printf("The IPv6 address is %s\n", this_address_str);
free(this_address_str);
}
}
}
}
else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.\n", this_transaction_id);
else
fprintf(stderr, "The callback got a callback_type of %d. Exiting.\n", this_callback_type);
getdns_dict_destroy(this_response);
}
int main()
{
/* Create the DNS context for this call */
struct getdns_context *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, 1);
if (context_create_return != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to create the context failed: %d\n", context_create_return);
return(GETDNS_RETURN_GENERIC_ERROR);
}
/* Create an event base and put it in the context using the unknown function name */
struct event_base *this_event_base;
this_event_base = event_base_new();
if (this_event_base == NULL)
{
fprintf(stderr, "Trying to create the event base failed.\n");
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
(void)getdns_extension_set_libevent_base(this_context, this_event_base);
/* Set up the getdns call */
const char * this_name = "www.example.com";
char* this_userarg = "somestring"; // Could add things here to help identify this call
getdns_transaction_t this_transaction_id = 0;
/* Make the call */
getdns_return_t dns_request_return = getdns_address(this_context, this_name,
NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
fprintf(stderr, "A bad domain name was used: %s. Exiting.\n", this_name);
event_base_free(this_event_base);
getdns_context_destroy(this_context);
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
{
/* Call the event loop */
int dispatch_return = event_base_dispatch(this_event_base);
UNUSED_PARAM(dispatch_return);
// TODO: check the return value above
}
/* Clean up */
event_base_free(this_event_base);
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
}

View File

@ -1,197 +0,0 @@
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <getdns/getdns.h>
#define UNUSED_PARAM(x) ((void)(x))
/* The return values */
getdns_return_t retregular;
char *retcharstar;
/* The args */
bool boolarg;
char *charstararg;
getdns_callback_t callbackarg;
uint16_t regulararg;
uint16_t *regularptrarg;
getdns_transaction_t txidarg;
getdns_transaction_t *txidptrarg;
getdns_data_type *datatypeptrarg;
struct getdns_bindata **bindataptrarg;
struct getdns_dict *dictarg;
struct getdns_bindata *bindataarg;
struct getdns_list *listarg;
struct getdns_dict **dictptrarg;
struct getdns_list **listptrarg;
size_t sizetarg;
size_t *sizetptrarg;
struct getdns_context *contextarg = NULL;
uint8_t uint8arg;
uint16_t uint16arg;
uint32_t uint32arg;
uint8_t *uint8ptrarg;
uint16_t *uint16ptrarg;
uint32_t *uint32ptrarg;
void *arrayarg;
void *
allocfunctionarg(size_t foo)
{
UNUSED_PARAM(foo);
return NULL;
}
void *
reallocfunctionarg(void *foo, size_t bar)
{
UNUSED_PARAM(foo);
UNUSED_PARAM(bar);
return NULL;
}
void
deallocfunctionarg(void *foo)
{
UNUSED_PARAM(foo);
}
void
setcallbackfunctionarg(struct getdns_context *foo1, uint16_t foo2)
{
UNUSED_PARAM(foo1);
UNUSED_PARAM(foo2);
}
int
main()
{
retregular = getdns_general(contextarg,
charstararg,
uint16arg, dictarg, arrayarg, txidptrarg, callbackarg);
retregular = getdns_address(contextarg,
charstararg, dictarg, arrayarg, txidptrarg, callbackarg);
retregular = getdns_hostname(contextarg,
dictarg, dictarg, arrayarg, txidptrarg, callbackarg);
retregular = getdns_service(contextarg,
charstararg, dictarg, arrayarg, txidptrarg, callbackarg);
retregular = getdns_context_create(&contextarg, boolarg);
retregular = getdns_cancel_callback(contextarg, txidarg);
retregular = getdns_general_sync(contextarg,
charstararg, uint16arg, dictarg, &dictarg);
retregular = getdns_address_sync(contextarg,
charstararg, dictarg, &dictarg);
retregular = getdns_hostname_sync(contextarg,
dictarg, dictarg, &dictarg);
retregular = getdns_service_sync(contextarg,
charstararg, dictarg, &dictarg);
retregular = getdns_list_get_length(listarg, sizetptrarg);
retregular =
getdns_list_get_data_type(listarg, sizetarg, datatypeptrarg);
retregular = getdns_list_get_dict(listarg, sizetarg, dictptrarg);
retregular = getdns_list_get_list(listarg, sizetarg, listptrarg);
retregular = getdns_list_get_bindata(listarg, sizetarg, bindataptrarg);
retregular = getdns_list_get_int(listarg, sizetarg, uint32ptrarg);
retregular = getdns_dict_get_names(dictarg, listptrarg);
retregular =
getdns_dict_get_data_type(dictarg, charstararg, datatypeptrarg);
retregular = getdns_dict_get_dict(dictarg, charstararg, dictptrarg);
retregular = getdns_dict_get_list(dictarg, charstararg, listptrarg);
retregular =
getdns_dict_get_bindata(dictarg, charstararg, bindataptrarg);
retregular = getdns_dict_get_int(dictarg, charstararg, uint32ptrarg);
listarg = getdns_list_create();
retregular = getdns_list_set_dict(listarg, sizetarg, dictarg);
retregular = getdns_list_set_list(listarg, sizetarg, listarg);
retregular = getdns_list_set_bindata(listarg, sizetarg, bindataarg);
retregular = getdns_list_set_int(listarg, sizetarg, uint32arg);
dictarg = getdns_dict_create();
retregular = getdns_dict_set_dict(dictarg, charstararg, dictarg);
retregular = getdns_dict_set_list(dictarg, charstararg, listarg);
retregular = getdns_dict_set_bindata(dictarg, charstararg, bindataarg);
retregular = getdns_dict_set_int(dictarg, charstararg, uint32arg);
retcharstar = getdns_pretty_print_dict(dictarg);
retcharstar = getdns_convert_fqdn_to_dns_name(charstararg);
retcharstar = getdns_convert_dns_name_to_fqdn(charstararg);
retcharstar = getdns_convert_ulabel_to_alabel(charstararg);
retcharstar = getdns_convert_alabel_to_ulabel(charstararg);
retregular = getdns_validate_dnssec(bindataarg, listarg, listarg);
retcharstar = getdns_display_ip_address(bindataarg);
retregular = getdns_context_set_context_update_callback(contextarg,
setcallbackfunctionarg);
retregular = getdns_context_set_resolution_type(contextarg,
regulararg);
retregular = getdns_context_set_namespaces(contextarg,
sizetarg, regularptrarg);
retregular = getdns_context_set_dns_transport(contextarg, regulararg);
retregular = getdns_context_set_limit_outstanding_queries(contextarg,
uint16arg);
retregular = getdns_context_set_timeout(contextarg, uint16arg);
retregular = getdns_context_set_follow_redirects(contextarg,
regulararg);
retregular = getdns_context_set_dns_root_servers(contextarg, listarg);
retregular = getdns_context_set_append_name(contextarg, regulararg);
retregular = getdns_context_set_suffix(contextarg, listarg);
retregular = getdns_context_set_dnssec_trust_anchors(contextarg,
listarg);
retregular = getdns_context_set_dnssec_allowed_skew(contextarg,
uint16arg);
retregular = getdns_context_set_stub_resolution(contextarg, listarg);
retregular =
getdns_context_set_edns_maximum_udp_payload_size(contextarg,
uint16arg);
retregular = getdns_context_set_edns_extended_rcode(contextarg,
uint8arg);
retregular = getdns_context_set_edns_version(contextarg, uint8arg);
retregular = getdns_context_set_edns_do_bit(contextarg, uint8arg);
retregular = getdns_context_set_memory_functions(contextarg,
allocfunctionarg, reallocfunctionarg, deallocfunctionarg);
getdns_list_destroy(listarg);
getdns_dict_destroy(dictarg);
getdns_context_destroy(contextarg);
return (0);
} /* End of main() */

View File

@ -1,160 +0,0 @@
/**
* /brief demonstrate asynchronous use of the API for fetching DNS data
*
* Originally taken from the getdns API description pseudo implementation.
*/
/* The MIT License (MIT)
* Copyright (c) 2013 Verisign, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "../config.h"
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <getdns/getdns.h>
#ifdef HAVE_EVENT2_EVENT_H
# include <event2/event.h>
#else
# include <event.h>
#endif
#define UNUSED_PARAM(x) ((void)(x))
/* Set up the callback function, which will also do the processing of the results */
void
this_callbackfn(struct getdns_context *this_context,
uint16_t this_callback_type,
struct getdns_dict *this_response,
void *this_userarg, getdns_transaction_t this_transaction_id)
{
UNUSED_PARAM(this_userarg); /* Not looking at the userarg for this example */
UNUSED_PARAM(this_context); /* Not looking at the context for this example */
getdns_return_t this_ret; /* Holder for all function returns */
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) { /* This is a callback with data */
/* Be sure the search returned something */
uint32_t this_error;
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr,
"The search had no results, and a return value of %d. Exiting.\n",
this_error);
getdns_dict_destroy(this_response);
return;
}
struct getdns_list *just_the_addresses_ptr;
this_ret =
getdns_dict_get_list(this_response, "just_address_answers",
&just_the_addresses_ptr);
if (this_ret != GETDNS_RETURN_GOOD) // This check is really not needed, but prevents a compiler error under "pedantic"
{
fprintf(stderr,
"Trying to get the answers failed: %d\n",
this_ret);
getdns_dict_destroy(this_response);
return;
}
size_t num_addresses = 0;
this_ret = getdns_list_get_length(just_the_addresses_ptr, &num_addresses); // Ignore any error
/* Go through each record */
if (num_addresses == 0) {
fprintf(stderr, "There are no addresses.\n");
getdns_dict_destroy(this_response);
return;
}
for (size_t rec_count = 0; rec_count < num_addresses;
++rec_count) {
struct getdns_bindata *this_address_data;
char *ipAddr = NULL;
this_ret = getdns_list_get_bindata(just_the_addresses_ptr, rec_count, &this_address_data); // Ignore any error
ipAddr = getdns_display_ip_address(this_address_data);
printf("The address is %s\n", ipAddr);
free(ipAddr);
}
} else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr,
"The callback with ID %" PRIu64
" was cancelled. Exiting.\n", this_transaction_id);
else
fprintf(stderr,
"The callback got a callback_type of %d. Exiting.\n",
this_callback_type);
/* clean up */
getdns_dict_destroy(this_response);
}
int
main()
{
/* Create the DNS context for this call */
struct getdns_context *this_context = NULL;
getdns_return_t context_create_return =
getdns_context_create(&this_context, 1);
if (context_create_return != GETDNS_RETURN_GOOD) {
fprintf(stderr, "Trying to create the context failed: %d",
context_create_return);
return (GETDNS_RETURN_GENERIC_ERROR);
}
/* Create an event base and put it in the context using the unknown function name */
struct event_base *this_event_base;
this_event_base = event_base_new();
if (this_event_base == NULL) {
fprintf(stderr, "Trying to create the event base failed.\n");
return (GETDNS_RETURN_GENERIC_ERROR);
}
(void) getdns_extension_set_libevent_base(this_context,
this_event_base);
/* Set up the getdns call */
const char *this_name = "www.example.com";
char *this_userarg = "somestring"; // Could add things here to help identify this call
getdns_transaction_t this_transaction_id = 0;
// getdns_context_set_resolution_type(this_context, GETDNS_CONTEXT_STUB);
/* Make the call */
getdns_return_t dns_request_return =
getdns_address(this_context, this_name,
NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) {
fprintf(stderr, "A bad domain name was used: %s. Exiting.\n",
this_name);
return (GETDNS_RETURN_GENERIC_ERROR);
} else if (dns_request_return != GETDNS_RETURN_GOOD) {
fprintf(stderr, "The context is not setup properly.\n");
return (GETDNS_RETURN_GENERIC_ERROR);
} else {
/* Call the event loop */
int dispatch_return = event_base_dispatch(this_event_base);
UNUSED_PARAM(dispatch_return);
// TODO: check the return value above
}
/* Clean up */
getdns_context_destroy(this_context);
event_base_free(this_event_base);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
} /* main */
/* example-simple-answers.c */

View File

@ -1,118 +0,0 @@
/* example-synchronous.c
*
* Originally taken from the getdns API description pseudo implementation.
*
* The MIT License (MIT)
* Copyright (c) 2013 Verisign, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <getdns/getdns.h>
int
main()
{
getdns_return_t context_create_return;
struct getdns_list *just_the_addresses_ptr;
size_t num_addresses = 0;
size_t rec_count;
struct getdns_bindata *this_address_data;
struct getdns_context *this_context = NULL;
uint32_t this_error = 0;
struct getdns_dict *this_extensions = NULL;
const char *this_name = "www.example.com";
uint8_t this_request_type = GETDNS_RRTYPE_A;
struct getdns_dict *this_response = NULL;
getdns_return_t this_ret;
/* Create the DNS context for this call */
context_create_return = getdns_context_create(&this_context, 1);
if (context_create_return != GETDNS_RETURN_GOOD) {
fprintf(stderr, "Trying to create the context failed: %d",
context_create_return);
return (GETDNS_RETURN_GENERIC_ERROR);
}
/* Set up the getdns_sync_request call */
/* Get the A and AAAA records */
this_extensions = getdns_dict_create();
this_ret =
getdns_dict_set_int(this_extensions, "return_both_v4_and_v6",
GETDNS_EXTENSION_TRUE);
if (this_ret != GETDNS_RETURN_GOOD) {
fprintf(stderr,
"Trying to set an extension do both IPv4 and IPv6 failed: %d",
this_ret);
return (GETDNS_RETURN_GENERIC_ERROR);
}
/* Make the call */
getdns_return_t dns_request_return =
getdns_general_sync(this_context, this_name, this_request_type,
this_extensions, &this_response);
/* free the extensions */
getdns_dict_destroy(this_extensions);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) {
fprintf(stderr, "A bad domain name was used: %s. Exiting.",
this_name);
return (GETDNS_RETURN_GENERIC_ERROR);
} else {
/* Be sure the search returned something */
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr,
"The search had no results, and a return value of %d. Exiting.",
this_error);
return (GETDNS_RETURN_GENERIC_ERROR);
}
this_ret = getdns_dict_get_list(this_response, "just_address_answers", &just_the_addresses_ptr); // Ignore any error
this_ret = getdns_list_get_length(just_the_addresses_ptr, &num_addresses); // Ignore any error
/* Go through each record */
if (num_addresses > 0) {
for (rec_count = 0; rec_count < num_addresses;
++rec_count) {
char *display;
this_ret = getdns_list_get_bindata(just_the_addresses_ptr, rec_count, &this_address_data); // Ignore any error
display =
getdns_display_ip_address
(this_address_data);
/* Just print the address */
printf("The address is %s\n", display);
if (display) {
free(display);
}
}
}
}
/* Clean up */
getdns_context_destroy(this_context);
exit(EXIT_SUCCESS);
} /* main */
/* example-synchronous.c */

View File

@ -1,163 +0,0 @@
#include "../config.h"
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <getdns/getdns.h>
#ifdef HAVE_EVENT2_EVENT_H
# include <event2/event.h>
#else
# include <event.h>
#endif
#define UNUSED_PARAM(x) ((void)(x))
/* Set up the callback function, which will also do the processing of the results */
void
this_callbackfn(struct getdns_context *this_context,
getdns_return_t this_callback_type,
struct getdns_dict *this_response,
void *this_userarg, getdns_transaction_t this_transaction_id)
{
UNUSED_PARAM(this_userarg); /* Not looking at the userarg for this example */
UNUSED_PARAM(this_context); /* Not looking at the context for this example */
getdns_return_t this_ret; /* Holder for all function returns */
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) { /* This is a callback with data */
/* Be sure the search returned something */
uint32_t this_error;
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr,
"The search had no results, and a return value of %d. Exiting.",
this_error);
return;
}
/* Find all the answers returned */
struct getdns_list *these_answers;
this_ret =
getdns_dict_get_list(this_response, "replies_tree",
&these_answers);
if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME) {
fprintf(stderr,
"Weird: the response had no error, but also no replies_tree. Exiting.");
return;
}
size_t num_answers;
this_ret = getdns_list_get_length(these_answers, &num_answers);
/* Go through each answer */
for (size_t rec_count = 0; rec_count < num_answers;
++rec_count) {
struct getdns_dict *this_record;
this_ret = getdns_list_get_dict(these_answers, rec_count, &this_record); // Ignore any error
/* Get the answer section */
struct getdns_list *this_answer;
this_ret = getdns_dict_get_list(this_record, "answer", &this_answer); // Ignore any error
/* Get each RR in the answer section */
size_t num_rrs_ptr;
this_ret =
getdns_list_get_length(this_answer, &num_rrs_ptr);
for (size_t rr_count = 0; rr_count < num_rrs_ptr;
++rr_count) {
struct getdns_dict *this_rr = NULL;
this_ret = getdns_list_get_dict(this_answer, rr_count, &this_rr); // Ignore any error
/* Get the RDATA */
struct getdns_dict *this_rdata = NULL;
this_ret = getdns_dict_get_dict(this_rr, "rdata", &this_rdata); // Ignore any error
/* Get the RDATA type */
uint32_t this_type;
this_ret = getdns_dict_get_int(this_rr, "type", &this_type); // Ignore any error
/* If it is type A or AAAA, print the value */
if (this_type == GETDNS_RRTYPE_A) {
struct getdns_bindata *this_a_record =
NULL;
this_ret =
getdns_dict_get_bindata(this_rdata,
"ipv4_address", &this_a_record);
if (this_ret ==
GETDNS_RETURN_NO_SUCH_DICT_NAME) {
fprintf(stderr,
"Weird: the A record at %d in record at %d had no address. Exiting.",
(int) rr_count,
(int) rec_count);
return;
}
printf("The IPv4 address is %s\n",
getdns_display_ip_address
(this_a_record));
} else if (this_type == GETDNS_RRTYPE_AAAA) {
struct getdns_bindata *this_aaaa_record
= NULL;
this_ret =
getdns_dict_get_bindata(this_rdata,
"ipv6_address", &this_aaaa_record);
if (this_ret ==
GETDNS_RETURN_NO_SUCH_DICT_NAME) {
fprintf(stderr,
"Weird: the AAAA record at %d in record at %d had no address. Exiting.",
(int) rr_count,
(int) rec_count);
return;
}
printf("The IPv6 address is %s\n",
getdns_display_ip_address
(this_aaaa_record));
}
}
}
} else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr,
"The callback with ID %" PRIu64 " was cancelled. Exiting.",
this_transaction_id);
else
fprintf(stderr,
"The callback got a callback_type of %d. Exiting.",
this_callback_type);
}
int
main()
{
/* Create the DNS context for this call */
struct getdns_context *this_context = NULL;
getdns_return_t context_create_return =
getdns_context_create(&this_context, 1);
if (context_create_return != GETDNS_RETURN_GOOD) {
fprintf(stderr, "Trying to create the context failed: %d",
context_create_return);
return (GETDNS_RETURN_GENERIC_ERROR);
}
/* Create an event base and put it in the context using the unknown function name */
struct event_base *this_event_base;
this_event_base = event_base_new();
if (this_event_base == NULL) {
fprintf(stderr, "Trying to create the event base failed.");
return (GETDNS_RETURN_GENERIC_ERROR);
}
(void) getdns_extension_set_libevent_base(this_context,
this_event_base);
/* Set up the getdns call */
const char *this_name = "www.example.com";
char *this_userarg = "somestring"; // Could add things here to help identify this call
getdns_transaction_t this_transaction_id = 0;
/* Make the call */
getdns_return_t dns_request_return =
getdns_address(this_context, this_name,
NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) {
fprintf(stderr, "A bad domain name was used: %s. Exiting.",
this_name);
return (GETDNS_RETURN_GENERIC_ERROR);
} else {
/* Call the event loop */
int dispatch_return = event_base_dispatch(this_event_base);
UNUSED_PARAM(dispatch_return);
// TODO: check the return value above
}
/* Clean up */
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
}

View File

@ -0,0 +1 @@
#include <getdns/getdns.h>

View File

@ -0,0 +1,6 @@
#include <getdns/getdns.h>
#ifdef HAVE_EVENT2_EVENT_H
#include <event2/event.h>
#else
#include <event.h>
#endif

View File

@ -53,25 +53,25 @@ struct event_base;
#define GETDNS_RETURN_GENERIC_ERROR 1
#define GETDNS_RETURN_GENERIC_ERROR_TEXT "Generic error"
#define GETDNS_RETURN_BAD_DOMAIN_NAME 300
#define GETDNS_RETURN_BAD_DOMAIN_NAME_TEXT "Badly-formed domain name"
#define GETDNS_RETURN_BAD_DOMAIN_NAME_TEXT "Badly-formed domain name in first argument"
#define GETDNS_RETURN_BAD_CONTEXT 301
#define GETDNS_RETURN_BAD_CONTEXT_TEXT "Bad context type"
#define GETDNS_RETURN_BAD_CONTEXT_TEXT "Bad value for a context type"
#define GETDNS_RETURN_CONTEXT_UPDATE_FAIL 302
#define GETDNS_RETURN_CONTEXT_UPDATE_FAIL_TEXT "Context update failure"
#define GETDNS_RETURN_CONTEXT_UPDATE_FAIL_TEXT "Did not update the context"
#define GETDNS_RETURN_UNKNOWN_TRANSACTION 303
#define GETDNS_RETURN_UNKNOWN_TRANSACTION_TEXT "Unknown transaction id"
#define GETDNS_RETURN_UNKNOWN_TRANSACTION_TEXT "An attempt was made to cancel a callback with a transaction_id that is not recognized"
#define GETDNS_RETURN_NO_SUCH_LIST_ITEM 304
#define GETDNS_RETURN_NO_SUCH_LIST_ITEM_TEXT "List index out of bounds"
#define GETDNS_RETURN_NO_SUCH_LIST_ITEM_TEXT "A helper function for lists had an index argument that was too high."
#define GETDNS_RETURN_NO_SUCH_DICT_NAME 305
#define GETDNS_RETURN_NO_SUCH_DICT_NAME_TEXT "Key not found in dict"
#define GETDNS_RETURN_NO_SUCH_DICT_NAME_TEXT "A helper function for dicts had a name argument that for a name that is not in the dict."
#define GETDNS_RETURN_WRONG_TYPE_REQUESTED 306
#define GETDNS_RETURN_WRONG_TYPE_REQUESTED_TEXT "Incorrect type in request"
#define GETDNS_RETURN_WRONG_TYPE_REQUESTED_TEXT "A helper function was supposed to return a certain type for an item, but the wrong type was given."
#define GETDNS_RETURN_NO_SUCH_EXTENSION 307
#define GETDNS_RETURN_NO_SUCH_EXTENSION_TEXT "Invalid extension name"
#define GETDNS_RETURN_NO_SUCH_EXTENSION_TEXT "A name in the extensions dict is not a valid extension."
#define GETDNS_RETURN_EXTENSION_MISFORMAT 308
#define GETDNS_RETURN_EXTENSION_MISFORMAT_TEXT "Extension format error"
#define GETDNS_RETURN_EXTENSION_MISFORMAT_TEXT "One or more of the extensions is has a bad format."
#define GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED 309
#define GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED_TEXT "Query with DNSSEC extensions and stub resolution not permitted"
#define GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED_TEXT "A query was made with a context that is using stub resolution and a DNSSEC extension specified."
#define GETDNS_RETURN_MEMORY_ERROR 310
#define GETDNS_RETURN_MEMORY_ERROR_TEXT "Unable to allocate the memory required."
/** @}

File diff suppressed because it is too large Load Diff

View File

@ -34,33 +34,36 @@ getdns_lookup_table getdns_error_str[] = {
,
{GETDNS_RETURN_GENERIC_ERROR, "Generic error"}
,
{GETDNS_RETURN_BAD_DOMAIN_NAME, "Badly-formed domain name"}
{GETDNS_RETURN_BAD_DOMAIN_NAME, "Badly-formed domain name in first argument"}
,
{GETDNS_RETURN_BAD_CONTEXT, "Bad context type"}
{GETDNS_RETURN_BAD_CONTEXT, "Bad value for a context type"}
,
{GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Context update failure"}
{GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Did not update the context"}
,
{GETDNS_RETURN_UNKNOWN_TRANSACTION,
"Unknown transaction id"}
"An attempt was made to cancel a callback with a transaction_id that is not recognized"}
,
{GETDNS_RETURN_NO_SUCH_LIST_ITEM,
"List index out of bounds"}
"A helper function for lists had an index argument that was too high."}
,
{GETDNS_RETURN_NO_SUCH_DICT_NAME,
"Key not found in dict"}
"A helper function for dicts had a name argument that for a name that is not in the dict."}
,
{GETDNS_RETURN_WRONG_TYPE_REQUESTED,
"Incorrect type in request"}
"A helper function was supposed to return a certain type for an item, but the wrong type was given."}
,
{GETDNS_RETURN_NO_SUCH_EXTENSION,
"Invalid extension name"}
"A name in the extensions dict is not a valid extension."}
,
{GETDNS_RETURN_EXTENSION_MISFORMAT,
"Extension format error"}
"One or more of the extensions is has a bad format."}
,
{GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED,
"Query with DNSSEC extensions andstub resolution not permitted"}
"A query was made with a context that is using stub resolution and a DNSSEC extension specified."}
,
{GETDNS_RETURN_MEMORY_ERROR,
"Unable to allocate the memory required."}
,
{0, ""}
};

View File

@ -64,18 +64,22 @@ getdns_hostname(struct getdns_context *context,
&address_type)) != GETDNS_RETURN_GOOD)
return retval;
if ((strncmp(GETDNS_STR_IPV4, (char *) address_type->data,
strlen(GETDNS_STR_IPV4)) == 0)
( strlen(GETDNS_STR_IPV4) < address_type->size
? strlen(GETDNS_STR_IPV4) : address_type->size )) == 0
&& address_data->size == 4)
|| (strncmp(GETDNS_STR_IPV6, (char *) address_type->data,
strlen(GETDNS_STR_IPV6)) == 0))
( strlen(GETDNS_STR_IPV6) < address_type->size
? strlen(GETDNS_STR_IPV6) : address_type->size )) == 0
&& address_data->size == 16))
req_type = GETDNS_RRTYPE_PTR;
else
return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
if ((name = reverse_address((char *) address_data->data)) == 0)
if ((name = reverse_address(address_data)) == NULL)
return GETDNS_RETURN_GENERIC_ERROR;
return getdns_general(context, name, req_type, extensions,
retval = getdns_general(context, name, req_type, extensions,
userarg, transaction_id, callback);
return GETDNS_RETURN_GOOD;
free(name);
return retval;
} /* getdns_hostname */
/* getdns_hostname.c */

View File

@ -58,6 +58,9 @@ getdns_list_get_data_type(struct getdns_list * list, size_t index,
if (!list || index >= list->numinuse)
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if (!answer)
return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
*answer = list->items[index].dtype;
return GETDNS_RETURN_GOOD;
} /* getdns_list_get_data_type */
@ -70,7 +73,7 @@ getdns_list_get_dict(struct getdns_list * list, size_t index,
if (!list || index >= list->numinuse)
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if (list->items[index].dtype != t_dict)
if (!answer || list->items[index].dtype != t_dict)
return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
*answer = list->items[index].data.dict;
@ -86,7 +89,7 @@ getdns_list_get_list(struct getdns_list * list, size_t index,
if (!list || index >= list->numinuse)
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if (list->items[index].dtype != t_list)
if (!answer || list->items[index].dtype != t_list)
return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
*answer = list->items[index].data.list;
@ -101,7 +104,7 @@ getdns_list_get_bindata(struct getdns_list * list, size_t index,
if (!list || index >= list->numinuse)
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if (list->items[index].dtype != t_bindata)
if (!answer || list->items[index].dtype != t_bindata)
return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
*answer = list->items[index].data.bindata;
@ -115,7 +118,7 @@ getdns_list_get_int(struct getdns_list * list, size_t index, uint32_t * answer)
if (!list || index >= list->numinuse)
return GETDNS_RETURN_NO_SUCH_LIST_ITEM;
if (list->items[index].dtype != t_int)
if (!answer || list->items[index].dtype != t_int)
return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
*answer = list->items[index].data.n;

View File

@ -126,16 +126,22 @@ getdns_hostname_sync(struct getdns_context *context,
&address_type)) != GETDNS_RETURN_GOOD)
return retval;
if ((strncmp(GETDNS_STR_IPV4, (char *) address_type->data,
strlen(GETDNS_STR_IPV4)) == 0)
( strlen(GETDNS_STR_IPV4) < address_type->size
? strlen(GETDNS_STR_IPV4) : address_type->size )) == 0
&& address_data->size == 4)
|| (strncmp(GETDNS_STR_IPV6, (char *) address_type->data,
strlen(GETDNS_STR_IPV6)) == 0))
( strlen(GETDNS_STR_IPV6) < address_type->size
? strlen(GETDNS_STR_IPV6) : address_type->size )) == 0
&& address_data->size == 16))
req_type = GETDNS_RRTYPE_PTR;
else
return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
if ((name = reverse_address((char *) address_data)) == 0)
if ((name = reverse_address(address_data)) == NULL)
return GETDNS_RETURN_GENERIC_ERROR;
return getdns_general_sync(context, name, req_type, extensions,
retval = getdns_general_sync(context, name, req_type, extensions,
response);
free(name);
return retval;
}
getdns_return_t

View File

@ -48,7 +48,6 @@ this_callbackfn(struct getdns_context *this_context,
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) { /* This is a callback with data */
char *res = getdns_pretty_print_dict(this_response);
fprintf(stdout, "%s\n", res);
getdns_dict_destroy(this_response);
free(res);
} else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
@ -59,6 +58,7 @@ this_callbackfn(struct getdns_context *this_context,
fprintf(stderr,
"The callback got a callback_type of %d. Exiting.",
this_callback_type);
getdns_dict_destroy(this_response);
}
int
@ -81,6 +81,7 @@ main(int argc, char** argv)
this_event_base = event_base_new();
if (this_event_base == NULL) {
fprintf(stderr, "Trying to create the event base failed.");
getdns_context_destroy(this_context);
return (GETDNS_RETURN_GENERIC_ERROR);
}
(void) getdns_extension_set_libevent_base(this_context,
@ -97,6 +98,8 @@ main(int argc, char** argv)
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME) {
fprintf(stderr, "A bad domain name was used: %s. Exiting.",
this_name);
event_base_free(this_event_base);
getdns_context_destroy(this_context);
return (GETDNS_RETURN_GENERIC_ERROR);
}
// dns_request_return = getdns_service(this_context, this_name, NULL, this_userarg, &this_transaction_id,
@ -112,6 +115,7 @@ main(int argc, char** argv)
// TODO: check the return value above
}
/* Clean up */
event_base_free(this_event_base);
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);

View File

@ -38,6 +38,7 @@
#include "getdns/getdns.h"
#include <ldns/rbtree.h>
#include "dict.h"
#include "list.h"
#include "util-internal.h"
#include "types-internal.h"
@ -47,7 +48,7 @@
* The list has to be in sorted order for bsearch lookup in function
* validate_extensions.
*/
getdns_extension_format extformats[] = {
static getdns_extension_format extformats[] = {
{"add_opt_parameters", t_dict},
{"add_warning_for_bad_dns", t_int},
{"dnssec_return_only_secure", t_int},
@ -59,6 +60,9 @@ getdns_extension_format extformats[] = {
{"specify_class", t_int},
};
static struct getdns_bindata IPv4_str_bindata = { 5, (void *)"IPv4" };
static struct getdns_bindata IPv6_str_bindata = { 5, (void *)"IPv6" };
getdns_return_t
getdns_dict_util_set_string(struct getdns_dict * dict, char *name, const char *value)
{
@ -336,23 +340,43 @@ create_list_from_rr_list(struct getdns_context *context, ldns_rr_list * rr_list)
static getdns_return_t
add_only_addresses(struct getdns_list * addrs, ldns_rr_list * rr_list)
{
int r = 0;
int r = GETDNS_RETURN_GOOD;
size_t i = 0;
for (i = 0; i < ldns_rr_list_rr_count(rr_list); ++i) {
size_t item_idx = 0;
r = getdns_list_get_length(addrs, &item_idx);
for (i = 0; r == GETDNS_RETURN_GOOD &&
i < ldns_rr_list_rr_count(rr_list); ++i) {
ldns_rr *rr = ldns_rr_list_rr(rr_list, i);
size_t j = 0;
size_t rd_count = ldns_rr_rd_count(rr);
for (j = 0; j < rd_count; ++j) {
size_t item_idx = 0;
for (j = 0; r == GETDNS_RETURN_GOOD && j < rd_count; ++j) {
ldns_rdf *rdf = ldns_rr_rdf(rr, j);
if (ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_A ||
ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_AAAA) {
struct getdns_bindata rbin =
{ ldns_rdf_size(rdf), ldns_rdf_data(rdf) };
r |= getdns_list_add_item(addrs, &item_idx);
r |= getdns_list_set_bindata(addrs, item_idx,
&rbin);
if (ldns_rdf_get_type(rdf) != LDNS_RDF_TYPE_A &&
ldns_rdf_get_type(rdf) != LDNS_RDF_TYPE_AAAA) {
continue;
}
struct getdns_dict *this_address =
getdns_dict_create_with_extended_memory_functions(
addrs->mf.mf_arg,
addrs->mf.mf.ext.malloc,
addrs->mf.mf.ext.realloc,
addrs->mf.mf.ext.free);
if (this_address == NULL) {
r |= GETDNS_RETURN_MEMORY_ERROR;
break;
}
struct getdns_bindata rbin =
{ ldns_rdf_size(rdf), ldns_rdf_data(rdf) };
r |= getdns_dict_set_bindata(this_address,
GETDNS_STR_ADDRESS_TYPE,
( ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_A
? &IPv4_str_bindata : &IPv6_str_bindata));
r |= getdns_dict_set_bindata(this_address,
GETDNS_STR_ADDRESS_DATA, &rbin);
r |= getdns_list_set_dict(addrs, item_idx++,
this_address);
getdns_dict_destroy(this_address);
}
}
return r;
@ -559,26 +583,28 @@ create_getdns_response(struct getdns_dns_req * completed_request)
/**
* reverse an IP address for PTR lookup
* @param addr_str dotted notation of IP address to reverse
* @param address_data IP address to reverse
* @return NULL on allocation failure
* @return reversed string on success, caller must free storage via call to free()
*/
char *
reverse_address(char *addr_str)
reverse_address(struct getdns_bindata *address_data)
{
ldns_rdf *addr_rdf;
ldns_rdf *rev_rdf;
char *rev_str;
addr_rdf = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_A, addr_str);
if (!addr_rdf) {
addr_rdf = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_AAAA, addr_str);
if (!addr_rdf)
return NULL;
}
if (address_data->size == 4)
addr_rdf = ldns_rdf_new(LDNS_RDF_TYPE_A, 4, address_data->data);
else if (address_data->size == 16)
addr_rdf = ldns_rdf_new(LDNS_RDF_TYPE_AAAA, 16, address_data->data);
else
return NULL;
if (!addr_rdf)
return NULL;
rev_rdf = ldns_rdf_address_reverse(addr_rdf);
ldns_rdf_deep_free(addr_rdf);
ldns_rdf_free(addr_rdf);
if (!rev_rdf)
return NULL;

View File

@ -94,7 +94,7 @@ getdns_return_t getdns_dict_util_set_string(struct getdns_dict * dict, char *nam
/* get a string from a dict. result is valid as long as dict is valid */
getdns_return_t getdns_dict_util_get_string(struct getdns_dict * dict, char *name,
char **result);
char *reverse_address(char *addr_str);
char *reverse_address(struct getdns_bindata *address_data);
/**
* detect unrecognized extension strings or invalid extension formats