Skip to content

Commit

Permalink
lib-dns: Compose final command in dns_client_lookup_common
Browse files Browse the repository at this point in the history
Makes logging easier
  • Loading branch information
cmouse authored and villesavolainen committed Nov 13, 2018
1 parent 267979d commit 5d36bcd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/lib-dns/dns-lookup.c
Expand Up @@ -2,6 +2,7 @@

#include "lib.h"
#include "ioloop.h"
#include "str.h"
#include "ostream.h"
#include "connection.h"
#include "llist.h"
Expand Down Expand Up @@ -345,7 +346,7 @@ dns_client_send_request(struct dns_client *client, const char *cmd,

static int
dns_client_lookup_common(struct dns_client *client,
const char *cmd, bool ptr_lookup,
const char *cmd, const char *param, bool ptr_lookup,
dns_lookup_callback_t *callback, void *context,
struct dns_lookup **lookup_r)
{
Expand All @@ -355,6 +356,8 @@ dns_client_lookup_common(struct dns_client *client,

i_zero(&result);
result.ret = EAI_FAIL;
i_assert(param != NULL && *param != '\0');
cmd = t_strdup_printf("%s\t%s\n", cmd, param);

if ((ret = dns_client_send_request(client, cmd, &result.error)) <= 0) {
if (ret == 0) {
Expand Down Expand Up @@ -391,17 +394,15 @@ int dns_client_lookup(struct dns_client *client, const char *host,
dns_lookup_callback_t *callback, void *context,
struct dns_lookup **lookup_r)
{
const char *cmd = t_strconcat("IP\t", host, "\n", NULL);
return dns_client_lookup_common(client, cmd, FALSE,
return dns_client_lookup_common(client, "IP", host, FALSE,
callback, context, lookup_r);
}

int dns_client_lookup_ptr(struct dns_client *client, const struct ip_addr *ip,
dns_lookup_callback_t *callback, void *context,
struct dns_lookup **lookup_r)
{
const char *cmd = t_strconcat("NAME\t", net_ip2addr(ip), "\n", NULL);
return dns_client_lookup_common(client, cmd, TRUE,
return dns_client_lookup_common(client, "NAME", net_ip2addr(ip), TRUE,
callback, context, lookup_r);
}

Expand Down

0 comments on commit 5d36bcd

Please sign in to comment.