dighost.c revision 77ae2d58c23aba222bf51379624b90bc27329587
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 2000 Internet Software Consortium.
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Permission to use, copy, modify, and distribute this software for any
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * purpose with or without fee is hereby granted, provided that the above
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
15a44745412679c30a6d022733925af70a38b715David Lawrence * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
15a44745412679c30a6d022733925af70a38b715David Lawrence * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15a44745412679c30a6d022733925af70a38b715David Lawrence * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
5eb91bd90e3ad3426e5e3213031556a737cf3809Mark Andrews/* $Id: dighost.c,v 1.52 2000/06/15 22:08:44 mws Exp $ */
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Notice to programmers: Do not use this code as an example of how to
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff * use the ISC library to perform DNS lookups. Dig and Host both operate
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence * on the request level, since they allow fine-tuning of output and are
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * intended as debugging tools. As a result, they perform many of the
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * functions which could be better handled using the dns_resolver
90c845947a6987a95d4facaed61406362fbb58dfBrian Wellington * functions in most applications.
363cb30a83e8e57bc8874e621910f0e23dd84909Mark Andrews#if defined(HAVE_ADDRINFO) && defined(HAVE_GETADDRINFO)
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrenceisc_boolean_t have_ipv6 = ISC_FALSE, specified_source = ISC_FALSE,
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrence free_now = ISC_FALSE, show_details = ISC_FALSE, usesearch=ISC_TRUE,
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff while (*s != 0) {
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff if (*s == '.')
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff unsigned int len;
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson printf("Printing a buffer with length %d\n", r.length);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffcheck_result(isc_result_t result, const char *msg) {
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff fatal("%s: %s", msg, isc_result_totext(result));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff /* Tests if a field is a class, without needing isc libs
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * initialized. This list will have to be manually kept in
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * sync with what the libs support.
01933e930208da3291de3722cb0d0787636b1e4fMichael Graff const char *classlist[] = {"in", "hs", "chaos"};
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington for (i = 0; i < numclasses; i++)
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington /* Tests if a field is a type, without needing isc libs
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington * initialized. This list will have to be manually kept in
5b34d8267e8228b4615b9eae4e32d9ad1f308179Andreas Gustafsson * sync with what the libs support.
5b34d8267e8228b4615b9eae4e32d9ad1f308179Andreas Gustafsson const char *typelist[] = {"a", "ns", "md", "mf", "cname",
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington for (i = 0; i < numtypes; i++) {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff unsigned char bitfield;
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff for (i=0;i<tw;i++) {
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson*requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson fatal ("Memory allocation failure in %s:%d",
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson strncpy (looknew->textname, lookold-> textname, MXNAME);
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson strncpy (looknew->rttext, lookold-> rttext, 32);
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson strncpy (looknew->rctext, lookold-> rctext, 32);
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson looknew->ixfr_serial = lookold->ixfr_serial;
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington looknew->ns_search_only = lookold->ns_search_only;
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson looknew->section_question = lookold->section_question;
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson looknew->section_answer = lookold->section_answer;
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson looknew->section_authority = lookold->section_authority;
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson looknew->section_additional = lookold->section_additional;
5733d25b06b46067b3751d10436d82aef09cd705Brian Wellington looknew->use_my_server_list = lookold->use_my_server_list;
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson s = ISC_LIST_HEAD(lookold->my_server_list);
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson while (s != NULL) {
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson srv = isc_mem_allocate (mctx, sizeof(struct
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington ISC_LIST_ENQUEUE(looknew->my_server_list, srv,
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington "-> %lx, new@%lx "
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson ISC_LIST_INSERTAFTER(lookup_list, lookold, looknew, link);
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson "%lx, new = %lx, "
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence unsigned char *secretstore;
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson search = isc_mem_allocate( mctx, sizeof(struct dig_server));
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff strncpy(search->origin, fixeddomain, MXNAME - 1);
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff get_servers = ISC_TF(server_list.head == NULL);
sizeof(struct dig_server));
__LINE__);
ptr,
ndots);
&& usesearch){
!= NULL) {
mctx, sizeof(struct
dig_server));
__LINE__);
ptr,
link);
(fixeddomain[0] == 0 )){
!= NULL) {
mctx, sizeof(struct
dig_server));
__LINE__);
ptr,
link);
l != NULL;
if (keysecret[0] != 0) {
goto SYSSETUP_FAIL;
namebuf);
goto SYSSETUP_FAIL;
setup_libs(void) {
if (free_now)
if (still_working)
isc_region_t r;
int len;
if (free_now)
BUFSIZE);
NULL,
isc_buffer_usedregion(b, &r);
(char *)r.base);
if (!success) {
if (section ==
query->
dig_server));
isc_buffer_free (&b);
if (free_now)
MXNAME);
int len;
isc_region_t r;
isc_buffer_t b;
if (free_now)
lookup_counter = 0;
isc_buffer_usedregion (&b, &r);
isc_buffer_usedregion (&b, &r);
DNS_SECTION_QUESTION, 0);
ISC_TRUE);
sockcount--;
sendcount++;
#ifdef TWIDDLE
if (twiddle) {
isc_region_t r;
q != NULL;
if (q->working) {
if (!free_now) {
isc_buffer_clear(b);
isc_buffer_usedregion(b, &r);
isc_buffer_free(&b);
isc_region_t r;
if (free_now) {
isc_buffer_usedregion(b, &r);
isc_buffer_free(&b);
sockcount--;
length);
if (free_now)
sockcount--;
if (include_question) {
#ifdef TWIDDLE
if (twiddle) {
link);
sendcount++;
isc_region_t r;
if (free_now) {
isc_buffer_usedregion(b, &r);
isc_buffer_free(&b);
static isc_boolean_t
return (ISC_TRUE);
return (ISC_FALSE);
isc_buffer_t b;
isc_region_t r;
#ifdef NEVER
&name);
goto NEXT_RDATA;
&soa,
mctx);
goto XFR_DONE;
goto NEXT_RDATA;
goto NEXT_RDATA;
isc_buffer_usedregion(&b, &r);
goto NEXT_RDATA;
goto XFR_DONE;
isc_region_t r;
dig_lookup_t *n;
if (free_now) {
if (free_now) {
sendcount--;
&msg);
hex_dump(b);
if (show_details ||
== ISC_R_SUCCESS) &&
if (show_details) {
== ISC_R_SUCCESS) &&
&ab);
query);
int result;
if (result != 0) {
port);
sockcount++;
if (specified_source)
sockcount++;
if (specified_source)
start_lookup(void) {
if (free_now)
void *ptr;
dig_lookup_t *l;
dig_query_t *q;
dig_server_t *s;
dig_searchlist_t *o;
if (free_now)
while (l != NULL) {
q = ISC_LIST_HEAD(l->q);
while (q != NULL) {
sockcount--;
link);
link);
ptr = q;
if (l->use_my_server_list) {
while (s != NULL) {
ptr = s;
ptr = l;
while (s != NULL) {
ptr = s;
while (o != NULL) {
ptr = o;
if (is_dst_up) {
if (isc_mem_debugging)
if (_exitcode != 0)