mirror of https://github.com/getdnsapi/getdns.git
Merge pull request #145 from wtoorop/features/wire2reply
Features/wire2reply
This commit is contained in:
commit
69a7c1f9ba
3
INSTALL
3
INSTALL
|
@ -384,9 +384,6 @@ getdns-specific Options
|
|||
`--with-libidn=pathname'
|
||||
path to libidn (default: search /usr/local ..)
|
||||
|
||||
`--with-libldns=pathname'
|
||||
path to libldns (default: search /usr/local ..)
|
||||
|
||||
`--with-libunbound=pathname'
|
||||
path to libunbound (default: search /usr/local ..)
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ NOTE: The current Windows implementation does not support the above.
|
|||
|
||||
A suite of regression tests are included with the library, if you make changes or just
|
||||
want to sanity check things on your system take a look at src/test. You will need
|
||||
to install [libcheck](https://libcheck.github.io/check/) and [libldns from NLnet Labs](https://nlnetlabs.nl/projects/ldns/) version 1.6.17 or later. Both libraries are also available from
|
||||
to install [libcheck](https://libcheck.github.io/check/). The check library is also available from
|
||||
many of the package repositories for the more popular operating systems.
|
||||
|
||||
NOTE: The current Windows implementation does not support the above.
|
||||
|
@ -198,7 +198,7 @@ build the packages, this is simplythe one we chose to use.
|
|||
# cd /home/deploy/build
|
||||
# mv lib lib64
|
||||
# . /usr/local/rvm/config/alias
|
||||
# fpm -x "*.la" -a native -s dir -t rpm -n getdns -v 0.2.0rc1 -d "unbound" -d "ldns" -d "libevent" -d "libidn" --prefix /usr --vendor "Verisign Inc., NLnet Labs" --license "BSD New" --url "https://getdnsapi.net" --description "Modern asynchronous API to the DNS" .
|
||||
# fpm -x "*.la" -a native -s dir -t rpm -n getdns -v 0.2.0rc1 -d "unbound" -d "libevent" -d "libidn" --prefix /usr --vendor "Verisign Inc., NLnet Labs" --license "BSD New" --url "https://getdnsapi.net" --description "Modern asynchronous API to the DNS" .
|
||||
|
||||
###OSX
|
||||
|
||||
|
|
56
configure.ac
56
configure.ac
|
@ -271,7 +271,7 @@ AC_RUN_IFELSE([AC_LANG_SOURCE([[
|
|||
#include <openssl/evp.h>
|
||||
#include <openssl/engine.h>
|
||||
#include <openssl/conf.h>
|
||||
/* routine to load gost (from sldns) */
|
||||
/* routine to load gost (from gldns) */
|
||||
int load_gost_id(void)
|
||||
{
|
||||
static int gost_id = 0;
|
||||
|
@ -608,60 +608,6 @@ AC_SUBST([CHECK_LIBS])
|
|||
AC_SUBST([CHECK_CFLAGS])
|
||||
# end libraries needed for libcheck
|
||||
|
||||
# find libldns
|
||||
LIBS="$initial_LIBS"
|
||||
|
||||
LDNS_LIBS=""
|
||||
LDNS_CFLAGS=""
|
||||
LDNS_LDFLAGS=""
|
||||
NOLIBLDNS=""
|
||||
|
||||
AC_ARG_WITH(libldns, AS_HELP_STRING([--with-libldns=pathname],
|
||||
[path to libldns (default: search /usr/local ..)]),
|
||||
[], [withval="yes"])
|
||||
if test x_$withval = x_yes; then
|
||||
for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do
|
||||
if test -f "$dir/include/ldns/ldns.h"; then
|
||||
LDNS_CFLAGS="-I$dir/include"
|
||||
LDNS_LDFLAGS="-L$dir/lib"
|
||||
CFLAGS="$CFLAGS $LDNS_CFLAGS"
|
||||
LDFLAGS="$LDFLAGS $LDNS_LDFLAGS"
|
||||
AC_MSG_NOTICE([Found libldns in $dir])
|
||||
break
|
||||
fi
|
||||
done
|
||||
else
|
||||
if test x_$withval != x_no; then
|
||||
LDNS_CFLAGS="-I$withval/include"
|
||||
LDNS_LDFLAGS="-L$withval/lib"
|
||||
CFLAGS="$CFLAGS $LDNS_CFLAGS"
|
||||
LDFLAGS="$LDFLAGS $LDNS_LDFLAGS"
|
||||
else
|
||||
NOLIBLDNS="nolibldns"
|
||||
AC_MSG_WARN([libldns not found or usable; unit tests will not be compiled and run])
|
||||
fi
|
||||
fi
|
||||
if test x$NOLIBLDNS = x
|
||||
then
|
||||
AC_CHECK_LIB([ldns], [ldns_dname_new_frm_str], [
|
||||
LDNS_LIBS="-lldns"
|
||||
AC_DEFINE_UNQUOTED(HAVE_LIBLDNS, [1], [Have libldns])
|
||||
], [
|
||||
NOLIBLDNS="nolibldns"
|
||||
AC_MSG_WARN([libldns not found or usable; unit tests will not be compiled and run])
|
||||
])
|
||||
fi
|
||||
|
||||
AC_SUBST([LDNS_LIBS])
|
||||
AC_SUBST([LDNS_CFLAGS])
|
||||
AC_SUBST([LDNS_LDFLAGS])
|
||||
AC_SUBST([NOLIBLDNS])
|
||||
|
||||
LIBS="$getdns_LIBS"
|
||||
CFLAGS="$getdns_CFLAGS"
|
||||
LDFLAGS="$getdns_LDFLAGS"
|
||||
|
||||
|
||||
#-------------------- libevent extension
|
||||
AC_ARG_WITH([libevent],
|
||||
[AS_HELP_STRING([--with-libevent], [path to libevent (default: search /usr/local ..)])],
|
||||
|
|
413
src/convert.c
413
src/convert.c
|
@ -587,4 +587,417 @@ getdns_fp2rr_list(
|
|||
&_getdns_plain_mem_funcs, in, rr_list, origin, default_ttl);
|
||||
}
|
||||
|
||||
#define SET_WIRE_INT(X,Y) if (getdns_dict_set_int(header, #X , (int) \
|
||||
GLDNS_ ## Y ## _WIRE(*wire))) goto error
|
||||
#define SET_WIRE_BIT(X,Y) if (getdns_dict_set_int(header, #X , \
|
||||
GLDNS_ ## Y ## _WIRE(*wire) ? 1 : 0)) goto error
|
||||
#define SET_WIRE_CNT(X,Y) if (getdns_dict_set_int(header, #X , (int) \
|
||||
GLDNS_ ## Y (*wire))) goto error
|
||||
|
||||
getdns_return_t
|
||||
_getdns_wire2msg_dict_scan(struct mem_funcs *mf,
|
||||
const uint8_t **wire, size_t *wire_len, getdns_dict **msg_dict)
|
||||
{
|
||||
getdns_return_t r = GETDNS_RETURN_GOOD;
|
||||
getdns_dict *result = NULL, *header = NULL, *rr_dict = NULL;
|
||||
_getdns_rr_iter rr_iter_storage, *rr_iter;
|
||||
gldns_pkt_section section;
|
||||
getdns_list *sections[4] = { NULL, NULL, NULL, NULL };
|
||||
const uint8_t *eop; /* end of packet */
|
||||
|
||||
if (!wire || !*wire || !wire_len || !msg_dict)
|
||||
return GETDNS_RETURN_INVALID_PARAMETER;
|
||||
|
||||
if (!(result = _getdns_dict_create_with_mf(mf)) ||
|
||||
!(header = _getdns_dict_create_with_mf(mf)) ||
|
||||
!(sections[GLDNS_SECTION_ANSWER]
|
||||
= _getdns_list_create_with_mf(mf)) ||
|
||||
!(sections[GLDNS_SECTION_AUTHORITY]
|
||||
= _getdns_list_create_with_mf(mf)) ||
|
||||
!(sections[GLDNS_SECTION_ADDITIONAL]
|
||||
= _getdns_list_create_with_mf(mf))) {
|
||||
r = GETDNS_RETURN_MEMORY_ERROR;
|
||||
goto error;
|
||||
}
|
||||
SET_WIRE_INT(id, ID);
|
||||
SET_WIRE_BIT(qr, QR);
|
||||
SET_WIRE_BIT(aa, AA);
|
||||
SET_WIRE_BIT(tc, TC);
|
||||
SET_WIRE_BIT(rd, RD);
|
||||
SET_WIRE_BIT(cd, CD);
|
||||
SET_WIRE_BIT(ra, RA);
|
||||
SET_WIRE_BIT(ad, AD);
|
||||
SET_WIRE_INT(opcode, OPCODE);
|
||||
SET_WIRE_INT(rcode, RCODE);
|
||||
SET_WIRE_BIT(z, Z);
|
||||
|
||||
SET_WIRE_CNT(qdcount, QDCOUNT);
|
||||
SET_WIRE_CNT(ancount, ANCOUNT);
|
||||
SET_WIRE_CNT(nscount, NSCOUNT);
|
||||
SET_WIRE_CNT(arcount, ARCOUNT);
|
||||
|
||||
/* header */
|
||||
if ((r = getdns_dict_set_dict(result, "header", header)))
|
||||
goto error;
|
||||
getdns_dict_destroy(header);
|
||||
header = NULL;
|
||||
eop = *wire + 12;
|
||||
|
||||
for ( rr_iter = _getdns_rr_iter_init(&rr_iter_storage,*wire,*wire_len)
|
||||
; rr_iter
|
||||
; rr_iter = _getdns_rr_iter_next(rr_iter)) {
|
||||
|
||||
if (rr_iter->nxt > eop)
|
||||
eop = rr_iter->nxt;
|
||||
|
||||
if (!(rr_dict = _getdns_rr_iter2rr_dict(mf, rr_iter)))
|
||||
continue;
|
||||
|
||||
switch ((section = _getdns_rr_iter_section(rr_iter))) {
|
||||
case GLDNS_SECTION_QUESTION:
|
||||
if ((r = getdns_dict_set_dict(
|
||||
result, "question", rr_dict)))
|
||||
goto error;
|
||||
break;
|
||||
default:
|
||||
if ((r = _getdns_list_append_dict(
|
||||
sections[section], rr_dict)))
|
||||
goto error;
|
||||
break;
|
||||
}
|
||||
rr_dict = NULL;
|
||||
}
|
||||
if ((r = getdns_dict_set_list(result, "answer",
|
||||
sections[GLDNS_SECTION_ANSWER])) ||
|
||||
(r = getdns_dict_set_list(result, "authority",
|
||||
sections[GLDNS_SECTION_AUTHORITY])) ||
|
||||
(r = getdns_dict_set_list(result, "additional",
|
||||
sections[GLDNS_SECTION_ADDITIONAL])))
|
||||
goto error;
|
||||
|
||||
*wire_len -= (eop - *wire);
|
||||
*wire = eop;
|
||||
error:
|
||||
getdns_dict_destroy(rr_dict);
|
||||
getdns_list_destroy(sections[GLDNS_SECTION_ADDITIONAL]);
|
||||
getdns_list_destroy(sections[GLDNS_SECTION_AUTHORITY]);
|
||||
getdns_list_destroy(sections[GLDNS_SECTION_ANSWER]);
|
||||
getdns_dict_destroy(header);
|
||||
if (r)
|
||||
getdns_dict_destroy(result);
|
||||
else
|
||||
*msg_dict = result;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
getdns_return_t
|
||||
_getdns_wire2msg_dict(struct mem_funcs *mf,
|
||||
const uint8_t *wire, size_t wire_len, getdns_dict **msg_dict)
|
||||
{
|
||||
return _getdns_wire2msg_dict_scan(mf, &wire, &wire_len, msg_dict);
|
||||
}
|
||||
getdns_return_t
|
||||
getdns_wire2msg_dict(
|
||||
const uint8_t *wire, size_t wire_len, getdns_dict **msg_dict)
|
||||
{
|
||||
return _getdns_wire2msg_dict(
|
||||
&_getdns_plain_mem_funcs, wire, wire_len, msg_dict);
|
||||
}
|
||||
|
||||
getdns_return_t
|
||||
_getdns_wire2msg_dict_buf(struct mem_funcs *mf,
|
||||
const uint8_t *wire, size_t *wire_len, getdns_dict **msg_dict)
|
||||
{
|
||||
size_t my_wire_len;
|
||||
getdns_return_t r;
|
||||
|
||||
if (!wire_len)
|
||||
return GETDNS_RETURN_INVALID_PARAMETER;
|
||||
else
|
||||
my_wire_len = *wire_len;
|
||||
|
||||
if ((r = _getdns_wire2msg_dict_scan(mf, &wire, &my_wire_len, msg_dict)))
|
||||
return r;
|
||||
|
||||
*wire_len -= my_wire_len;
|
||||
return GETDNS_RETURN_GOOD;
|
||||
}
|
||||
getdns_return_t
|
||||
getdns_wire2msg_dict_buf(
|
||||
const uint8_t *wire, size_t *wire_len, getdns_dict **msg_dict)
|
||||
{
|
||||
return _getdns_wire2msg_dict_buf(
|
||||
&_getdns_plain_mem_funcs, wire, wire_len, msg_dict);
|
||||
}
|
||||
|
||||
getdns_return_t
|
||||
getdns_wire2msg_dict_scan(
|
||||
const uint8_t **wire, size_t *wire_len, getdns_dict **msg_dict)
|
||||
{
|
||||
return _getdns_wire2msg_dict_scan(
|
||||
&_getdns_plain_mem_funcs, wire, wire_len, msg_dict);
|
||||
}
|
||||
|
||||
#define SET_HEADER_INT(X,Y) \
|
||||
if (!getdns_dict_get_int(reply, "/header/" #X, &n)) \
|
||||
GLDNS_ ## Y ## _SET(header, n);
|
||||
#define SET_HEADER_BIT(X,Y) \
|
||||
if (!getdns_dict_get_int(reply, "/header/" #X, &n) && n) \
|
||||
GLDNS_ ## Y ## _SET(header);
|
||||
|
||||
static getdns_return_t
|
||||
_getdns_reply_dict2wire(const getdns_dict *reply, gldns_buffer *buf)
|
||||
{
|
||||
uint8_t header[GLDNS_HEADER_SIZE];
|
||||
uint32_t n, qtype, qclass = GETDNS_RRCLASS_IN;
|
||||
size_t pkt_start, i;
|
||||
getdns_list *section;
|
||||
getdns_dict *rr_dict;
|
||||
getdns_bindata *qname;
|
||||
|
||||
(void) memset(header, 0, sizeof(GLDNS_HEADER_SIZE));
|
||||
SET_HEADER_INT(id, ID);
|
||||
SET_HEADER_BIT(qr, QR);
|
||||
SET_HEADER_BIT(aa, AA);
|
||||
SET_HEADER_BIT(tc, TC);
|
||||
SET_HEADER_BIT(rd, RD);
|
||||
SET_HEADER_BIT(cd, CD);
|
||||
SET_HEADER_BIT(ra, RA);
|
||||
SET_HEADER_BIT(ad, AD);
|
||||
SET_HEADER_INT(opcode, OPCODE);
|
||||
SET_HEADER_INT(rcode, RCODE);
|
||||
SET_HEADER_BIT(z, Z);
|
||||
|
||||
pkt_start = gldns_buffer_position(buf);
|
||||
gldns_buffer_write(buf, header, sizeof(header));
|
||||
|
||||
if (!getdns_dict_get_bindata(reply, "/question/qname", &qname) &&
|
||||
!getdns_dict_get_int(reply, "/question/qtype", &qtype)) {
|
||||
(void)getdns_dict_get_int(reply, "/question/qclass", &qclass);
|
||||
gldns_buffer_write(buf, qname->data, qname->size);
|
||||
gldns_buffer_write_u16(buf, (uint16_t)qtype);
|
||||
gldns_buffer_write_u16(buf, (uint16_t)qclass);
|
||||
gldns_buffer_write_u16_at(buf, pkt_start+GLDNS_QDCOUNT_OFF, 1);
|
||||
}
|
||||
if (!getdns_dict_get_list(reply, "answer", §ion)) {
|
||||
for ( n = 0, i = 0
|
||||
; !getdns_list_get_dict(section, i, &rr_dict); i++) {
|
||||
|
||||
if (!_getdns_rr_dict2wire(rr_dict, buf))
|
||||
n++;
|
||||
}
|
||||
gldns_buffer_write_u16_at(buf, pkt_start+GLDNS_ANCOUNT_OFF, n);
|
||||
}
|
||||
if (!getdns_dict_get_list(reply, "authority", §ion)) {
|
||||
for ( n = 0, i = 0
|
||||
; !getdns_list_get_dict(section, i, &rr_dict); i++) {
|
||||
|
||||
if (!_getdns_rr_dict2wire(rr_dict, buf))
|
||||
n++;
|
||||
}
|
||||
gldns_buffer_write_u16_at(buf, pkt_start+GLDNS_NSCOUNT_OFF, n);
|
||||
}
|
||||
if (!getdns_dict_get_list(reply, "additional", §ion)) {
|
||||
for ( n = 0, i = 0
|
||||
; !getdns_list_get_dict(section, i, &rr_dict); i++) {
|
||||
|
||||
if (!_getdns_rr_dict2wire(rr_dict, buf))
|
||||
n++;
|
||||
}
|
||||
gldns_buffer_write_u16_at(buf, pkt_start+GLDNS_ARCOUNT_OFF, n);
|
||||
}
|
||||
return GETDNS_RETURN_GOOD;
|
||||
}
|
||||
|
||||
static getdns_return_t
|
||||
_getdns_msg_dict2wire_buf(const getdns_dict *msg_dict, gldns_buffer *gbuf)
|
||||
{
|
||||
getdns_return_t r;
|
||||
getdns_list *replies;
|
||||
getdns_dict *reply;
|
||||
size_t i;
|
||||
|
||||
if ((r = getdns_dict_get_list(msg_dict, "replies_tree", &replies))) {
|
||||
if (r != GETDNS_RETURN_NO_SUCH_DICT_NAME)
|
||||
return r;
|
||||
return _getdns_reply_dict2wire(msg_dict, gbuf);
|
||||
}
|
||||
for (i = 0; r == GETDNS_RETURN_GOOD; i++) {
|
||||
if (!(r = getdns_list_get_dict(replies, i, &reply)))
|
||||
r = _getdns_reply_dict2wire(reply, gbuf);
|
||||
}
|
||||
return r == GETDNS_RETURN_NO_SUCH_LIST_ITEM ? GETDNS_RETURN_GOOD : r;
|
||||
}
|
||||
|
||||
getdns_return_t
|
||||
getdns_msg_dict2wire(
|
||||
const getdns_dict *msg_dict, uint8_t **wire, size_t *wire_sz)
|
||||
{
|
||||
uint8_t buf_spc[4096], *buf;
|
||||
size_t buf_len = sizeof(buf_spc);
|
||||
getdns_return_t r = getdns_msg_dict2wire_buf(
|
||||
msg_dict, buf_spc, &buf_len);
|
||||
|
||||
if (r != GETDNS_RETURN_GOOD && r != GETDNS_RETURN_NEED_MORE_SPACE)
|
||||
return r;
|
||||
|
||||
if (!(buf = malloc(buf_len)))
|
||||
return GETDNS_RETURN_MEMORY_ERROR;
|
||||
|
||||
if (!r)
|
||||
memcpy(buf, buf_spc, buf_len);
|
||||
|
||||
else if ((r = getdns_msg_dict2wire_buf(msg_dict, buf, &buf_len))) {
|
||||
free(buf);
|
||||
return r;
|
||||
}
|
||||
*wire = buf;
|
||||
*wire_sz = buf_len;
|
||||
return GETDNS_RETURN_GOOD;
|
||||
}
|
||||
|
||||
getdns_return_t
|
||||
getdns_msg_dict2wire_buf(
|
||||
const getdns_dict *msg_dict, uint8_t *wire, size_t *wire_sz)
|
||||
{
|
||||
int my_wire_sz;
|
||||
getdns_return_t r;
|
||||
|
||||
if (!wire_sz)
|
||||
return GETDNS_RETURN_INVALID_PARAMETER;
|
||||
else
|
||||
my_wire_sz = *wire_sz;
|
||||
|
||||
r = getdns_msg_dict2wire_scan(msg_dict, &wire, &my_wire_sz);
|
||||
if (r == GETDNS_RETURN_GOOD || r == GETDNS_RETURN_NEED_MORE_SPACE)
|
||||
*wire_sz -= my_wire_sz;
|
||||
return r;
|
||||
}
|
||||
|
||||
getdns_return_t
|
||||
getdns_msg_dict2wire_scan(
|
||||
const getdns_dict *msg_dict, uint8_t **wire, int *wire_sz)
|
||||
{
|
||||
getdns_return_t r;
|
||||
gldns_buffer gbuf;
|
||||
|
||||
if (!msg_dict || !wire || !*wire || !wire_sz)
|
||||
return GETDNS_RETURN_INVALID_PARAMETER;
|
||||
|
||||
|
||||
gldns_buffer_init_frm_data(&gbuf, *wire, *wire_sz);
|
||||
if ((r = _getdns_msg_dict2wire_buf(msg_dict, &gbuf)))
|
||||
return r;
|
||||
|
||||
if (gldns_buffer_position(&gbuf) == 0)
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
|
||||
*wire += gldns_buffer_position(&gbuf);
|
||||
*wire_sz -= gldns_buffer_position(&gbuf);
|
||||
if (gldns_buffer_position(&gbuf) > gldns_buffer_limit(&gbuf))
|
||||
return GETDNS_RETURN_NEED_MORE_SPACE;
|
||||
else
|
||||
return GETDNS_RETURN_GOOD;
|
||||
}
|
||||
|
||||
getdns_return_t
|
||||
getdns_msg_dict2str(
|
||||
const getdns_dict *msg_dict, char **str)
|
||||
{
|
||||
char buf_spc[4096], *buf;
|
||||
size_t buf_len = sizeof(buf_spc) - 1;
|
||||
getdns_return_t r = getdns_msg_dict2str_buf(
|
||||
msg_dict, buf_spc, &buf_len);
|
||||
|
||||
if (r != GETDNS_RETURN_GOOD && r != GETDNS_RETURN_NEED_MORE_SPACE)
|
||||
return r;
|
||||
|
||||
buf_len += 1;
|
||||
if (!(buf = malloc(buf_len)))
|
||||
return GETDNS_RETURN_MEMORY_ERROR;
|
||||
|
||||
if (!r)
|
||||
memcpy(buf, buf_spc, buf_len);
|
||||
|
||||
else if ((r = getdns_msg_dict2str_buf(msg_dict, buf, &buf_len))) {
|
||||
free(buf);
|
||||
return r;
|
||||
}
|
||||
*str = buf;
|
||||
return GETDNS_RETURN_GOOD;
|
||||
}
|
||||
|
||||
getdns_return_t
|
||||
getdns_msg_dict2str_buf(
|
||||
const getdns_dict *msg_dict, char *str, size_t *str_len)
|
||||
{
|
||||
int my_str_len;
|
||||
getdns_return_t r;
|
||||
|
||||
if (!str_len)
|
||||
return GETDNS_RETURN_INVALID_PARAMETER;
|
||||
else
|
||||
my_str_len = *str_len;
|
||||
|
||||
r = getdns_msg_dict2str_scan(msg_dict, &str, &my_str_len);
|
||||
if (r == GETDNS_RETURN_GOOD || r == GETDNS_RETURN_NEED_MORE_SPACE)
|
||||
*str_len -= my_str_len;
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
getdns_return_t
|
||||
getdns_msg_dict2str_scan(
|
||||
const getdns_dict *msg_dict, char **str, int *str_len)
|
||||
{
|
||||
getdns_return_t r;
|
||||
gldns_buffer gbuf;
|
||||
uint8_t buf_spc[4096], *buf = buf_spc, *scan_buf;
|
||||
size_t sz, scan_sz;
|
||||
int prev_str_len;
|
||||
char *prev_str;
|
||||
int sz_needed;
|
||||
|
||||
if (!msg_dict || !str || !*str || !str_len)
|
||||
return GETDNS_RETURN_INVALID_PARAMETER;
|
||||
|
||||
gldns_buffer_init_frm_data(&gbuf, buf, sizeof(buf_spc));
|
||||
r = _getdns_msg_dict2wire_buf(msg_dict, &gbuf);
|
||||
if (gldns_buffer_position(&gbuf) > sizeof(buf_spc)) {
|
||||
if (!(buf = GETDNS_XMALLOC(
|
||||
msg_dict->mf, uint8_t, (sz = gldns_buffer_position(&gbuf))))) {
|
||||
return GETDNS_RETURN_MEMORY_ERROR;
|
||||
}
|
||||
gldns_buffer_init_frm_data(&gbuf, buf, sz);
|
||||
r = _getdns_msg_dict2wire_buf(msg_dict, &gbuf);
|
||||
}
|
||||
if (r) {
|
||||
if (buf != buf_spc)
|
||||
GETDNS_FREE(msg_dict->mf, buf);
|
||||
return r;
|
||||
}
|
||||
scan_buf = gldns_buffer_begin(&gbuf);
|
||||
scan_sz = gldns_buffer_position(&gbuf);
|
||||
prev_str = *str;
|
||||
prev_str_len = *str_len;
|
||||
sz = (size_t)*str_len;
|
||||
sz_needed = gldns_wire2str_pkt_scan(
|
||||
&scan_buf, &scan_sz, str, &sz);
|
||||
|
||||
if (sz_needed > prev_str_len) {
|
||||
*str = prev_str + sz_needed;
|
||||
*str_len = prev_str_len - sz_needed;
|
||||
r = GETDNS_RETURN_NEED_MORE_SPACE;
|
||||
} else {
|
||||
*str_len = sz;
|
||||
**str = 0;
|
||||
}
|
||||
if (buf != buf_spc)
|
||||
GETDNS_FREE(msg_dict->mf, buf);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/* convert.c */
|
||||
|
|
|
@ -611,7 +611,7 @@ getdns_rr_dict2str_scan(
|
|||
/**
|
||||
* Convert the string representation of the resource record to rr_dict format.
|
||||
*
|
||||
* @param str String representation of the resource record.
|
||||
* @param str String representation of the resource record.
|
||||
* @return rr_dict The result getdns dict representation of the resource record
|
||||
* @param origin Default suffix for not fully qualified domain names
|
||||
* @param default_ttl Default ttl
|
||||
|
@ -625,7 +625,7 @@ getdns_str2rr_dict(
|
|||
/**
|
||||
* Read the zonefile and convert to a list of rr_dict's.
|
||||
*
|
||||
* @param fp String representation of the resource record.
|
||||
* @param fp An opened FILE pointer on the zone file.
|
||||
* @return rr_list The result list of rr_dicts representing the zone file.
|
||||
* @param origin Default suffix for not fully qualified domain names
|
||||
* @param default_ttl Default ttl
|
||||
|
@ -636,6 +636,149 @@ getdns_fp2rr_list(
|
|||
FILE *in, getdns_list **rr_list,
|
||||
const char *origin, uint32_t default_ttl);
|
||||
|
||||
/**
|
||||
* Convert DNS message dict to wireformat representation.
|
||||
*
|
||||
* @param msg_dict The getdns dict representation of a DNS message
|
||||
* @return wire A newly allocated buffer which will contain the wireformat.
|
||||
* @return wire_sz The size of the allocated buffer and the wireformat.
|
||||
* @return GETDNS_RETURN_GOOD on success or an error code on failure.
|
||||
*/
|
||||
getdns_return_t
|
||||
getdns_msg_dict2wire(
|
||||
const getdns_dict *msg_dict, uint8_t **wire, size_t *wire_sz);
|
||||
|
||||
/**
|
||||
* Convert DNS message dict to wireformat representation.
|
||||
*
|
||||
* @param msg_dict The getdns dict representation of a DNS message
|
||||
* @param wire The buffer in which the wireformat will be written
|
||||
* @param wire_sz On input the size of the wire buffer,
|
||||
* On output the amount of wireformat needed for the
|
||||
* wireformat representation of the DNS message;
|
||||
* even if it did not fit.
|
||||
* @return GETDNS_RETURN_GOOD on success or an error code on failure.
|
||||
* GETDNS_RETURN_NEED_MORE_SPACE will be returned when the buffer was too
|
||||
* small. wire_sz will be set to the needed buffer space then.
|
||||
*/
|
||||
getdns_return_t
|
||||
getdns_msg_dict2wire_buf(
|
||||
const getdns_dict *msg_dict, uint8_t *wire, size_t *wire_sz);
|
||||
|
||||
/**
|
||||
* Convert DNS message dict to wireformat representation.
|
||||
*
|
||||
* @param msg_dict The getdns dict representation of the DNS message
|
||||
* @param wire A pointer to the buffer pointer in which the wireformat
|
||||
* will be written.
|
||||
* On output the buffer pointer will have moved along
|
||||
* the buffer and point right after the just written RR.
|
||||
* @param wire_sz On input the size of the wire buffer,
|
||||
* On output the amount of wireformat needed for the
|
||||
* wireformat will have been substracted from wire_sz.
|
||||
* @return GETDNS_RETURN_GOOD on success or an error code on failure.
|
||||
* GETDNS_RETURN_NEED_MORE_SPACE will be returned when the buffer was too
|
||||
* small. The function will pretend that it had written beyond the end
|
||||
* of the buffer, and wire will point past the buffer and wire_sz will
|
||||
* contain a negative value.
|
||||
*/
|
||||
getdns_return_t
|
||||
getdns_msg_dict2wire_scan(
|
||||
const getdns_dict *msg_dict, uint8_t **wire, int *wire_sz);
|
||||
|
||||
|
||||
/**
|
||||
* Convert wireformat DNS message in a getdns msg_dict representation.
|
||||
*
|
||||
* @param wire Buffer containing the wireformat rr
|
||||
* @param wire_sz Size of the wire buffer
|
||||
* @return msg_dict The returned DNS message
|
||||
* @return GETDNS_RETURN_GOOD on success or an error code on failure.
|
||||
*/
|
||||
getdns_return_t
|
||||
getdns_wire2msg_dict(
|
||||
const uint8_t *wire, size_t wire_sz, getdns_dict **msg_dict);
|
||||
|
||||
/**
|
||||
* Convert wireformat DNS message in a getdns msg_dict representation.
|
||||
*
|
||||
* @param wire Buffer containing the wireformat rr
|
||||
* @param wire_sz On input the size of the wire buffer
|
||||
* On output the length of the wireformat rr.
|
||||
* @return msg_dict The returned DNS message
|
||||
* @return GETDNS_RETURN_GOOD on success or an error code on failure.
|
||||
*/
|
||||
getdns_return_t
|
||||
getdns_wire2msg_dict_buf(
|
||||
const uint8_t *wire, size_t *wire_sz, getdns_dict **msg_dict);
|
||||
|
||||
/**
|
||||
* Convert wireformat DNS message in a getdns msg_dic representation.
|
||||
*
|
||||
* @param wire A pointer to the pointer of the wireformat buffer.
|
||||
* On return this pointer is moved to after first read
|
||||
* in resource record.
|
||||
* @param wire_sz On input the size of the wire buffer
|
||||
* On output the size is decreased with the length
|
||||
* of the wireformat DNS message.
|
||||
* @return msg_dict The returned DNS message
|
||||
* @return GETDNS_RETURN_GOOD on success or an error code on failure.
|
||||
*/
|
||||
getdns_return_t
|
||||
getdns_wire2msg_dict_scan(
|
||||
const uint8_t **wire, size_t *wire_sz, getdns_dict **msg_dict);
|
||||
|
||||
|
||||
/**
|
||||
* Convert msg_dict to the string representation of the DNS message.
|
||||
*
|
||||
* @param msg_dict The getdns dict representation of the DNS message
|
||||
* @return str A newly allocated string representation of the rr
|
||||
* @return GETDNS_RETURN_GOOD on success or an error code on failure.
|
||||
*/
|
||||
getdns_return_t
|
||||
getdns_msg_dict2str(
|
||||
const getdns_dict *msg_dict, char **str);
|
||||
|
||||
/**
|
||||
* Convert msg_dict to the string representation of the DNS message.
|
||||
*
|
||||
* @param msg_dict The getdns dict representation of the resource record
|
||||
* @param str The buffer in which the string will be written
|
||||
* @param str_len On input the size of the text buffer,
|
||||
* On output the amount of characters needed to write
|
||||
* the string representation of the rr. Even if it does
|
||||
* not fit.
|
||||
* @return GETDNS_RETURN_GOOD on success or an error code on failure.
|
||||
* GETDNS_RETURN_NEED_MORE_SPACE will be returned when the buffer was too
|
||||
* small. str_len will be set to the needed buffer space then.
|
||||
*/
|
||||
getdns_return_t
|
||||
getdns_msg_dict2str_buf(
|
||||
const getdns_dict *msg_dict, char *str, size_t *str_len);
|
||||
|
||||
/**
|
||||
* Convert msg_dict to the string representation of the resource record.
|
||||
*
|
||||
* @param msg_dict The getdns dict representation of the resource record
|
||||
* @param str A pointer to the buffer pointer in which the string
|
||||
* will be written.
|
||||
* On output the buffer pointer will have moved along
|
||||
* the buffer and point right after the just written RR.
|
||||
* @param str_len On input the size of the str buffer,
|
||||
* On output the number of characters needed for the
|
||||
* string will have been substracted from strlen.
|
||||
* @return GETDNS_RETURN_GOOD on success or an error code on failure.
|
||||
* GETDNS_RETURN_NEED_MORE_SPACE will be returned when the buffer was too
|
||||
* small. The function will pretend that it had written beyond the end
|
||||
* of the buffer, and str will point past the buffer and str_len will
|
||||
* contain a negative value.
|
||||
*/
|
||||
getdns_return_t
|
||||
getdns_msg_dict2str_scan(
|
||||
const getdns_dict *msg_dict, char **str, int *str_len);
|
||||
|
||||
|
||||
/**
|
||||
* Validate replies or resource records.
|
||||
*
|
||||
|
@ -670,6 +813,8 @@ getdns_validate_dnssec2(getdns_list *to_validate,
|
|||
getdns_list *trust_anchors,
|
||||
time_t validation_time, uint32_t skew);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -108,6 +108,12 @@ getdns_list_set_bindata
|
|||
getdns_list_set_dict
|
||||
getdns_list_set_int
|
||||
getdns_list_set_list
|
||||
getdns_msg_dict2str
|
||||
getdns_msg_dict2str_buf
|
||||
getdns_msg_dict2str_scan
|
||||
getdns_msg_dict2wire
|
||||
getdns_msg_dict2wire_buf
|
||||
getdns_msg_dict2wire_scan
|
||||
getdns_pretty_print_dict
|
||||
getdns_pretty_print_list
|
||||
getdns_pretty_snprint_dict
|
||||
|
@ -131,6 +137,9 @@ getdns_str2rr_dict
|
|||
getdns_strerror
|
||||
getdns_validate_dnssec
|
||||
getdns_validate_dnssec2
|
||||
getdns_wire2msg_dict
|
||||
getdns_wire2msg_dict_buf
|
||||
getdns_wire2msg_dict_scan
|
||||
getdns_wire2rr_dict
|
||||
getdns_wire2rr_dict_buf
|
||||
getdns_wire2rr_dict_scan
|
||||
|
|
|
@ -43,7 +43,6 @@ have_libevent = @have_libevent@
|
|||
have_libuv = @have_libuv@
|
||||
have_libev = @have_libev@
|
||||
NOLIBCHECK = @NOLIBCHECK@
|
||||
NOLIBLDNS = @NOLIBLDNS@
|
||||
|
||||
EXTENSION_LIBEVENT_EXT_LIBS=@EXTENSION_LIBEVENT_EXT_LIBS@
|
||||
EXTENSION_LIBEVENT_LDFLAGS=@EXTENSION_LIBEVENT_LDFLAGS@
|
||||
|
@ -63,9 +62,6 @@ LDFLAGS=-L.. @LDFLAGS@
|
|||
LDLIBS=../libgetdns.la @LIBS@
|
||||
CHECK_LIBS=@CHECK_LIBS@
|
||||
CHECK_CFLAGS=@CHECK_CFLAGS@
|
||||
LDNS_LIBS=@LDNS_LIBS@
|
||||
LDNS_CFLAGS=@LDNS_CFLAGS@
|
||||
LDNS_LDFLAGS=@LDNS_LDFLAGS@
|
||||
|
||||
CHECK_OBJS=check_getdns_common.lo check_getdns_context_set_timeout.lo \
|
||||
check_getdns.lo check_getdns_transport.lo
|
||||
|
@ -93,7 +89,7 @@ default: all
|
|||
all: $(PROGRAMS)
|
||||
|
||||
$(ALL_OBJS):
|
||||
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(LDNS_CFLAGS) -c $(srcdir)/$(@:.lo=.c) -o $@
|
||||
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $(srcdir)/$(@:.lo=.c) -o $@
|
||||
|
||||
$(NON_C99_OBJS):
|
||||
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -c $(srcdir)/$(@:.lo=.c) -o $@
|
||||
|
@ -117,16 +113,16 @@ check_getdns_common: check_getdns_common.lo
|
|||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ check_getdns_common.lo
|
||||
|
||||
check_getdns: check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_selectloop.lo
|
||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(CHECK_CFLAGS) $(CHECK_LIBS) $(LDNS_CFLAGS) $(LDNS_LDFLAGS) $(LDNS_LIBS) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_selectloop.lo
|
||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(CHECK_CFLAGS) $(CHECK_LIBS) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_selectloop.lo
|
||||
|
||||
check_getdns_event: check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libevent.lo ../libgetdns_ext_event.la
|
||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libevent.lo $(LDFLAGS) $(LDLIBS) $(CHECK_CFLAGS) $(CHECK_LIBS) $(LDNS_CFLAGS) $(LDNS_LDFLAGS) $(LDNS_LIBS) ../libgetdns_ext_event.la $(EXTENSION_LIBEVENT_LDFLAGS) $(EXTENSION_LIBEVENT_EXT_LIBS)
|
||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libevent.lo $(LDFLAGS) $(LDLIBS) $(CHECK_CFLAGS) $(CHECK_LIBS) ../libgetdns_ext_event.la $(EXTENSION_LIBEVENT_LDFLAGS) $(EXTENSION_LIBEVENT_EXT_LIBS)
|
||||
|
||||
check_getdns_uv: check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libuv.lo ../libgetdns_ext_uv.la
|
||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libuv.lo $(LDFLAGS) $(LDLIBS) $(CHECK_CFLAGS) $(CHECK_LIBS) $(LDNS_CFLAGS) $(LDNS_LDFLAGS) $(LDNS_LIBS) ../libgetdns_ext_uv.la $(EXTENSION_LIBUV_LDFLAGS) $(EXTENSION_LIBUV_EXT_LIBS)
|
||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libuv.lo $(LDFLAGS) $(LDLIBS) $(CHECK_CFLAGS) $(CHECK_LIBS) ../libgetdns_ext_uv.la $(EXTENSION_LIBUV_LDFLAGS) $(EXTENSION_LIBUV_EXT_LIBS)
|
||||
|
||||
check_getdns_ev: check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libev.lo ../libgetdns_ext_ev.la
|
||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libev.lo $(LDFLAGS) $(LDLIBS) $(CHECK_CFLAGS) $(CHECK_LIBS) $(LDNS_CFLAGS) $(LDNS_LDFLAGS) $(LDNS_LIBS) ../libgetdns_ext_ev.la $(EXTENSION_LIBEV_LDFLAGS) $(EXTENSION_LIBEV_EXT_LIBS)
|
||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libev.lo $(LDFLAGS) $(LDLIBS) $(CHECK_CFLAGS) $(CHECK_LIBS) ../libgetdns_ext_ev.la $(EXTENSION_LIBEV_LDFLAGS) $(EXTENSION_LIBEV_EXT_LIBS)
|
||||
|
||||
getdns_query: getdns_query.lo
|
||||
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ getdns_query.lo $(LDFLAGS) $(LDLIBS)
|
||||
|
@ -155,16 +151,7 @@ nolibcheck:
|
|||
@echo "***"
|
||||
@false
|
||||
|
||||
nolibldns:
|
||||
@echo "***"
|
||||
@echo "*** Cannot run unit tests, because they could not be compiled,"
|
||||
@echo "*** because libldns was not found or usable at configure time."
|
||||
@echo "*** To compile and run unit tests make sure libldns is available"
|
||||
@echo "*** and usable during configuration"
|
||||
@echo "***"
|
||||
@false
|
||||
|
||||
test: $(NOLIBCHECK) $(NOLIBLDNS) all
|
||||
test: $(NOLIBCHECK) all
|
||||
(cd $(srcdir)/../.. && find . -type f -executable -and \( -name "*.[ch]" -or -name "*.html" -or -name "*.in" -or -name "*.good" -or -name "*.ac" \) | awk 'BEGIN{e=0}{print("ERROR! Executable bit found on", $$0);e=1}END{exit(e)}')
|
||||
./$(CHECK_GETDNS)
|
||||
if test $(have_libevent) = 1 ; then ./$(CHECK_EVENT_PROG) ; fi
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdio.h>
|
||||
#include <ldns/ldns.h>
|
||||
|
||||
|
||||
/*
|
||||
|
@ -126,7 +125,7 @@ typedef struct timeout_thread_data {
|
|||
|
||||
typedef struct queued_response {
|
||||
struct sockaddr_in client_addr;
|
||||
ldns_pkt* pkt;
|
||||
getdns_dict *reply;
|
||||
} queued_response;
|
||||
|
||||
void* run_server(void* data) {
|
||||
|
@ -135,13 +134,25 @@ void* run_server(void* data) {
|
|||
struct sockaddr_in serv_addr;
|
||||
uint8_t mesg[65536];
|
||||
fd_set read_fds;
|
||||
ldns_rdf* answerfrom;
|
||||
ldns_resolver* resolver;
|
||||
getdns_context *ctxt;
|
||||
getdns_return_t r;
|
||||
getdns_dict *dns_msg;
|
||||
getdns_bindata *qname;
|
||||
char *qname_str;
|
||||
uint32_t qtype, qid;
|
||||
int num_received = 0;
|
||||
queued_response responses[10];
|
||||
|
||||
ldns_resolver_new_frm_file(&resolver, NULL);
|
||||
|
||||
if ((r = getdns_context_create(&ctxt, 1))) {
|
||||
fprintf( stderr, "Could not create a getdns context: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
return NULL;
|
||||
}
|
||||
if ((r = getdns_context_set_resolution_type(ctxt, GETDNS_RESOLUTION_STUB))) {
|
||||
fprintf( stderr, "Could not set context in stub mode resolution: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fd=socket(AF_INET,SOCK_DGRAM,0);
|
||||
|
||||
|
@ -166,32 +177,63 @@ void* run_server(void* data) {
|
|||
tv.tv_usec = 0;
|
||||
int r = select(fd + 1, &read_fds, NULL, NULL, &tv);
|
||||
if (r > 0 && num_received < 10) {
|
||||
ldns_pkt* query;
|
||||
socklen_t len = sizeof(client_addr);
|
||||
int n = recvfrom(fd,mesg,65536,0,(struct sockaddr *)&(responses[num_received].client_addr),&len);
|
||||
ldns_wire2pkt(&query, mesg, n);
|
||||
ldns_resolver_send_pkt(&(responses[num_received].pkt), resolver, query);
|
||||
ldns_str2rdf_a(&answerfrom, "127.0.0.1");
|
||||
ldns_pkt_set_answerfrom(responses[num_received].pkt, answerfrom);
|
||||
ldns_pkt_free(query);
|
||||
if ((r = getdns_wire2msg_dict(mesg, n, &dns_msg))) {
|
||||
fprintf( stderr, "Could not convert wireformat to DNS message dict: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
if ((r = getdns_dict_get_bindata(dns_msg, "/question/qname", &qname))) {
|
||||
fprintf( stderr, "Could not get query name from request dict: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
if ((r = getdns_convert_dns_name_to_fqdn(qname, &qname_str))) {
|
||||
fprintf( stderr, "Could not convert qname to fqdn: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
if ((r = getdns_dict_get_int(dns_msg, "/question/qtype", &qtype))) {
|
||||
fprintf( stderr, "Could not get query type from request dict: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
if ((r = getdns_dict_get_int(dns_msg, "/header/id", &qid))) {
|
||||
fprintf( stderr, "Could not get message ID from request dict: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
getdns_dict_destroy(dns_msg);
|
||||
r = getdns_general_sync(ctxt, qname_str, qtype, NULL, &responses[num_received].reply);
|
||||
free(qname_str);
|
||||
if (r) {
|
||||
fprintf( stderr, "Could query for \"%s\" %d: \"%s\"\n", qname_str, (int)qtype
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
if ((r = getdns_dict_set_int(responses[num_received].reply, "/replies_tree/0/header/id", qid))) {
|
||||
fprintf( stderr, "Could not set message ID on reply dict: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
++num_received;
|
||||
} else if (r == 0 && num_received > 0) {
|
||||
int i = 0;
|
||||
/* timeout - see if we have anything to send */
|
||||
for (i = 0; i < num_received; ++i) {
|
||||
uint8_t* pkt_data;
|
||||
size_t pkt_len;
|
||||
ldns_pkt* answer = responses[i].pkt;
|
||||
ldns_pkt2wire(&pkt_data, answer, &pkt_len);
|
||||
sendto(fd,pkt_data,pkt_len,0,(struct sockaddr *)&(responses[i].client_addr),sizeof(client_addr));
|
||||
free(pkt_data);
|
||||
ldns_pkt_free(answer);
|
||||
size_t pkt_len = sizeof(mesg);
|
||||
if ((r = getdns_msg_dict2wire_buf(responses[i].reply, mesg, &pkt_len))) {
|
||||
fprintf( stderr, "Could not convert DNS message dict to wireformat: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
}
|
||||
sendto(fd,mesg,pkt_len,0,(struct sockaddr *)&(responses[i].client_addr),sizeof(client_addr));
|
||||
getdns_dict_destroy(responses[i].reply);
|
||||
}
|
||||
num_received = 0;
|
||||
}
|
||||
}
|
||||
ldns_resolver_deep_free(resolver);
|
||||
|
||||
getdns_context_destroy(ctxt);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
@ -214,7 +256,6 @@ void timeout_3_cb(struct getdns_context *context,
|
|||
}
|
||||
|
||||
/* Temporarily disabled because of unpredictable results */
|
||||
#if 0
|
||||
START_TEST (getdns_context_set_timeout_3)
|
||||
{
|
||||
/*
|
||||
|
@ -290,7 +331,6 @@ START_TEST (getdns_context_set_timeout_3)
|
|||
|
||||
}
|
||||
END_TEST
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -309,12 +349,10 @@ getdns_context_set_timeout_suite (void)
|
|||
|
||||
/* Positive test cases */
|
||||
/* Temporarily disabled because of unpredictable results */
|
||||
#if 0
|
||||
TCase *tc_pos = tcase_create("Positive");
|
||||
tcase_set_timeout(tc_pos, 15.0);
|
||||
tcase_add_test(tc_pos, getdns_context_set_timeout_3);
|
||||
suite_add_tcase(s, tc_pos);
|
||||
#endif
|
||||
|
||||
return s;
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdio.h>
|
||||
#include <ldns/ldns.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
|
||||
|
@ -58,11 +57,25 @@ void* run_transport_server(void* data) {
|
|||
struct sockaddr_in serv_addr;
|
||||
uint8_t mesg[65536], tcplength[2];
|
||||
fd_set read_fds;
|
||||
ldns_rdf* answerfrom;
|
||||
ldns_resolver* resolver;
|
||||
size_t pkt_len;
|
||||
getdns_context *ctxt;
|
||||
getdns_return_t r;
|
||||
getdns_dict *dns_msg;
|
||||
getdns_bindata *qname;
|
||||
char *qname_str;
|
||||
uint32_t qtype, qid;
|
||||
int udp_count = 0;
|
||||
int tcp_count = 0;
|
||||
ldns_resolver_new_frm_file(&resolver, NULL);
|
||||
if ((r = getdns_context_create(&ctxt, 1))) {
|
||||
fprintf( stderr, "Could not create a getdns context: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
return NULL;
|
||||
}
|
||||
if ((r = getdns_context_set_resolution_type(ctxt, GETDNS_RESOLUTION_STUB))) {
|
||||
fprintf( stderr, "Could not set context in stub mode resolution: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
udp = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
tcp = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
@ -83,7 +96,6 @@ void* run_transport_server(void* data) {
|
|||
FD_ZERO(&read_fds);
|
||||
FD_SET(udp, &read_fds);
|
||||
FD_SET(tcp, &read_fds);
|
||||
ldns_pkt* pkt;
|
||||
int n = 0;
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 1;
|
||||
|
@ -91,7 +103,6 @@ void* run_transport_server(void* data) {
|
|||
int maxfdp1 = MAX(udp, tcp) + 1;
|
||||
int r = select(maxfdp1, &read_fds, NULL, NULL, &tv);
|
||||
if (r > 0) {
|
||||
ldns_pkt* query;
|
||||
socklen_t len = sizeof (client_addr);
|
||||
if (FD_ISSET(udp, &read_fds)) {
|
||||
n = recvfrom(udp, mesg, 65536, 0, (struct sockaddr *) &client_addr, &len);
|
||||
|
@ -107,37 +118,66 @@ void* run_transport_server(void* data) {
|
|||
break;
|
||||
}
|
||||
|
||||
ldns_wire2pkt(&query, mesg, n);
|
||||
ldns_resolver_send_pkt(&pkt, resolver, query);
|
||||
ldns_str2rdf_a(&answerfrom, "127.0.0.1");
|
||||
ldns_pkt_set_answerfrom(pkt, answerfrom);
|
||||
ldns_pkt_free(query);
|
||||
|
||||
ldns_buffer *send_buf;
|
||||
send_buf = ldns_buffer_new(LDNS_MIN_BUFLEN);
|
||||
ldns_pkt2buffer_wire(send_buf, pkt);
|
||||
if ((r = getdns_wire2msg_dict(mesg, n, &dns_msg))) {
|
||||
fprintf( stderr, "Could not convert wireformat to DNS message dict: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
if ((r = getdns_dict_get_bindata(dns_msg, "/question/qname", &qname))) {
|
||||
fprintf( stderr, "Could not get query name from request dict: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
if ((r = getdns_convert_dns_name_to_fqdn(qname, &qname_str))) {
|
||||
fprintf( stderr, "Could not convert qname to fqdn: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
if ((r = getdns_dict_get_int(dns_msg, "/question/qtype", &qtype))) {
|
||||
fprintf( stderr, "Could not get query type from request dict: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
if ((r = getdns_dict_get_int(dns_msg, "/header/id", &qid))) {
|
||||
fprintf( stderr, "Could not get message ID from request dict: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
getdns_dict_destroy(dns_msg);
|
||||
r = getdns_general_sync(ctxt, qname_str, qtype, NULL, &dns_msg);
|
||||
free(qname_str);
|
||||
if (r) {
|
||||
fprintf( stderr, "Could query for \"%s\" %d: \"%s\"\n", qname_str, (int)qtype
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
if ((r = getdns_dict_set_int(dns_msg, "/replies_tree/0/header/id", qid))) {
|
||||
fprintf( stderr, "Could not set message ID on reply dict: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
continue;
|
||||
}
|
||||
pkt_len = sizeof(mesg) - 2;
|
||||
if ((r = getdns_msg_dict2wire_buf(dns_msg, mesg + 2, &pkt_len))) {
|
||||
fprintf( stderr, "Could not convert DNS message dict to wireformat: \"%s\"\n"
|
||||
, getdns_get_errorstr_by_id(r));
|
||||
}
|
||||
getdns_dict_destroy(dns_msg);
|
||||
|
||||
if (udp_count > 0) {
|
||||
sendto(udp, (void*)ldns_buffer_begin(send_buf), ldns_buffer_position(send_buf),
|
||||
sendto(udp, mesg + 2, pkt_len,
|
||||
0, (struct sockaddr *) &client_addr, sizeof (client_addr));
|
||||
} else if (conn > 0) {
|
||||
uint8_t *send_array;
|
||||
/* add length of packet */
|
||||
send_array = LDNS_XMALLOC(uint8_t, ldns_buffer_position(send_buf) + 2);
|
||||
if(!send_array) return 0;
|
||||
ldns_write_uint16(send_array, ldns_buffer_position(send_buf));
|
||||
memcpy(send_array + 2, ldns_buffer_begin(send_buf), ldns_buffer_position(send_buf));
|
||||
if (write(conn, (void*)send_array, ldns_buffer_position(send_buf) + 2) == -1) return 0;
|
||||
LDNS_FREE(send_array);
|
||||
mesg[0] = (uint8_t) ((pkt_len >> 8) & 0xff);
|
||||
mesg[1] = (uint8_t) (pkt_len & 0xff);
|
||||
if (write(conn, mesg, pkt_len + 2) == -1) return 0;
|
||||
}
|
||||
LDNS_FREE(send_buf);
|
||||
ldns_pkt_free(pkt);
|
||||
} /* End of if */
|
||||
} /* end of while loop */
|
||||
close(udp);
|
||||
close(tcp);
|
||||
if (conn > 0) close(conn);
|
||||
ldns_resolver_deep_free(resolver);
|
||||
getdns_context_destroy(ctxt);
|
||||
tdata->udp_count = udp_count;
|
||||
tdata->tcp_count = tcp_count;
|
||||
return NULL;
|
||||
|
|
|
@ -299,9 +299,9 @@ function report() {
|
|||
pper=0
|
||||
uper=0
|
||||
else
|
||||
fper=`echo -e "scale=4\n$failed/$total*100" | bc | sed 's/00$//'`
|
||||
pper=`echo -e "scale=4\n$passed/$total*100" | bc | sed 's/00$//'`
|
||||
uper=`echo -e "scale=4\n$unknown/$total*100" | bc | sed 's/00$//'`
|
||||
fper=`awk -vN=$failed -vT=$total 'BEGIN{printf("%.0f",(N/T*100))}'`
|
||||
pper=`awk -vN=$passed -vT=$total 'BEGIN{printf("%.0f",(N/T*100))}'`
|
||||
uper=`awk -vN=$unknown -vT=$total 'BEGIN{printf("%.0f",(N/T*100))}'`
|
||||
fi
|
||||
echo
|
||||
echo -e "$tp: $passed ($pper %)\t$tf: $failed ($fper %)\t$tu: $unknown ($uper %)"
|
||||
|
|
Loading…
Reference in New Issue