dighost.c revision df5503799f5d2609cc759a7a1f3274daeb728236
/*
* Copyright (C) 2000 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 <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
extern int h_errno;
#include <isc/assertions.h>
#include <isc/sockaddr.h>
#include <dns/fixedname.h>
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
#include <dns/rdataclass.h>
#include <dns/rdatatype.h>
unsigned int timeout;
int sendcount = 0;
extern isc_boolean_t short_form;
static void
free_lists(void);
static void
hex_dump(isc_buffer_t *b) {
unsigned int len;
isc_region_t r;
isc_buffer_remainingregion(b, &r);
printf("\n");
}
if (len % 16 != 0)
printf("\n");
}
void
free_lists();
exit(1);
}
inline void
if (result != ISC_R_SUCCESS)
}
/* Tests if a field is a class, without needing isc libs
initialized. This list will have to be manually kept in
sync with what the libs support. */
const int numclasses = 3;
int i;
for (i = 0; i < numclasses; i++)
return ISC_TRUE;
return ISC_FALSE;
}
/* Tests if a field is a type, without needing isc libs
initialized. This list will have to be manually kept in
sync with what the libs support. */
"soa", "mb", "mg", "mr", "null",
"wks", "ptr", "hinfo", "minfo",
"mx", "txt", "rp", "afsdb",
"x25", "isdn", "rt", "nsap",
"nsap_ptr", "sig", "key", "px",
"gpos", "aaaa", "loc", "nxt",
"srv", "naptr", "kx", "cert",
"a6", "dname", "opt", "unspec",
"tkey", "tsig", "axfr"};
const int numtypes = 41;
int i;
for (i = 0; i < numtypes; i++) {
return ISC_TRUE;
}
return ISC_FALSE;
}
static void
setup_system(void) {
char *ptr;
sizeof(struct dig_server));
fatal("Memory "
"allocation "
"failure.");
ptr,
MXNAME - 1);
}
}
}
}
}
fatal("Memory allocation failure");
}
}
static void
setup_libs(void) {
isc_buffer_t b;
result = isc_app_start();
result = isc_net_probeipv4();
result = isc_net_probeipv6();
if (result == ISC_R_SUCCESS)
isc_buffer_add(&b, 1);
}
static void
{
}
void
isc_buffer_t *b = NULL;
isc_region_t r;
int len;
if (result != ISC_R_SUCCESS) {
#ifdef DEBUG
printf ("Firstname returned %s\n",
#endif
return;
}
#ifdef DEBUG
#endif
for (;;) {
&name);
while (loopresult == ISC_R_SUCCESS) {
BUFSIZE);
"isc_buffer_allocate");
NULL,
b);
"dns_rdata_totext");
isc_buffer_usedregion(b, &r);
/* Initialize lookup if we've not yet */
#ifdef DEBUG
(char *)r.base);
#endif
(mctx,
sizeof(struct
dig_lookup));
fatal ("Memory "
"allocation "
"failure.");
rttext, 32);
rctext, 32);
ISC_LIST_INIT(lookup->q);
sizeof(
struct
dig_server));
fatal("Memory allocation "
"failure.");
len);
isc_buffer_free (&b);
}
#ifdef DEBUG
"-> %ld, new@%ld "
#endif
link);
#ifdef DEBUG
"%ld, new = %ld, "
"new -> %ld\n",(long int)query->
#endif
}
}
if (result != ISC_R_SUCCESS)
break;
}
return; /* We didn't get a NS. Just give up. */
}
void
int len;
isc_buffer_t b;
#ifdef DEBUG
#endif
isc_buffer_add(&b, len);
if (result != ISC_R_SUCCESS) {
fatal("Aborting: %s is not a legal name syntax.",
}
if (recurse)
if (!lookup->ns_search_only) {
} else {
r.base="NS";
r.length=2;
}
if (rdtype == dns_rdatatype_axfr) {
/*
* Force TCP mode if we're doing an xfr.
*/
}
if (!lookup->ns_search_only) {
} else {
r.base="IN";
r.length=2;
}
DNS_SECTION_QUESTION, 0);
if (lookup->use_my_server_list)
else
sl = &server_list;
fatal("Memory allocation failure.");
}
}
static void
}
static void
#ifdef DEBUG
#endif
return;
}
}
}
/* connect_timeout is used for both UDP recieves and TCP connects. */
static void
dig_query_t *q=NULL;
isc_buffer_t *b=NULL;
isc_region_t r;
#ifdef DEBUG
#endif
for (q = ISC_LIST_HEAD(lookup->q);
q != NULL;
q = ISC_LIST_NEXT(q, link)) {
if (q->working) {
if (!free_now) {
isc_buffer_clear(b);
isc_buffer_usedregion(b, &r);
printf(";; Connection to server %.*s for %s "
"failed: Connection timed out.\n",
}
}
}
isc_buffer_free(&b);
}
static void
static void
isc_buffer_t *b=NULL;
isc_region_t r;
#ifdef DEBUG
#endif
return;
}
#ifdef DEBUG
#endif
isc_buffer_usedregion(b, &r);
isc_buffer_free(&b);
return;
}
length = isc_buffer_getuint16(b);
fatal ("Length was longer than I can handle!");
/* XXXMWS Fix the above. */
/*
* Even though the buffer was already init'ed, we need
* to redo it now, to force the length we want.
*/
#ifdef DEBUG
#endif
}
static void
#ifdef DEBUG
fputs("Ignoring launch_next_query because !pending.\n",
stderr);
#endif
return;
}
if (include_question)
link);
sendcount++;
#ifdef DEBUG
#endif
return;
}
static void
isc_buffer_t *b=NULL;
isc_region_t r;
#ifdef DEBUG
#endif
#ifdef DEBUG
#endif
isc_buffer_usedregion(b, &r);
printf(";; Connection to server %.*s for %s failed: %s.\n",
isc_buffer_free(&b);
return;
}
}
static isc_boolean_t
if (result == ISC_R_SUCCESS) {
#ifdef DEBUG
#endif
return (ISC_TRUE);
} else {
#ifdef DEBUG
#endif
return (ISC_FALSE);
}
}
static void
isc_buffer_t *b = NULL;
isc_region_t r;
sendcount--;
#ifdef DEBUG
#endif
#ifdef DEBUG
#endif
return;
}
&msg);
if (result != ISC_R_SUCCESS)
hex_dump(b);
else {
if (query->first_soa_rcvd &&
else
}
}
#ifdef DEBUG
#endif
if (!query->first_soa_rcvd) {
puts("; Transfer failed. "
"Didn't start with SOA answer.");
isc_event_free (&event);
return;
}
else {
}
}
else {
return;
}
else {
}
}
}
else {
}
isc_buffer_usedregion(&ab, &r);
if (!short_form)
printf("; Received %u bytes from %s\n",
}
return;
}
/* In truth, we should never get into the CANCELED routine, since
the cancel_lookup() routine clears the pending flag. */
return;
}
fatal("recv_done got result %s",
}
static void
else {
fatal("Couldn't look up your server host %s. errno=%d",
port);
}
}
void
#ifdef DEBUG
#endif
}
}
void
#ifdef DEBUG
if (tcp_mode)
#endif
sendcount++;
#ifdef DEBUG
#endif
}
}
static void
free_lists(void) {
void *ptr;
dig_lookup_t *l;
dig_query_t *q;
dig_server_t *s;
l = ISC_LIST_HEAD(lookup_list);
while (l != NULL) {
q = ISC_LIST_HEAD(l->q);
while (q != NULL) {
isc_socket_detach(&q->sock);
}
link);
link);
isc_buffer_invalidate(&q->recvbuf);
ptr = q;
q = ISC_LIST_NEXT(q, link);
}
if (l->use_my_server_list) {
s = ISC_LIST_HEAD(l->my_server_list);
while (s != NULL) {
ptr = s;
s = ISC_LIST_NEXT(s, link);
}
}
dns_message_destroy (&l->sendmsg);
isc_timer_detach (&l->timer);
ptr = l;
l = ISC_LIST_NEXT(l, link);
}
s = ISC_LIST_HEAD(server_list);
while (s != NULL) {
ptr = s;
s = ISC_LIST_NEXT(s, link);
}
}
int
setup_libs();
port = 53;
timeout = 10;
setup_system();
if (tcp_mode)
else
isc_app_run();
free_lists();
#ifdef MEMDEBUG
#endif
return (0);
}