Set OPCODE in header too

This commit is contained in:
Willem Toorop 2016-04-28 13:44:28 +02:00
parent d841582d67
commit 04b3830fb6
1 changed files with 39 additions and 14 deletions

View File

@ -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)