summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rfc1035/rfc1035.h11
-rw-r--r--rfc1035/rfc1035resolve.c5
-rw-r--r--rfc1035/rfc1035udp.c49
3 files changed, 51 insertions, 14 deletions
diff --git a/rfc1035/rfc1035.h b/rfc1035/rfc1035.h
index 2123c2a..ee85101 100644
--- a/rfc1035/rfc1035.h
+++ b/rfc1035/rfc1035.h
@@ -616,6 +616,13 @@ void rfc1035_ifconf_free(struct rfc1035_ifconf *ifconf_list);
** Outstanding UDP queries.
*/
+ /* common query buffer */
+
+struct querybuf {
+ char qbuf[512];
+ unsigned qbuflen;
+ } ;
+
struct rfc1035_udp_query_response;
/* How many queries, and the queries */
@@ -645,6 +652,10 @@ rfc1035_udp_query_response_alloc(const char **queries,
const unsigned *querylens,
int n_queries);
+struct rfc1035_udp_query_responses *
+rfc1035_udp_query_response_alloc_bis(struct querybuf *queries,
+ int n_queries);
+
/*
** Send all queries via UDPs, wait for responses.
**
diff --git a/rfc1035/rfc1035resolve.c b/rfc1035/rfc1035resolve.c
index b8bb91f..850fdbd 100644
--- a/rfc1035/rfc1035resolve.c
+++ b/rfc1035/rfc1035resolve.c
@@ -15,11 +15,6 @@
#include <string.h>
#include <idna.h>
-struct querybuf {
- char qbuf[512];
- unsigned qbuflen;
- } ;
-
static void putqbuf(const char *p, unsigned l, void *q)
{
struct querybuf *qp=(struct querybuf *)q;
diff --git a/rfc1035/rfc1035udp.c b/rfc1035/rfc1035udp.c
index c128efd..2a4ed34 100644
--- a/rfc1035/rfc1035udp.c
+++ b/rfc1035/rfc1035udp.c
@@ -40,15 +40,11 @@ int rfc1035_send_udp(int fd, const struct sockaddr *sin, int sin_len,
return (-1);
}
-
-struct rfc1035_udp_query_responses *
-rfc1035_udp_query_response_alloc(const char **queries,
- const unsigned *querylens,
- int n_queries)
+static struct rfc1035_udp_query_responses *
+rfc1035_udp_query_response_alloc_common(int n_queries)
{
struct rfc1035_udp_query_response *buf=
calloc(n_queries, sizeof(struct rfc1035_udp_query_response));
- int n;
struct rfc1035_udp_query_responses *resps;
@@ -65,10 +61,45 @@ rfc1035_udp_query_response_alloc(const char **queries,
resps->n_queries=n_queries;
resps->queries=buf;
- for (n=0; n<n_queries; ++n)
+ return resps;
+}
+
+struct rfc1035_udp_query_responses *
+rfc1035_udp_query_response_alloc(const char **queries,
+ const unsigned *querylens,
+ int n_queries)
+{
+ struct rfc1035_udp_query_responses *resps =
+ rfc1035_udp_query_response_alloc_common(n_queries);
+
+ if (!resps)
+ return 0;
+
+ for (int n=0; n<n_queries; ++n)
+ {
+ resps->queries[n].query=queries[n];
+ resps->queries[n].querylen=querylens[n];
+ }
+
+ return resps;
+}
+
+
+struct rfc1035_udp_query_responses *
+rfc1035_udp_query_response_alloc_bis(struct querybuf *queries,
+ int n_queries)
+{
+ struct rfc1035_udp_query_responses *resps =
+ rfc1035_udp_query_response_alloc_common(n_queries);
+
+ if (!resps)
+ return 0;
+
+
+ for (int n=0; n<n_queries; ++n)
{
- buf[n].query=queries[n];
- buf[n].querylen=querylens[n];
+ resps->queries[n].query=queries[n].qbuf;
+ resps->queries[n].querylen=queries[n].qbuflen;
}
return resps;