sig0_test.c revision bf7c02293f883118784f7952944fa3e2bce98078
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer/*
f3064bfd1b75f7408cff6dbdb864ad62390307d3Mark Andrews * Copyright (C) 1999 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * purpose with or without fee is hereby granted, provided that the above
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * copyright notice and this permission notice appear in all copies.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * SOFTWARE.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews#include <config.h>
47058d17266420179fa294de6b82d8fb5b918df4Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <stddef.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <stdlib.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <string.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/app.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/boolean.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/assertions.h>
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington#include <isc/commandline.h>
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson#include <isc/entropy.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/error.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/log.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/mem.h>
1893b56ef9f5f2bc2a0fbe80d3c6b69df1bdc7c2Michael Sawyer#include <isc/mutex.h>
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer#include <isc/net.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <isc/task.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <isc/timer.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <isc/socket.h>
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer#include <isc/util.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/dnssec.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/events.h>
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson#include <dns/fixedname.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/keyvalues.h>
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer#include <dns/message.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/name.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <dns/rdataset.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <dns/resolver.h>
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellington#include <dns/result.h>
fb2c34419d268d36acb222e08e6f789b45a81306Mark Andrews#include <dns/types.h>
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellington
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <dst/result.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <dst/dst.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews#define CHECK(str, x) { \
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews if ((x) != ISC_R_SUCCESS) { \
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellington printf("%s: %s\n", (str), isc_result_totext(x)); \
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellington exit(-1); \
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellington } \
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellington}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellingtonisc_mutex_t lock;
688a4c50c2025a683d8d2bf5bb53a591556df4fcAndreas Gustafssondst_key_t *key;
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyerisc_mem_t *mctx;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerunsigned char qdata[1024], rdata[1024];
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerisc_buffer_t qbuffer, rbuffer;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerisc_taskmgr_t *taskmgr;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerisc_entropy_t *ent = NULL;
da5d1cf1b1aa29ae53a0427be49291b04bd60549Mark Andrewsisc_task_t *task1;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerisc_log_t *log = NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerisc_logconfig_t *logconfig = NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerisc_socket_t *s;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerisc_sockaddr_t address;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerchar output[10 * 1024];
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerisc_buffer_t outbuf;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic void
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyersenddone(isc_task_t *task, isc_event_t *event) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_socketevent_t *sevent = (isc_socketevent_t *)event;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer REQUIRE(sevent != NULL);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer REQUIRE(sevent->ev_type == ISC_SOCKEVENT_SENDDONE);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer REQUIRE(task == task1);
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("senddone\n");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_event_free(&event);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic void
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellingtonrecvdone(isc_task_t *task, isc_event_t *event) {
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington isc_socketevent_t *sevent = (isc_socketevent_t *)event;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington isc_buffer_t source;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington isc_result_t result;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington dns_message_t *response;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE(sevent != NULL);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE(sevent->ev_type == ISC_SOCKEVENT_RECVDONE);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE(task == task1);
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("recvdone\n");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (sevent->result != ISC_R_SUCCESS) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("failed\n");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer exit(-1);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
e32394a2ac3466a2235f79ee32c247a11be42a8dAndreas Gustafsson
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_init(&source, sevent->region.base, sevent->region.length);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_add(&source, sevent->n);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer response = NULL;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response);
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington CHECK("dns_message_create", result);
36c754f274dd439e5a7ebf2401427c1d51b21302Brian Wellington result = dns_message_parse(response, &source, ISC_FALSE);
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington CHECK("dns_message_parse", result);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_init(&outbuf, output, sizeof(output));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_message_totext(response, 0, &outbuf);
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington CHECK("dns_message_totext", result);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("%.*s\n", (int)isc_buffer_usedlength(&outbuf),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (char *)isc_buffer_base(&outbuf));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_message_destroy(&response);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_event_free(&event);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington isc_app_shutdown();
9a762177e6a0aff3ea5c00f87568c8ae3cd0e6c7Andreas Gustafsson}
9a762177e6a0aff3ea5c00f87568c8ae3cd0e6c7Andreas Gustafsson
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic void
066cb385cd8f801dd3757db2922c9b1f343e65edAndreas Gustafssonbuildquery(void) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_result_t result;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington dns_rdataset_t *question = NULL;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington dns_name_t *qname = NULL;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington isc_region_t r, inr;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_message_t *query;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer char nametext[] = "host.example";
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington isc_buffer_t namesrc, namedst;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington unsigned char namedata[256];
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington isc_sockaddr_t sa;
cc48bb397fa6ba889f25157840492e68114dec8fBrian Wellington
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington query = NULL;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &query);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington CHECK("dns_message_create", result);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington result = dns_message_setsig0key(query, key);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington CHECK("dns_message_setsig0key", result);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington result = dns_message_gettemprdataset(query, &question);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer CHECK("dns_message_gettemprdataset", result);
cc48bb397fa6ba889f25157840492e68114dec8fBrian Wellington dns_rdataset_init(question);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_rdataset_makequestion(question, dns_rdataclass_in,
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_rdatatype_a);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington result = dns_message_gettempname(query, &qname);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington CHECK("dns_message_gettempname", result);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington isc_buffer_init(&namesrc, nametext, strlen(nametext));
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington isc_buffer_add(&namesrc, strlen(nametext));
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington isc_buffer_init(&namedst, namedata, sizeof namedata);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_name_init(qname, NULL);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington result = dns_name_fromtext(qname, &namesrc, dns_rootname, ISC_FALSE,
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington &namedst);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington CHECK("dns_name_fromtext", result);
c38b92000c0f1a95daaad5468777e165b8047de9Mark Andrews ISC_LIST_APPEND(qname->list, question, link);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_message_addname(query, qname, DNS_SECTION_QUESTION);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington isc_buffer_init(&qbuffer, qdata, sizeof(qdata));
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington result = dns_message_renderbegin(query, &qbuffer);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington CHECK("dns_message_renderbegin", result);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington result = dns_message_rendersection(query, DNS_SECTION_QUESTION, 0);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington CHECK("dns_message_rendersection(question)", result);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington result = dns_message_rendersection(query, DNS_SECTION_ANSWER, 0);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington CHECK("dns_message_rendersection(answer)", result);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington result = dns_message_rendersection(query, DNS_SECTION_AUTHORITY, 0);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington CHECK("dns_message_rendersection(auth)", result);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington result = dns_message_rendersection(query, DNS_SECTION_ADDITIONAL, 0);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington CHECK("dns_message_rendersection(add)", result);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington result = dns_message_renderend(query);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington CHECK("dns_message_renderend", result);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington isc_buffer_init(&outbuf, output, sizeof(output));
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington result = dns_message_totext(query, 0, &outbuf);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington CHECK("dns_message_totext", result);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington printf("%.*s\n", (int)isc_buffer_usedlength(&outbuf),
2a23a625246acfbf6ff92b86a6b8b9df59dbeaa4Mark Andrews (char *)isc_buffer_base(&outbuf));
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews isc_buffer_usedregion(&qbuffer, &r);
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews isc_sockaddr_any(&sa);
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews result = isc_socket_bind(s, &sa);
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews CHECK("isc_socket_bind", result);
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews result = isc_socket_sendto(s, &r, task1, senddone, NULL, &address,
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews NULL);
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews CHECK("isc_socket_sendto", result);
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews inr.base = rdata;
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews inr.length = sizeof(rdata);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington result = isc_socket_recv(s, &inr, 1, task1, recvdone, NULL);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington CHECK("isc_socket_recv", result);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_message_destroy(&query);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington}
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellingtonint
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellingtonmain(int argc, char *argv[]) {
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington isc_boolean_t verbose = ISC_FALSE;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington isc_socketmgr_t *socketmgr;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington isc_timermgr_t *timermgr;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington struct in_addr inaddr;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_fixedname_t fname;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_name_t *name;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington isc_buffer_t b;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington int ch;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington isc_result_t result;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington in_port_t port = 53;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington RUNTIME_CHECK(isc_app_start() == ISC_R_SUCCESS);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington RUNTIME_CHECK(isc_mutex_init(&lock) == ISC_R_SUCCESS);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington mctx = NULL;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington while ((ch = isc_commandline_parse(argc, argv, "vp:")) != -1) {
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington switch (ch) {
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington case 'v':
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer verbose = ISC_TRUE;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case 'p':
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer port = (unsigned int)atoi(isc_commandline_argument);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews }
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer RUNTIME_CHECK(isc_entropy_create(mctx, &ent) == ISC_R_SUCCESS);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson RUNTIME_CHECK(dst_lib_init(mctx, ent, 0) == ISC_R_SUCCESS);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_result_register();
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dst_result_register();
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer taskmgr = NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer RUNTIME_CHECK(isc_taskmgr_create(mctx, 2, 0, &taskmgr) ==
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer ISC_R_SUCCESS);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer task1 = NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer RUNTIME_CHECK(isc_task_create(taskmgr, 0, &task1) == ISC_R_SUCCESS);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer timermgr = NULL;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence RUNTIME_CHECK(isc_timermgr_create(mctx, &timermgr) == ISC_R_SUCCESS);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer socketmgr = NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer s = NULL;
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson RUNTIME_CHECK(isc_socket_create(socketmgr, PF_INET,
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson isc_sockettype_udp, &s) ==
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_R_SUCCESS);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer inaddr.s_addr = htonl(INADDR_LOOPBACK);
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson isc_sockaddr_fromin(&address, &inaddr, port);
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_fixedname_init(&fname);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington name = dns_fixedname_name(&fname);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_init(&b, "child.example.", strlen("child.example."));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_add(&b, strlen("child.example."));
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson result = dns_name_fromtext(name, &b, dns_rootname, ISC_FALSE, NULL);
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson CHECK("dns_name_fromtext", result);
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington key = NULL;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dst_key_fromfile(name, 4017, DNS_KEYALG_DSA,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer DST_TYPE_PUBLIC | DST_TYPE_PRIVATE,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer NULL, mctx, &key);
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson CHECK("dst_key_fromfile", result);
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington buildquery();
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington (void)isc_app_run();
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrews isc_task_shutdown(task1);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_task_detach(&task1);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_taskmgr_destroy(&taskmgr);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_socket_detach(&s);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_socketmgr_destroy(&socketmgr);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_timermgr_destroy(&timermgr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dst_key_free(&key);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dst_lib_destroy();
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_entropy_detach(&ent);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_log_destroy(&log);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (verbose)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_mem_stats(mctx, stdout);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_mem_destroy(&mctx);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews DESTROYLOCK(&lock);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_app_finish();
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer return (0);
38cf6e52ce4b33795713388824b69d78e430b115Michael Sawyer}
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer