mirror of https://github.com/getdnsapi/getdns.git
Get rid of ldns usage, and a malloc/free
This commit is contained in:
parent
c02f895358
commit
ebb519919a
|
@ -286,7 +286,7 @@ priv_getdns_hostname_loop(getdns_context *context, getdns_eventloop *loop,
|
|||
struct getdns_bindata *address_data;
|
||||
struct getdns_bindata *address_type;
|
||||
uint16_t req_type;
|
||||
char *name;
|
||||
char name[1024];
|
||||
getdns_return_t retval;
|
||||
|
||||
if ((retval =
|
||||
|
@ -308,11 +308,60 @@ priv_getdns_hostname_loop(getdns_context *context, getdns_eventloop *loop,
|
|||
req_type = GETDNS_RRTYPE_PTR;
|
||||
else
|
||||
return GETDNS_RETURN_INVALID_PARAMETER;
|
||||
if ((name = reverse_address(address_data)) == NULL)
|
||||
|
||||
switch (address_data->size) {
|
||||
case 4:
|
||||
(void)snprintf(name, sizeof(name),
|
||||
"%hhu.%hhu.%hhu.%hhu.in-addr.arpa.",
|
||||
((uint8_t *)address_data->data)[3],
|
||||
((uint8_t *)address_data->data)[2],
|
||||
((uint8_t *)address_data->data)[1],
|
||||
((uint8_t *)address_data->data)[0]);
|
||||
break;
|
||||
case 16:
|
||||
(void)snprintf(name, sizeof(name),
|
||||
"%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx."
|
||||
"%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx."
|
||||
"%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx."
|
||||
"%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.ip6.arpa.",
|
||||
((uint8_t *)address_data->data)[15] & 0x0F,
|
||||
((uint8_t *)address_data->data)[15] >> 4,
|
||||
((uint8_t *)address_data->data)[14] & 0x0F,
|
||||
((uint8_t *)address_data->data)[14] >> 4,
|
||||
((uint8_t *)address_data->data)[13] & 0x0F,
|
||||
((uint8_t *)address_data->data)[13] >> 4,
|
||||
((uint8_t *)address_data->data)[12] & 0x0F,
|
||||
((uint8_t *)address_data->data)[12] >> 4,
|
||||
((uint8_t *)address_data->data)[11] & 0x0F,
|
||||
((uint8_t *)address_data->data)[11] >> 4,
|
||||
((uint8_t *)address_data->data)[10] & 0x0F,
|
||||
((uint8_t *)address_data->data)[10] >> 4,
|
||||
((uint8_t *)address_data->data)[9] & 0x0F,
|
||||
((uint8_t *)address_data->data)[9] >> 4,
|
||||
((uint8_t *)address_data->data)[8] & 0x0F,
|
||||
((uint8_t *)address_data->data)[8] >> 4,
|
||||
((uint8_t *)address_data->data)[7] & 0x0F,
|
||||
((uint8_t *)address_data->data)[7] >> 4,
|
||||
((uint8_t *)address_data->data)[6] & 0x0F,
|
||||
((uint8_t *)address_data->data)[6] >> 4,
|
||||
((uint8_t *)address_data->data)[5] & 0x0F,
|
||||
((uint8_t *)address_data->data)[5] >> 4,
|
||||
((uint8_t *)address_data->data)[4] & 0x0F,
|
||||
((uint8_t *)address_data->data)[4] >> 4,
|
||||
((uint8_t *)address_data->data)[3] & 0x0F,
|
||||
((uint8_t *)address_data->data)[3] >> 4,
|
||||
((uint8_t *)address_data->data)[2] & 0x0F,
|
||||
((uint8_t *)address_data->data)[2] >> 4,
|
||||
((uint8_t *)address_data->data)[1] & 0x0F,
|
||||
((uint8_t *)address_data->data)[1] >> 4,
|
||||
((uint8_t *)address_data->data)[0] & 0x0F,
|
||||
((uint8_t *)address_data->data)[0] >> 4);
|
||||
break;
|
||||
default:
|
||||
return GETDNS_RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
retval = priv_getdns_general_loop(context, loop, name, req_type,
|
||||
extensions, userarg, transaction_id, callback);
|
||||
free(name);
|
||||
return retval;
|
||||
} /* getdns_hostname_loop */
|
||||
|
||||
|
|
|
@ -848,38 +848,6 @@ error_free_result:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* reverse an IP address for PTR lookup
|
||||
* @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(struct getdns_bindata *address_data)
|
||||
{
|
||||
ldns_rdf *addr_rdf;
|
||||
ldns_rdf *rev_rdf;
|
||||
char *rev_str;
|
||||
|
||||
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_free(addr_rdf);
|
||||
if (!rev_rdf)
|
||||
return NULL;
|
||||
|
||||
rev_str = ldns_rdf2str(rev_rdf);
|
||||
ldns_rdf_deep_free(rev_rdf);
|
||||
return rev_str;
|
||||
}
|
||||
|
||||
static int
|
||||
extformatcmp(const void *a, const void *b)
|
||||
{
|
||||
|
|
|
@ -122,7 +122,6 @@ getdns_return_t sockaddr_to_dict(struct getdns_context *context,
|
|||
|
||||
struct getdns_dns_req;
|
||||
struct getdns_dict *create_getdns_response(struct getdns_dns_req *completed_request);
|
||||
char *reverse_address(struct getdns_bindata *address_data);
|
||||
|
||||
getdns_return_t validate_dname(const char* dname);
|
||||
|
||||
|
|
Loading…
Reference in New Issue