summaryrefslogtreecommitdiff
path: root/lib/libc/asr/res_send_async.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/asr/res_send_async.c')
-rw-r--r--lib/libc/asr/res_send_async.c90
1 files changed, 25 insertions, 65 deletions
diff --git a/lib/libc/asr/res_send_async.c b/lib/libc/asr/res_send_async.c
index cab78a3dc3d..20cc6ff695d 100644
--- a/lib/libc/asr/res_send_async.c
+++ b/lib/libc/asr/res_send_async.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_send_async.c,v 1.2 2012/07/07 20:41:52 eric Exp $ */
+/* $OpenBSD: res_send_async.c,v 1.3 2012/09/09 09:42:06 eric Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -58,12 +58,8 @@ res_send_async(const unsigned char *buf, int buflen, unsigned char *ans,
struct header h;
struct query q;
-#ifdef DEBUG
- if (asr_debug) {
- asr_printf("asr: res_send_async()\n");
- asr_dump_packet(stderr, buf, buflen, 0);
- }
-#endif
+ DPRINT_PACKET("asr: res_send_async()", buf, buflen);
+
ac = asr_use_resolver(asr);
if ((as = async_new(ac, ASR_SEND)) == NULL) {
asr_ctx_unref(ac);
@@ -122,9 +118,9 @@ res_query_async(const char *name, int class, int type, unsigned char *ans,
{
struct asr_ctx *ac;
struct async *as;
-#ifdef DEBUG
- asr_printf("asr: res_query_async(\"%s\", %i, %i)\n", name, class, type);
-#endif
+
+ DPRINT("asr: res_query_async(\"%s\", %i, %i)\n", name, class, type);
+
ac = asr_use_resolver(asr);
as = res_query_async_ctx(name, class, type, ans, anslen, ac);
asr_ctx_unref(ac);
@@ -138,10 +134,8 @@ res_query_async_ctx(const char *name, int class, int type, unsigned char *ans,
{
struct async *as;
-#ifdef DEBUG
- asr_printf("asr: res_query_async_ctx(\"%s\", %i, %i)\n", name, class,
- type);
-#endif
+ DPRINT("asr: res_query_async_ctx(\"%s\", %i, %i)\n", name, class, type);
+
if ((as = async_new(a_ctx, ASR_SEND)) == NULL)
return (NULL); /* errno set */
as->as_run = res_send_async_run;
@@ -378,25 +372,19 @@ setup_query(struct async *as, const char *name, const char *dom,
if (as->as.dns.flags & ASYNC_EXTOBUF) {
errno = EINVAL;
-#ifdef DEBUG
- asr_printf("attempting to write in user packet");
-#endif
+ DPRINT("attempting to write in user packet");
return (-1);
}
if (asr_make_fqdn(name, dom, fqdn, sizeof(fqdn)) > sizeof(fqdn)) {
errno = EINVAL;
-#ifdef DEBUG
- asr_printf("asr_make_fqdn: name too long\n");
-#endif
+ DPRINT("asr_make_fqdn: name too long\n");
return (-1);
}
if (dname_from_fqdn(fqdn, dname, sizeof(dname)) == -1) {
errno = EINVAL;
-#ifdef DEBUG
- asr_printf("dname_from_fqdn: invalid\n");
-#endif
+ DPRINT("dname_from_fqdn: invalid\n");
return (-1);
}
@@ -418,9 +406,7 @@ setup_query(struct async *as, const char *name, const char *dom,
pack_header(&p, &h);
pack_query(&p, type, class, dname);
if (p.err) {
-#ifdef DEBUG
- asr_printf("error packing query");
-#endif
+ DPRINT("error packing query");
errno = EINVAL;
return (-1);
}
@@ -433,20 +419,12 @@ setup_query(struct async *as, const char *name, const char *dom,
free(as->as.dns.dname);
as->as.dns.dname = strdup(dname);
if (as->as.dns.dname == NULL) {
-#ifdef DEBUG
- asr_printf("strdup");
-#endif
+ DPRINT("strdup");
return (-1); /* errno set */
}
as->as.dns.obuflen = p.offset;
-#ifdef DEBUG
- if (asr_debug) {
- asr_printf("------- asr_setup_query(): packet -------\n");
- asr_dump_packet(stderr, as->as.dns.obuf, as->as.dns.obuflen, 0);
- asr_printf("-----------------------------------------\n");
- }
-#endif
+ DPRINT_PACKET("asr_setup_query", as->as.dns.obuf, as->as.dns.obuflen);
return (0);
}
@@ -463,11 +441,11 @@ udp_send(struct async *as)
int save_errno;
#ifdef DEBUG
char buf[256];
-
- if (asr_debug)
- asr_printf("asr: [%p] connecting to %s UDP\n", as,
- asr_print_addr(AS_NS_SA(as), buf, sizeof buf));
#endif
+
+ DPRINT("asr: [%p] connecting to %s UDP\n", as,
+ asr_print_addr(AS_NS_SA(as), buf, sizeof buf));
+
as->as_fd = sockaddr_connect(AS_NS_SA(as), SOCK_DGRAM);
if (as->as_fd == -1)
return (-1); /* errno set */
@@ -518,13 +496,7 @@ udp_recv(struct async *as)
as->as.dns.ibuflen = n;
-#ifdef DEBUG
- if (asr_debug) {
- asr_printf("------- asr_udp_recv() packet -------\n");
- asr_dump_packet(stderr, as->as.dns.ibuf, as->as.dns.ibuflen, 0);
- asr_printf("-------------------------------------\n");
- }
-#endif
+ DPRINT_PACKET("asr_udp_recv()", as->as.dns.ibuf, as->as.dns.ibuflen);
if (validate_packet(as) == -1)
return (-1); /* errno set */
@@ -552,11 +524,8 @@ tcp_write(struct async *as)
/* First try to connect if not already */
if (as->as_fd == -1) {
-#ifdef DEBUG
- if (asr_debug)
- asr_printf("asr: [%p] connecting to %s TCP\n", as,
- asr_print_addr(AS_NS_SA(as), buf, sizeof buf));
-#endif
+ DPRINT("asr: [%p] connecting to %s TCP\n", as,
+ asr_print_addr(AS_NS_SA(as), buf, sizeof buf));
as->as_fd = sockaddr_connect(AS_NS_SA(as), SOCK_STREAM);
if (as->as_fd == -1)
return (-1); /* errno set */
@@ -675,13 +644,8 @@ tcp_read(struct async *as)
if (as->as.dns.ibuflen != as->as.dns.datalen)
return (1);
-#ifdef DEBUG
- if (asr_debug) {
- asr_printf("------- asr_tcp_read() packet -------\n");
- asr_dump_packet(stderr, as->as.dns.ibuf, as->as.dns.ibuflen, 0);
- asr_printf("-------------------------------------\n");
- }
-#endif
+ DPRINT_PACKET("asr_tcp_read()", as->as.dns.ibuf, as->as.dns.ibuflen);
+
if (validate_packet(as) == -1)
goto close; /* errno set */
@@ -751,9 +715,7 @@ validate_packet(struct async *as)
goto inval;
if (h.id != as->as.dns.reqid) {
-#ifdef DEBUG
- asr_printf("incorrect reqid\n");
-#endif
+ DPRINT("incorrect reqid\n");
goto inval;
}
if (h.qdcount != 1)
@@ -778,10 +740,8 @@ validate_packet(struct async *as)
if (q.q_type != as->as.dns.type ||
q.q_class != as->as.dns.class ||
strcasecmp(q.q_dname, as->as.dns.dname)) {
-#ifdef DEBUG
- asr_printf("incorrect type/class/dname '%s' != '%s'\n",
+ DPRINT("incorrect type/class/dname '%s' != '%s'\n",
q.q_dname, as->as.dns.dname);
-#endif
goto inval;
}