From 04b3830fb62509922d6073f20c12f7482d84602b Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Thu, 28 Apr 2016 13:44:28 +0200 Subject: [PATCH] Set OPCODE in header too --- src/test/scratchpad.c | 53 +++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/src/test/scratchpad.c b/src/test/scratchpad.c index d3c6bfbe..e845299b 100644 --- a/src/test/scratchpad.c +++ b/src/test/scratchpad.c @@ -11,10 +11,11 @@ int main() getdns_dict *extensions = NULL; getdns_bindata ipv4 = { 4, (uint8_t*)"IPv4" }; /* 185.49.141.37 */ - getdns_bindata nsip = { 4, (uint8_t*)"\xb9\x31\x8d\x25" }; + getdns_bindata nsip = { 4, (uint8_t*)"\xb9\x31\x8c\x3c" }; getdns_dict *upstream = NULL; getdns_list *upstreams = NULL; getdns_dict *response = NULL; + uint32_t value; char *str; if ((r = getdns_context_create(&ctx, 1))) @@ -24,21 +25,12 @@ int main() fprintf(stderr, "Could not create dictionary"); r = GETDNS_RETURN_MEMORY_ERROR; - } else if ((r = getdns_dict_set_int(extensions, "/header/cd", 1))) - fprintf(stderr, "Could not set CD bit"); - - else if ((r = getdns_dict_set_int(extensions, "/header/rd", 0))) + } else if ((r = getdns_dict_set_int(extensions, "/header/rd", 0))) fprintf(stderr, "Could not set RD bit"); else if ((r = getdns_dict_set_int(extensions, "/add_opt_parameters/do_bit", 1))) fprintf(stderr, "Could not set qtype"); - else if (!(str = getdns_pretty_print_dict(extensions))) - fprintf(stderr, "Could not pretty print dict"); - - else if(printf("extensions: %s\n", str), free(str), 0) - ; - else if (!(upstream = getdns_dict_create_with_context(ctx))) { fprintf(stderr, "Could not create upstream dictionary"); r = GETDNS_RETURN_MEMORY_ERROR; @@ -62,13 +54,46 @@ int main() else if ((r = getdns_context_set_upstream_recursive_servers(ctx, upstreams))) fprintf(stderr, "Could not set upstreams list"); - else if ((r = getdns_address_sync(ctx, "getdnsapi.net", extensions, &response))) - fprintf(stderr, "Could not do address lookup"); + else if ((r = getdns_general_sync(ctx, "bogus.nlnetlabs.nl.", GETDNS_RRTYPE_TXT, extensions, &response))) + fprintf(stderr, "Could not do lookup"); + + else if ((r = getdns_dict_get_int(response, "status", &value))) + fprintf(stderr, "Could not get status from response"); + + else if (value != GETDNS_RESPSTATUS_GOOD) { + fprintf(stderr, "response['status'] != GETDNS_RESPSTATUS_GOOD"); + r = GETDNS_RETURN_GENERIC_ERROR; + + } else if ((r = getdns_dict_get_int(response, "/replies_tree/0/header/rd", &value))) + fprintf(stderr, "Could not get RD bit from header"); + + else if (value != 0) { + fprintf(stderr, "RD bit != 0"); + r = GETDNS_RETURN_GENERIC_ERROR; + + } else if ((r = getdns_dict_get_int(response, "/replies_tree/0/header/ancount", &value))) + fprintf(stderr, "Could not get ANCOUNT from header"); + + else if (value != 2) { + fprintf(stderr, "ANCOUNT != 2"); + r = GETDNS_RETURN_GENERIC_ERROR; + + } else if ((r = getdns_dict_set_int(extensions, "/header/opcode", GETDNS_OPCODE_STATUS))) + fprintf(stderr, "Could not set opcode"); + + else if ((r = getdns_general_sync(ctx, "bogus.nlnetlabs.nl.", GETDNS_RRTYPE_TXT, extensions, &response))) + fprintf(stderr, "Could not do lookup"); + + else if ((r = getdns_dict_remove_name(response, "replies_full"))) + fprintf(stderr, "Could not remove reponse['replies_full']"); + + else if ((r = getdns_dict_remove_name(response, "/replies_tree/0/header/id"))) + fprintf(stderr, "Could not remove ID from response"); else if (!(str = getdns_pretty_print_dict(response))) fprintf(stderr, "Could not pretty print dict"); - else if(printf("response: %s\n", str), free(str), 0) + else if(printf("%s\n", str), free(str), 0) ; if (response)