summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2012-07-11 16:49:13 +0000
committerEric Faurot <eric@cvs.openbsd.org>2012-07-11 16:49:13 +0000
commit9c7fd97e2271d92e7b9291b1706c2713f6484585 (patch)
tree98649df77a6adf4147d045f371fc472b13db139b /lib/libc
parent6bd7e6c37970208b6213d5ed329d66062a502511 (diff)
implement res_mkquery
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/asr/asr_resolver.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/lib/libc/asr/asr_resolver.c b/lib/libc/asr/asr_resolver.c
index 6d49dd31ab1..a44a9735327 100644
--- a/lib/libc/asr/asr_resolver.c
+++ b/lib/libc/asr/asr_resolver.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asr_resolver.c,v 1.3 2012/07/08 17:01:06 eric Exp $ */
+/* $OpenBSD: asr_resolver.c,v 1.4 2012/07/11 16:49:12 eric Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -24,6 +24,7 @@
#include <string.h>
#include "asr.h"
+#include "asr_private.h"
/*
* XXX this function is actually internal to asr, but we use it here to force
@@ -140,6 +141,51 @@ res_querydomain(const char *name,
return (res_query(fqdn, class, type, answer, anslen));
}
+/* This function is apparently needed by some ports. */
+int
+res_mkquery(int op, const char *dname, int class, int type,
+ const unsigned char *data, int datalen, const unsigned char *newrr,
+ unsigned char *buf, int buflen)
+{
+ struct asr_ctx *ac;
+ struct packed p;
+ struct header h;
+ char fqdn[MAXDNAME];
+ char dn[MAXDNAME];
+
+ /* we currently only support QUERY */
+ if (op != QUERY || data)
+ return (-1);
+
+ if (dname[0] == '\0' || dname[strlen(dname) - 1] != '.') {
+ strlcpy(fqdn, dname, sizeof fqdn);
+ if (strlcat(fqdn, ".", sizeof fqdn) >= sizeof fqdn)
+ return (-1);
+ dname = fqdn;
+ }
+
+ if (dname_from_fqdn(dname, dn, sizeof(dn)) == -1)
+ return (-1);
+
+ ac = asr_use_resolver(NULL);
+
+ h.id = res_randomid();
+ if (ac->ac_options & RES_RECURSE)
+ h.flags |= RD_MASK;
+ h.qdcount = 1;
+
+ packed_init(&p, buf, buflen);
+ pack_header(&p, &h);
+ pack_query(&p, type, class, dn);
+
+ asr_ctx_unref(ac);
+
+ if (p.err)
+ return (-1);
+
+ return (p.offset);
+}
+
int
res_search(const char *name, int class, int type, u_char *ans, int anslen)
{