1999-07-08 03:16:00 +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-02 02:54:16 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
1999-07-09 01:57:55 +00:00
|
|
|
#include <isc/app.h>
|
1999-07-08 03:16:00 +00:00
|
|
|
#include <isc/assertions.h>
|
|
|
|
#include <isc/error.h>
|
|
|
|
#include <isc/mem.h>
|
1999-07-22 01:34:31 +00:00
|
|
|
#include <isc/mutex.h>
|
1999-10-02 02:54:16 +00:00
|
|
|
#include <isc/net.h>
|
1999-07-08 03:16:00 +00:00
|
|
|
#include <isc/task.h>
|
|
|
|
#include <isc/thread.h>
|
|
|
|
#include <isc/result.h>
|
|
|
|
#include <isc/socket.h>
|
|
|
|
#include <isc/timer.h>
|
|
|
|
|
|
|
|
#include <dns/dispatch.h>
|
1999-07-09 01:57:55 +00:00
|
|
|
#include <dns/message.h>
|
1999-07-09 20:34:33 +00:00
|
|
|
#include <dns/rdatalist.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdataclass.h>
|
|
|
|
#include <dns/rdatatype.h>
|
1999-07-08 03:16:00 +00:00
|
|
|
|
1999-07-09 17:45:06 +00:00
|
|
|
#include "printmsg.h"
|
|
|
|
|
1999-07-22 01:34:31 +00:00
|
|
|
typedef struct {
|
|
|
|
int count;
|
|
|
|
isc_buffer_t render;
|
|
|
|
unsigned char render_buffer[1024];
|
|
|
|
dns_rdataset_t rdataset;
|
|
|
|
dns_rdatalist_t rdatalist;
|
|
|
|
dns_dispentry_t *resp;
|
|
|
|
} clictx_t;
|
|
|
|
|
1999-07-08 03:16:00 +00:00
|
|
|
isc_mem_t *mctx;
|
|
|
|
isc_taskmgr_t *manager;
|
|
|
|
isc_socketmgr_t *socketmgr;
|
|
|
|
dns_dispatch_t *disp;
|
1999-07-09 01:57:55 +00:00
|
|
|
isc_task_t *t0, *t1, *t2;
|
1999-07-22 01:34:31 +00:00
|
|
|
clictx_t clients[16]; /* lots of things might want to use this */
|
|
|
|
unsigned int client_count = 0;
|
|
|
|
isc_mutex_t client_lock;
|
1999-07-08 03:16:00 +00:00
|
|
|
|
1999-07-09 01:57:55 +00:00
|
|
|
void got_request(isc_task_t *, isc_event_t *);
|
|
|
|
void got_response(isc_task_t *, isc_event_t *);
|
1999-07-22 01:34:31 +00:00
|
|
|
void start_response(clictx_t *, char *, isc_task_t *);
|
1999-12-23 00:09:04 +00:00
|
|
|
static inline void CHECKRESULT(isc_result_t, char *);
|
1999-07-09 20:34:33 +00:00
|
|
|
void send_done(isc_task_t *, isc_event_t *);
|
1999-07-12 23:46:05 +00:00
|
|
|
void hex_dump(isc_buffer_t *);
|
|
|
|
|
|
|
|
void
|
|
|
|
hex_dump(isc_buffer_t *b)
|
|
|
|
{
|
|
|
|
unsigned int len;
|
|
|
|
isc_region_t r;
|
|
|
|
|
|
|
|
isc_buffer_remaining(b, &r);
|
|
|
|
|
|
|
|
printf("Buffer %p: used region base %p, length %d",
|
|
|
|
b, r.base, r.length);
|
|
|
|
for (len = 0 ; len < r.length ; len++) {
|
|
|
|
if (len % 16 == 0)
|
|
|
|
printf("\n");
|
|
|
|
printf("%02x ", r.base[len]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
1999-07-09 17:45:06 +00:00
|
|
|
|
|
|
|
static inline void
|
1999-12-23 00:09:04 +00:00
|
|
|
CHECKRESULT(isc_result_t result, char *msg)
|
1999-07-09 17:45:06 +00:00
|
|
|
{
|
|
|
|
if (result != DNS_R_SUCCESS) {
|
|
|
|
printf("%s: %s\n", msg, isc_result_totext(result));
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
1999-07-08 03:16:00 +00:00
|
|
|
|
1999-07-09 20:34:33 +00:00
|
|
|
void
|
|
|
|
send_done(isc_task_t *task, isc_event_t *ev_in)
|
|
|
|
{
|
|
|
|
isc_socketevent_t *ev = (isc_socketevent_t *)ev_in;
|
1999-07-22 01:34:31 +00:00
|
|
|
clictx_t *cli = (clictx_t *)ev_in->arg;
|
1999-07-09 20:34:33 +00:00
|
|
|
|
1999-07-09 20:45:58 +00:00
|
|
|
(void)task;
|
|
|
|
|
1999-07-09 20:34:33 +00:00
|
|
|
if (ev->result == ISC_R_SUCCESS) {
|
|
|
|
printf("Send done (SUCCESS)\n");
|
|
|
|
isc_event_free(&ev_in);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECKRESULT(ev->result, "send_done got event");
|
|
|
|
|
|
|
|
isc_event_free(&ev_in);
|
|
|
|
|
|
|
|
printf("--- removing response (FAILURE)\n");
|
1999-07-22 01:34:31 +00:00
|
|
|
dns_dispatch_removeresponse(disp, &cli->resp, NULL);
|
1999-07-09 20:34:33 +00:00
|
|
|
isc_app_shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-08 03:16:00 +00:00
|
|
|
void
|
1999-07-22 01:34:31 +00:00
|
|
|
start_response(clictx_t *cli, char *query, isc_task_t *task)
|
1999-07-09 01:57:55 +00:00
|
|
|
{
|
|
|
|
dns_messageid_t id;
|
|
|
|
isc_sockaddr_t from;
|
|
|
|
dns_message_t *msg;
|
1999-07-09 20:34:33 +00:00
|
|
|
isc_result_t result;
|
1999-09-10 20:25:51 +00:00
|
|
|
dns_name_t *name;
|
1999-07-09 20:34:33 +00:00
|
|
|
unsigned char namebuf[255];
|
|
|
|
isc_buffer_t target;
|
|
|
|
isc_buffer_t source;
|
|
|
|
isc_region_t region;
|
|
|
|
|
1999-07-22 01:34:31 +00:00
|
|
|
isc_buffer_init(&source, query, strlen(query), ISC_BUFFERTYPE_TEXT);
|
|
|
|
isc_buffer_add(&source, strlen(query));
|
|
|
|
isc_buffer_setactive(&source, strlen(query));
|
1999-07-09 20:34:33 +00:00
|
|
|
isc_buffer_init(&target, namebuf, sizeof(namebuf),
|
|
|
|
ISC_BUFFERTYPE_BINARY);
|
|
|
|
|
|
|
|
memset(&from, 0, sizeof(from));
|
|
|
|
from.length = sizeof(struct sockaddr_in);
|
1999-10-28 01:36:36 +00:00
|
|
|
#ifdef ISC_PLATFORM_HAVESALEN
|
1999-07-09 20:34:33 +00:00
|
|
|
from.type.sa.sa_len = sizeof(struct sockaddr_in);
|
1999-07-09 21:10:40 +00:00
|
|
|
#endif
|
1999-07-09 20:34:33 +00:00
|
|
|
from.type.sin.sin_port = htons(53);
|
|
|
|
from.type.sa.sa_family = AF_INET;
|
1999-07-16 00:47:22 +00:00
|
|
|
RUNTIME_CHECK(inet_aton("204.152.184.97",
|
|
|
|
&from.type.sin.sin_addr) == 1);
|
1999-07-09 20:34:33 +00:00
|
|
|
|
|
|
|
msg = NULL;
|
1999-07-24 00:55:35 +00:00
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &msg);
|
1999-07-09 20:34:33 +00:00
|
|
|
CHECKRESULT(result, "dns_message_create()");
|
|
|
|
|
1999-09-10 20:25:51 +00:00
|
|
|
name = NULL;
|
|
|
|
result = dns_message_gettempname(msg, &name);
|
|
|
|
CHECKRESULT(result, "dns_message_gettempname()");
|
|
|
|
|
|
|
|
dns_name_init(name, NULL);
|
|
|
|
result = dns_name_fromtext(name, &source, dns_rootname, ISC_FALSE,
|
|
|
|
&target);
|
|
|
|
CHECKRESULT(result, "dns_name_fromtext()");
|
|
|
|
|
|
|
|
dns_message_addname(msg, name, DNS_SECTION_QUESTION);
|
1999-07-09 20:34:33 +00:00
|
|
|
|
1999-07-22 01:34:31 +00:00
|
|
|
cli->rdatalist.rdclass = dns_rdataclass_in;
|
|
|
|
cli->rdatalist.type = dns_rdatatype_a;
|
|
|
|
cli->rdatalist.ttl = 0;
|
|
|
|
ISC_LIST_INIT(cli->rdatalist.rdata);
|
1999-07-09 20:34:33 +00:00
|
|
|
|
1999-07-22 01:34:31 +00:00
|
|
|
dns_rdataset_init(&cli->rdataset);
|
|
|
|
result = dns_rdatalist_tordataset(&cli->rdatalist, &cli->rdataset);
|
1999-07-09 20:34:33 +00:00
|
|
|
CHECKRESULT(result, "dns_rdatalist_tordataset()");
|
|
|
|
|
1999-09-10 20:25:51 +00:00
|
|
|
ISC_LIST_APPEND(name->list, &cli->rdataset, link);
|
1999-07-09 20:34:33 +00:00
|
|
|
|
|
|
|
result = printmessage(msg);
|
|
|
|
CHECKRESULT(result, "printmessage()");
|
|
|
|
|
1999-07-22 01:34:31 +00:00
|
|
|
isc_buffer_init(&cli->render, cli->render_buffer,
|
|
|
|
sizeof(cli->render_buffer), ISC_BUFFERTYPE_BINARY);
|
|
|
|
result = dns_message_renderbegin(msg, &cli->render);
|
1999-07-09 20:34:33 +00:00
|
|
|
CHECKRESULT(result, "dns_message_renderbegin()");
|
|
|
|
|
1999-07-22 01:34:31 +00:00
|
|
|
cli->rdataset.attributes |= DNS_RDATASETATTR_QUESTION;
|
1999-07-09 20:34:33 +00:00
|
|
|
|
1999-12-22 03:22:59 +00:00
|
|
|
result = dns_message_rendersection(msg, DNS_SECTION_QUESTION, 0);
|
1999-07-09 20:34:33 +00:00
|
|
|
CHECKRESULT(result, "dns_message_rendersection(QUESTION)");
|
|
|
|
|
1999-12-22 03:22:59 +00:00
|
|
|
result = dns_message_rendersection(msg, DNS_SECTION_ANSWER, 0);
|
1999-07-09 20:34:33 +00:00
|
|
|
CHECKRESULT(result, "dns_message_rendersection(ANSWER)");
|
|
|
|
|
1999-12-22 03:22:59 +00:00
|
|
|
result = dns_message_rendersection(msg, DNS_SECTION_ADDITIONAL, 0);
|
1999-07-09 20:34:33 +00:00
|
|
|
CHECKRESULT(result, "dns_message_rendersection(ADDITIONAL)");
|
|
|
|
|
1999-12-22 03:22:59 +00:00
|
|
|
result = dns_message_rendersection(msg, DNS_SECTION_AUTHORITY, 0);
|
1999-07-09 20:34:33 +00:00
|
|
|
CHECKRESULT(result, "dns_message_rendersection(AUTHORITY)");
|
1999-07-09 01:57:55 +00:00
|
|
|
|
|
|
|
printf("--- adding response\n");
|
1999-07-22 01:34:31 +00:00
|
|
|
RUNTIME_CHECK(isc_mutex_lock(&client_lock) == ISC_R_SUCCESS);
|
|
|
|
client_count++;
|
|
|
|
RUNTIME_CHECK(isc_mutex_unlock(&client_lock) == ISC_R_SUCCESS);
|
|
|
|
cli->resp = NULL;
|
|
|
|
result = dns_dispatch_addresponse(disp, &from, task, got_response,
|
|
|
|
cli, &id, &cli->resp);
|
1999-07-09 20:34:33 +00:00
|
|
|
CHECKRESULT(result, "dns_dispatch_addresponse");
|
|
|
|
|
1999-07-09 01:57:55 +00:00
|
|
|
printf("Assigned MessageID %d\n", id);
|
1999-07-09 20:34:33 +00:00
|
|
|
|
|
|
|
msg->opcode = dns_opcode_query;
|
|
|
|
msg->rcode = dns_rcode_noerror;
|
|
|
|
msg->flags = DNS_MESSAGEFLAG_RD;
|
|
|
|
msg->id = id;
|
|
|
|
|
|
|
|
result = dns_message_renderend(msg);
|
|
|
|
CHECKRESULT(result, "dns_message_renderend");
|
|
|
|
|
|
|
|
dns_message_destroy(&msg);
|
|
|
|
|
1999-07-22 01:34:31 +00:00
|
|
|
isc_buffer_used(&cli->render, ®ion);
|
1999-07-09 20:34:33 +00:00
|
|
|
result = isc_socket_sendto(dns_dispatch_getsocket(disp), ®ion,
|
1999-12-04 01:27:44 +00:00
|
|
|
task, send_done, cli->resp, &from, NULL);
|
1999-07-09 20:34:33 +00:00
|
|
|
CHECKRESULT(result, "isc_socket_sendto()");
|
1999-07-09 01:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
got_response(isc_task_t *task, isc_event_t *ev_in)
|
1999-07-08 03:16:00 +00:00
|
|
|
{
|
|
|
|
dns_dispatchevent_t *ev = (dns_dispatchevent_t *)ev_in;
|
|
|
|
dns_dispentry_t *resp = ev->sender;
|
1999-07-09 20:34:33 +00:00
|
|
|
dns_message_t *msg;
|
|
|
|
isc_result_t result;
|
1999-07-22 01:34:31 +00:00
|
|
|
unsigned int cnt;
|
1999-07-09 20:34:33 +00:00
|
|
|
|
1999-07-09 20:45:58 +00:00
|
|
|
(void)task;
|
|
|
|
|
1999-07-09 20:34:33 +00:00
|
|
|
printf("App: Got response (id %d). Result: %s\n",
|
|
|
|
ev->id, isc_result_totext(ev->result));
|
|
|
|
|
1999-07-22 01:34:31 +00:00
|
|
|
if (ev->result != ISC_R_SUCCESS) {
|
|
|
|
printf("--- ERROR, shutting down response slot\n");
|
|
|
|
printf("--- shutting down dispatcher\n");
|
|
|
|
dns_dispatch_cancel(disp);
|
|
|
|
printf("--- removing response\n");
|
|
|
|
dns_dispatch_removeresponse(disp, &resp, &ev);
|
|
|
|
RUNTIME_CHECK(isc_mutex_lock(&client_lock) == ISC_R_SUCCESS);
|
|
|
|
INSIST(client_count > 0);
|
|
|
|
client_count--;
|
|
|
|
cnt = client_count;
|
|
|
|
RUNTIME_CHECK(isc_mutex_unlock(&client_lock) == ISC_R_SUCCESS);
|
|
|
|
if (cnt == 0)
|
|
|
|
isc_app_shutdown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-07-09 20:34:33 +00:00
|
|
|
msg = NULL;
|
1999-07-24 00:55:35 +00:00
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg);
|
1999-07-09 20:34:33 +00:00
|
|
|
CHECKRESULT(result, "dns_message_create() failed");
|
1999-07-08 03:16:00 +00:00
|
|
|
|
1999-08-20 06:09:46 +00:00
|
|
|
result = dns_message_parse(msg, &ev->buffer, ISC_FALSE);
|
1999-07-09 20:34:33 +00:00
|
|
|
CHECKRESULT(result, "dns_message_parse() failed");
|
|
|
|
|
|
|
|
result = printmessage(msg);
|
|
|
|
CHECKRESULT(result, "printmessage() failed");
|
|
|
|
|
|
|
|
dns_message_destroy(&msg);
|
|
|
|
|
1999-07-22 01:34:31 +00:00
|
|
|
printf("--- shutting down dispatcher\n");
|
|
|
|
dns_dispatch_cancel(disp);
|
1999-07-09 20:34:33 +00:00
|
|
|
printf("--- removing response\n");
|
|
|
|
dns_dispatch_removeresponse(disp, &resp, &ev);
|
1999-07-22 01:34:31 +00:00
|
|
|
RUNTIME_CHECK(isc_mutex_lock(&client_lock) == ISC_R_SUCCESS);
|
|
|
|
INSIST(client_count > 0);
|
|
|
|
client_count--;
|
|
|
|
cnt = client_count;
|
|
|
|
RUNTIME_CHECK(isc_mutex_unlock(&client_lock) == ISC_R_SUCCESS);
|
|
|
|
if (cnt == 0)
|
|
|
|
isc_app_shutdown();
|
1999-07-09 01:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
got_request(isc_task_t *task, isc_event_t *ev_in)
|
|
|
|
{
|
|
|
|
dns_dispatchevent_t *ev = (dns_dispatchevent_t *)ev_in;
|
1999-07-22 01:34:31 +00:00
|
|
|
clictx_t *cli = (clictx_t *)ev_in->arg;
|
1999-07-09 17:45:06 +00:00
|
|
|
dns_message_t *msg;
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t result;
|
1999-07-22 01:34:31 +00:00
|
|
|
unsigned int cnt;
|
1999-07-09 17:45:06 +00:00
|
|
|
|
1999-07-09 20:34:33 +00:00
|
|
|
printf("App: Got request. Result: %s\n",
|
1999-07-09 17:45:06 +00:00
|
|
|
isc_result_totext(ev->result));
|
|
|
|
|
|
|
|
if (ev->result != DNS_R_SUCCESS) {
|
1999-07-22 01:34:31 +00:00
|
|
|
RUNTIME_CHECK(isc_mutex_lock(&client_lock) == ISC_R_SUCCESS);
|
|
|
|
printf("Got error, terminating CLIENT %p resp %p\n",
|
|
|
|
cli, cli->resp);
|
|
|
|
dns_dispatch_removerequest(disp, &cli->resp, &ev);
|
|
|
|
INSIST(client_count > 0);
|
|
|
|
client_count--;
|
|
|
|
cnt = client_count;
|
|
|
|
printf("CLIENT %p ENDING, %d remain\n", cli, client_count);
|
|
|
|
RUNTIME_CHECK(isc_mutex_unlock(&client_lock) == ISC_R_SUCCESS);
|
|
|
|
if (cnt == 0)
|
|
|
|
isc_app_shutdown();
|
1999-07-09 17:45:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-07-12 23:46:05 +00:00
|
|
|
hex_dump(&ev->buffer);
|
|
|
|
|
1999-07-09 17:45:06 +00:00
|
|
|
msg = NULL;
|
1999-07-24 00:55:35 +00:00
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg);
|
1999-07-09 17:45:06 +00:00
|
|
|
CHECKRESULT(result, "dns_message_create() failed");
|
|
|
|
|
1999-08-20 06:09:46 +00:00
|
|
|
result = dns_message_parse(msg, &ev->buffer, ISC_FALSE);
|
1999-07-09 17:45:06 +00:00
|
|
|
CHECKRESULT(result, "dns_message_parse() failed");
|
|
|
|
|
|
|
|
result = printmessage(msg);
|
|
|
|
CHECKRESULT(result, "printmessage() failed");
|
1999-07-08 03:16:00 +00:00
|
|
|
|
1999-07-09 17:45:06 +00:00
|
|
|
dns_message_destroy(&msg);
|
1999-07-08 22:12:37 +00:00
|
|
|
|
1999-07-09 20:34:33 +00:00
|
|
|
sleep (1);
|
1999-07-22 01:34:31 +00:00
|
|
|
cli->count++;
|
|
|
|
printf("App: Client %p ready, count == %d.\n", cli, cli->count);
|
|
|
|
switch (cli->count) {
|
|
|
|
case 4:
|
|
|
|
printf("--- starting DNS lookup\n");
|
|
|
|
dns_dispatch_freeevent(disp, cli->resp, &ev);
|
|
|
|
start_response(&clients[3], "flame.org", task);
|
|
|
|
start_response(&clients[4], "vix.com", task);
|
|
|
|
start_response(&clients[5], "isc.org", task);
|
1999-07-09 00:51:08 +00:00
|
|
|
break;
|
|
|
|
|
1999-07-22 01:34:31 +00:00
|
|
|
case 2:
|
1999-07-09 00:51:08 +00:00
|
|
|
printf("--- removing request\n");
|
1999-07-22 01:34:31 +00:00
|
|
|
dns_dispatch_removerequest(disp, &cli->resp, &ev);
|
1999-07-09 00:51:08 +00:00
|
|
|
printf("--- adding request\n");
|
1999-07-09 01:57:55 +00:00
|
|
|
RUNTIME_CHECK(dns_dispatch_addrequest(disp, task, got_request,
|
1999-07-22 01:34:31 +00:00
|
|
|
cli, &cli->resp)
|
1999-07-09 00:51:08 +00:00
|
|
|
== DNS_R_SUCCESS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-07-22 01:34:31 +00:00
|
|
|
dns_dispatch_freeevent(disp, cli->resp, &ev);
|
1999-07-09 00:51:08 +00:00
|
|
|
break;
|
1999-07-08 22:12:37 +00:00
|
|
|
}
|
1999-07-08 03:16:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
isc_socket_t *s0;
|
|
|
|
isc_sockaddr_t sockaddr;
|
1999-07-22 01:34:31 +00:00
|
|
|
unsigned int i;
|
1999-07-08 03:16:00 +00:00
|
|
|
|
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
|
1999-07-09 01:57:55 +00:00
|
|
|
RUNTIME_CHECK(isc_app_start() == ISC_R_SUCCESS);
|
|
|
|
|
1999-07-08 03:16:00 +00:00
|
|
|
/*
|
|
|
|
* EVERYTHING needs a memory context.
|
|
|
|
*/
|
|
|
|
mctx = NULL;
|
|
|
|
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
|
|
|
|
|
1999-07-08 22:12:37 +00:00
|
|
|
dns_result_register();
|
|
|
|
|
1999-07-08 03:16:00 +00:00
|
|
|
/*
|
|
|
|
* The task manager is independent (other than memory context)
|
|
|
|
*/
|
|
|
|
manager = NULL;
|
1999-07-09 00:51:08 +00:00
|
|
|
RUNTIME_CHECK(isc_taskmgr_create(mctx, 5, 0, &manager) ==
|
1999-07-08 03:16:00 +00:00
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
t0 = NULL;
|
|
|
|
RUNTIME_CHECK(isc_task_create(manager, NULL, 0, &t0) == ISC_R_SUCCESS);
|
1999-07-09 01:57:55 +00:00
|
|
|
t1 = NULL;
|
|
|
|
RUNTIME_CHECK(isc_task_create(manager, NULL, 0, &t1) == ISC_R_SUCCESS);
|
|
|
|
t2 = NULL;
|
|
|
|
RUNTIME_CHECK(isc_task_create(manager, NULL, 0, &t2) == ISC_R_SUCCESS);
|
1999-07-08 03:16:00 +00:00
|
|
|
|
|
|
|
socketmgr = NULL;
|
|
|
|
RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open up a random socket. Who cares where.
|
|
|
|
*/
|
|
|
|
s0 = NULL;
|
|
|
|
memset(&sockaddr, 0, sizeof(sockaddr));
|
|
|
|
sockaddr.type.sin.sin_family = AF_INET;
|
1999-07-08 22:12:37 +00:00
|
|
|
sockaddr.type.sin.sin_port = htons(5555);
|
1999-07-08 03:16:00 +00:00
|
|
|
sockaddr.length = sizeof (struct sockaddr_in);
|
1999-07-15 20:18:43 +00:00
|
|
|
RUNTIME_CHECK(isc_socket_create(socketmgr, PF_INET,
|
|
|
|
isc_sockettype_udp, &s0) ==
|
1999-07-08 03:16:00 +00:00
|
|
|
ISC_R_SUCCESS);
|
|
|
|
RUNTIME_CHECK(isc_socket_bind(s0, &sockaddr) == ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a dispatch context
|
|
|
|
*/
|
|
|
|
disp = NULL;
|
1999-07-09 02:47:55 +00:00
|
|
|
RUNTIME_CHECK(dns_dispatch_create(mctx, s0, t0, 512, 6, 1024,
|
1999-12-15 17:14:52 +00:00
|
|
|
17, 19, &disp) == ISC_R_SUCCESS);
|
1999-07-08 03:16:00 +00:00
|
|
|
|
1999-07-22 01:34:31 +00:00
|
|
|
RUNTIME_CHECK(isc_mutex_init(&client_lock) == ISC_R_SUCCESS);
|
|
|
|
RUNTIME_CHECK(isc_mutex_lock(&client_lock) == ISC_R_SUCCESS);
|
|
|
|
for (i = 0 ; i < 2 ; i++) {
|
|
|
|
clients[i].count = 0;
|
|
|
|
clients[i].resp = NULL;
|
|
|
|
RUNTIME_CHECK(dns_dispatch_addrequest(disp, t1, got_request,
|
|
|
|
&clients[i],
|
|
|
|
&clients[i].resp)
|
|
|
|
== ISC_R_SUCCESS);
|
|
|
|
client_count++;
|
|
|
|
}
|
|
|
|
RUNTIME_CHECK(isc_mutex_unlock(&client_lock) == ISC_R_SUCCESS);
|
1999-07-08 03:16:00 +00:00
|
|
|
|
1999-07-09 01:57:55 +00:00
|
|
|
isc_app_run();
|
|
|
|
|
1999-07-28 23:04:33 +00:00
|
|
|
fprintf(stderr, "canceling dispatcher\n");
|
1999-07-22 10:23:50 +00:00
|
|
|
dns_dispatch_cancel(disp);
|
|
|
|
|
1999-07-28 23:04:33 +00:00
|
|
|
fprintf(stderr, "detaching from socket\n");
|
1999-07-08 22:12:37 +00:00
|
|
|
isc_socket_detach(&s0);
|
1999-07-09 01:57:55 +00:00
|
|
|
|
1999-07-28 23:04:33 +00:00
|
|
|
fprintf(stderr, "detaching from dispatcher\n");
|
1999-07-13 00:25:21 +00:00
|
|
|
dns_dispatch_detach(&disp);
|
1999-07-08 22:12:37 +00:00
|
|
|
|
1999-07-08 03:16:00 +00:00
|
|
|
fprintf(stderr, "Destroying socket manager\n");
|
|
|
|
isc_socketmgr_destroy(&socketmgr);
|
|
|
|
|
1999-07-09 01:57:55 +00:00
|
|
|
isc_task_shutdown(t0);
|
|
|
|
isc_task_detach(&t0);
|
|
|
|
isc_task_shutdown(t1);
|
|
|
|
isc_task_detach(&t1);
|
|
|
|
isc_task_shutdown(t2);
|
|
|
|
isc_task_detach(&t2);
|
|
|
|
|
1999-07-08 03:16:00 +00:00
|
|
|
fprintf(stderr, "Destroying task manager\n");
|
|
|
|
isc_taskmgr_destroy(&manager);
|
|
|
|
|
1999-07-09 20:34:33 +00:00
|
|
|
isc_mem_stats(mctx, stderr);
|
1999-07-08 03:16:00 +00:00
|
|
|
isc_mem_destroy(&mctx);
|
|
|
|
|
1999-07-09 01:57:55 +00:00
|
|
|
isc_app_finish();
|
|
|
|
|
1999-07-08 03:16:00 +00:00
|
|
|
return (0);
|
|
|
|
}
|