1999-10-04 20:25:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1998, 1999 Internet Software Consortium.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
1999-10-16 00:38:21 +00:00
|
|
|
#include <isc/app.h>
|
1999-10-04 20:25:05 +00:00
|
|
|
#include <isc/assertions.h>
|
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/error.h>
|
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/task.h>
|
|
|
|
#include <isc/thread.h>
|
|
|
|
#include <isc/result.h>
|
|
|
|
#include <isc/sockaddr.h>
|
|
|
|
#include <isc/net.h>
|
|
|
|
|
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/address.h>
|
|
|
|
|
|
|
|
isc_mem_t *mctx;
|
|
|
|
isc_taskmgr_t *manager;
|
|
|
|
|
1999-10-16 00:38:21 +00:00
|
|
|
static void lookup_callback(isc_task_t *, isc_event_t *);
|
|
|
|
static void fatal(char *, ...);
|
|
|
|
static inline void check_result(isc_result_t, char *);
|
|
|
|
|
1999-10-04 20:25:05 +00:00
|
|
|
static void
|
|
|
|
fatal(char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
check_result(isc_result_t result, char *msg)
|
|
|
|
{
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("%s: %s", msg, isc_result_totext(result));
|
|
|
|
}
|
|
|
|
|
1999-10-16 00:38:21 +00:00
|
|
|
static void
|
|
|
|
lookup_callback(isc_task_t *task, isc_event_t *ev)
|
|
|
|
{
|
|
|
|
dns_name_t *name;
|
|
|
|
dns_adbhandle_t *handle;
|
|
|
|
|
|
|
|
printf("Task %p got event %p type %08x from %p, arg %p\n",
|
|
|
|
task, ev, ev->type, ev->sender, ev->arg);
|
|
|
|
|
|
|
|
name = ev->arg;
|
|
|
|
handle = ev->sender;
|
|
|
|
|
|
|
|
isc_event_free(&ev);
|
|
|
|
isc_app_shutdown();
|
|
|
|
}
|
|
|
|
|
1999-10-04 20:25:05 +00:00
|
|
|
int
|
1999-10-06 22:12:04 +00:00
|
|
|
main(int argc, char **argv)
|
1999-10-04 20:25:05 +00:00
|
|
|
{
|
|
|
|
isc_task_t *t1, *t2;
|
|
|
|
isc_sockaddr_t sockaddr;
|
|
|
|
struct in_addr ina;
|
|
|
|
isc_result_t result;
|
1999-10-12 02:06:08 +00:00
|
|
|
dns_name_t name1, name2;
|
1999-10-04 20:25:05 +00:00
|
|
|
isc_buffer_t t, namebuf;
|
1999-10-12 02:06:08 +00:00
|
|
|
unsigned char namestorage1[512];
|
|
|
|
unsigned char namestorage2[512];
|
1999-10-10 17:13:21 +00:00
|
|
|
dns_view_t *view;
|
1999-10-04 20:25:05 +00:00
|
|
|
dns_adb_t *adb;
|
1999-10-14 00:50:00 +00:00
|
|
|
dns_adbhandle_t *handle;
|
1999-10-04 20:25:05 +00:00
|
|
|
|
1999-10-06 22:12:04 +00:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
|
1999-10-04 20:25:05 +00:00
|
|
|
dns_result_register();
|
1999-10-16 00:38:21 +00:00
|
|
|
result = isc_app_start();
|
|
|
|
check_result(result, "isc_app_start()");
|
1999-10-04 20:25:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* EVERYTHING needs a memory context.
|
|
|
|
*/
|
|
|
|
mctx = NULL;
|
|
|
|
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The task manager is independent (other than memory context)
|
|
|
|
*/
|
|
|
|
manager = NULL;
|
|
|
|
result = isc_taskmgr_create(mctx, 2, 0, &manager);
|
|
|
|
check_result(result, "isc_taskmgr_create");
|
|
|
|
|
|
|
|
t1 = NULL;
|
|
|
|
result = isc_task_create(manager, NULL, 0, &t1);
|
|
|
|
check_result(result, "isc_task_create t1");
|
|
|
|
t2 = NULL;
|
|
|
|
result = isc_task_create(manager, NULL, 0, &t2);
|
|
|
|
check_result(result, "isc_task_create t2");
|
|
|
|
|
|
|
|
printf("task 1 = %p\n", t1);
|
|
|
|
printf("task 2 = %p\n", t2);
|
|
|
|
|
1999-10-10 17:13:21 +00:00
|
|
|
view = NULL;
|
|
|
|
result = dns_view_create(mctx, dns_rdataclass_in, "foo", &view);
|
|
|
|
check_result(result, "dns_view_create");
|
|
|
|
|
1999-10-04 20:25:05 +00:00
|
|
|
/*
|
|
|
|
* Create the address database.
|
|
|
|
*/
|
|
|
|
adb = NULL;
|
1999-10-10 17:13:21 +00:00
|
|
|
result = dns_adb_create(mctx, view, &adb);
|
1999-10-04 20:25:05 +00:00
|
|
|
check_result(result, "dns_adb_create");
|
|
|
|
|
1999-10-05 23:50:43 +00:00
|
|
|
#define NAME1 "nonexistant.flame.org."
|
1999-10-12 02:06:08 +00:00
|
|
|
#define NAME2 "badname.isc.org."
|
1999-10-04 20:25:05 +00:00
|
|
|
|
|
|
|
isc_buffer_init(&t, NAME1, sizeof NAME1 - 1, ISC_BUFFERTYPE_TEXT);
|
|
|
|
isc_buffer_add(&t, strlen(NAME1));
|
1999-10-12 02:06:08 +00:00
|
|
|
isc_buffer_init(&namebuf, namestorage1, sizeof namestorage1,
|
1999-10-04 20:25:05 +00:00
|
|
|
ISC_BUFFERTYPE_BINARY);
|
1999-10-12 02:06:08 +00:00
|
|
|
dns_name_init(&name1, NULL);
|
|
|
|
result = dns_name_fromtext(&name1, &t, dns_rootname, ISC_FALSE,
|
1999-10-04 20:25:05 +00:00
|
|
|
&namebuf);
|
1999-10-12 02:06:08 +00:00
|
|
|
check_result(result, "dns_name_fromtext NAME1");
|
|
|
|
|
|
|
|
isc_buffer_init(&t, NAME2, sizeof NAME2 - 1, ISC_BUFFERTYPE_TEXT);
|
|
|
|
isc_buffer_add(&t, strlen(NAME2));
|
|
|
|
isc_buffer_init(&namebuf, namestorage2, sizeof namestorage2,
|
|
|
|
ISC_BUFFERTYPE_BINARY);
|
|
|
|
dns_name_init(&name2, NULL);
|
|
|
|
result = dns_name_fromtext(&name2, &t, dns_rootname, ISC_FALSE,
|
|
|
|
&namebuf);
|
|
|
|
check_result(result, "dns_name_fromtext NAME2");
|
1999-10-04 20:25:05 +00:00
|
|
|
|
1999-10-05 23:50:43 +00:00
|
|
|
/*
|
|
|
|
* Store this address for this name.
|
|
|
|
*/
|
|
|
|
ina.s_addr = inet_addr("1.2.3.4");
|
|
|
|
isc_sockaddr_fromin(&sockaddr, &ina, 53);
|
1999-10-12 02:06:08 +00:00
|
|
|
result = dns_adb_insert(adb, &name1, &sockaddr);
|
1999-10-05 23:50:43 +00:00
|
|
|
check_result(result, "dns_adb_insert 1.2.3.4");
|
|
|
|
printf("Added 1.2.3.4\n");
|
|
|
|
|
|
|
|
ina.s_addr = inet_addr("1.2.3.5");
|
|
|
|
isc_sockaddr_fromin(&sockaddr, &ina, 53);
|
1999-10-12 02:06:08 +00:00
|
|
|
result = dns_adb_insert(adb, &name1, &sockaddr);
|
1999-10-05 23:50:43 +00:00
|
|
|
check_result(result, "dns_adb_insert 1.2.3.5");
|
|
|
|
printf("Added 1.2.3.5\n");
|
|
|
|
|
|
|
|
ina.s_addr = inet_addr("1.2.3.6");
|
|
|
|
isc_sockaddr_fromin(&sockaddr, &ina, 53);
|
1999-10-12 02:06:08 +00:00
|
|
|
result = dns_adb_insert(adb, &name1, &sockaddr);
|
1999-10-05 23:50:43 +00:00
|
|
|
check_result(result, "dns_adb_insert 1.2.3.6");
|
|
|
|
printf("Added 1.2.3.6\n");
|
1999-10-04 20:25:05 +00:00
|
|
|
|
1999-10-12 02:06:08 +00:00
|
|
|
ina.s_addr = inet_addr("1.2.3.5");
|
|
|
|
isc_sockaddr_fromin(&sockaddr, &ina, 53);
|
|
|
|
result = dns_adb_insert(adb, &name2, &sockaddr);
|
|
|
|
check_result(result, "dns_adb_insert 1.2.3.5");
|
|
|
|
printf("Added 1.2.3.5\n");
|
|
|
|
|
1999-10-14 00:50:00 +00:00
|
|
|
/*
|
|
|
|
* Try to look up a name or two.
|
|
|
|
*/
|
|
|
|
handle = NULL;
|
1999-10-16 00:38:21 +00:00
|
|
|
result = dns_adb_lookup(adb, t2, lookup_callback, &name1,
|
1999-10-14 00:50:00 +00:00
|
|
|
&name1, &name1, &handle);
|
|
|
|
check_result(result, "dns_adb_lookup name1");
|
|
|
|
check_result(handle->result, "handle->result");
|
|
|
|
|
1999-10-16 00:38:21 +00:00
|
|
|
dns_adb_dump(adb, stderr);
|
|
|
|
dns_adb_dumphandle(adb, handle, stderr);
|
|
|
|
|
1999-10-14 00:50:00 +00:00
|
|
|
/*
|
|
|
|
* delete the names, and kill the adb
|
|
|
|
*/
|
1999-10-12 02:06:08 +00:00
|
|
|
result = dns_adb_deletename(adb, &name1);
|
|
|
|
check_result(result, "dns_adb_deletename name1");
|
|
|
|
result = dns_adb_deletename(adb, &name2);
|
|
|
|
check_result(result, "dns_adb_deletename name2");
|
1999-10-04 20:25:05 +00:00
|
|
|
|
|
|
|
dns_adb_dump(adb, stderr);
|
1999-10-16 00:38:21 +00:00
|
|
|
dns_adb_dumphandle(adb, handle, stderr);
|
|
|
|
|
|
|
|
isc_app_run();
|
1999-10-04 20:25:05 +00:00
|
|
|
|
1999-10-14 00:50:00 +00:00
|
|
|
dns_adb_done(adb, &handle);
|
|
|
|
|
1999-10-16 00:38:21 +00:00
|
|
|
isc_task_detach(&t1);
|
|
|
|
isc_task_detach(&t2);
|
|
|
|
|
1999-10-04 20:25:05 +00:00
|
|
|
isc_mem_stats(mctx, stdout);
|
|
|
|
dns_adb_destroy(&adb);
|
|
|
|
|
1999-10-12 02:06:08 +00:00
|
|
|
dns_view_detach(&view);
|
|
|
|
|
1999-10-04 20:25:05 +00:00
|
|
|
fprintf(stderr, "Destroying task manager\n");
|
|
|
|
isc_taskmgr_destroy(&manager);
|
|
|
|
|
|
|
|
isc_mem_stats(mctx, stdout);
|
|
|
|
isc_mem_destroy(&mctx);
|
|
|
|
|
1999-10-16 00:38:21 +00:00
|
|
|
isc_app_finish();
|
|
|
|
|
1999-10-04 20:25:05 +00:00
|
|
|
return (0);
|
|
|
|
}
|