nslookup.c revision e42c402595802edceafbd3e5338dda011fbbcdb6
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * Copyright (C) 2000 Internet Software Consortium.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * 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.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
15a44745412679c30a6d022733925af70a38b715David Lawrence * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15a44745412679c30a6d022733925af70a38b715David Lawrence * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15a44745412679c30a6d022733925af70a38b715David Lawrence * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer/* $Id: nslookup.c,v 1.45 2000/09/14 22:03:52 mws Exp $ */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern ISC_LIST(dig_searchlist_t) search_list;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerextern unsigned int timeout;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerisc_boolean_t short_form = ISC_TRUE, printcmd = ISC_TRUE,
6c6a62933dda281cb9193de1d54d4c9e74515f5aMichael Sawyer tcpmode = ISC_FALSE, deprecation_msg = ISC_TRUE;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer trace = ISC_FALSE, ns_search_only = ISC_FALSE,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer comments = ISC_TRUE, section_question = ISC_TRUE,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer section_answer = ISC_TRUE, section_authority = ISC_TRUE,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer section_additional = ISC_TRUE, recurse = ISC_TRUE,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerisc_boolean_t busy = ISC_FALSE, in_use = ISC_FALSE;
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyerstatic const char *rcodetext[] = {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED11",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED12",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED13",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED14",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED15",
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyerstatic const char *rtypetext[] = {
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonstatic void flush_lookup_list(void);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonstatic void getinput(isc_task_t *task, isc_event_t *event);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerreceived(int bytes, int frmsize, char *frm, dig_query_t *query) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyertrying(int frmsize, char *frm, dig_lookup_t *lookup) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerprintsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_message_firstname(msg, section);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = isc_buffer_allocate(mctx, &b, MXNAME);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dns_name_totext");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dns_rdata_totext");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dns_name_totext");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dns_rdata_totext");
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyer ((char *)isc_buffer_used(b))[0]=0;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dns_name_totext");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dns_rdata_totext");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerdetailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_message_firstname(msg, section);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = isc_buffer_allocate(mctx, &b, MXNAME);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer "dns_name_totext");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer "dns_rdata_totext");
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyer ((char *)isc_buffer_used(b))[0]=0;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer "dns_rdata_totext");
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer result = isc_buffer_allocate(mctx, &b, MXNAME);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer result = isc_sockaddr_totext(&query->sockaddr, b);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer printf("Address:\t%.*s\n", (int)isc_buffer_usedlength(b),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = isc_buffer_allocate(mctx, &b, MXNAME);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_name_totext(query->lookup->name, ISC_FALSE,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer /* detailheader(query, msg);*/
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer detailsection(query, msg, headers, DNS_SECTION_QUESTION);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer detailsection(query, msg, headers, DNS_SECTION_ANSWER);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer detailsection(query, msg, headers, DNS_SECTION_AUTHORITY);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer detailsection(query, msg, headers, DNS_SECTION_ADDITIONAL);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER]))
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer printsection(query, msg, headers, DNS_SECTION_ANSWER);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (((msg->flags & DNS_MESSAGEFLAG_AA) == 0) &&
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer (query->lookup->rdtype != dns_rdatatype_a)) {
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson puts("\nAuthorative answers can be found from:");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = isc_buffer_allocate(mctx, &b, MXNAME);
97beb7237b6383cf518d79cee08e23c8aa2bae3fMichael Sawyer get_address(srv->servername, 53, &sockaddr, ISC_FALSE);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("Default server: %s\nAddress: %.*s\n",
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer srv->servername, (int)isc_buffer_usedlength(b),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer tcpmode?"vc":"novc", short_form?"nodebug":"debug",
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("\t timeout = %d\t\tretry = %d\tport = %d\n",
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf("\t querytype = %-8s\tclass = %s\n",deftype, defclass);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_rdatatype_fromtext(&rdtype, &tr);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer printf("unknown query type: %s\n", typetext);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_rdataclass_fromtext(&rdclass, &tr);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer printf("unknown query class: %s\n", typetext);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "class=", 6) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "cl=", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "type=", 5) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "ty=", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "querytype=", 10) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "query=", 6) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "qu=", 3) == 0) {
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer /* XXXMWS domain= doesn't work now. */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "domain=", 7) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "do=", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "port=", 5) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "po=", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "timeout=", 8) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "retry=", 6) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "ret=", 4) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "def", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "nodef", 5) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "deb", 3) == 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (strncasecmp(opt, "nodeb", 5) == 0) {
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer } else if (strncasecmp(opt, "nod2", 4) == 0) {
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_rdatatype_fromtext(&rdtype, &tr);
bac3fc1a365bd48b1efe4044c7f3f587ed42b8a6Andreas Gustafsson printf("unknown query type: %s\n",deftype);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_rdataclass_fromtext(&rdclass, &tr);
bac3fc1a365bd48b1efe4044c7f3f587ed42b8a6Andreas Gustafsson printf("unknown query class: %s\n",defclass);
cd720113a2fc8a781d4e33350b8a2b62857b31d8David Lawrence lookup->trace = ISC_TF(trace || ns_search_only);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->section_authority = section_authority;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->section_additional = section_additional;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer while (s != NULL) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * This works on the global server list, instead of on a per-lookup
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * server list, since the change is persistent.
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer srv=isc_mem_allocate(mctx, sizeof(struct dig_server));
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington printf("The '%s' command is not yet implemented.\n", ptr);
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington } else if (strcasecmp(ptr, "finger") == 0 ||
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington printf("The '%s' command is not implemented.\n", ptr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer for (argc--, argv++; argc > 0; argc--, argv++) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer while (l != NULL) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer while (q != NULL) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_LIST_DEQUEUE(q->lengthlist, &q->lengthbuf,
e715e011788a529446b8013239c33599542ece32Michael Sawyer while (s != NULL) {
e715e011788a529446b8013239c33599542ece32Michael Sawyer ISC_LIST_DEQUEUE(l->my_server_list, sp, link);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtongetinput(isc_task_t *task, isc_event_t *event) {
6c6a62933dda281cb9193de1d54d4c9e74515f5aMichael Sawyer"Note: nslookup is deprecated and may be removed from future releases.\n"
ad7bb5bff3e796f5648835bf87a203d23d8319e4David Lawrence"Consider using the `dig' or `host' programs instead. Run nslookup with\n"
88301f84d1391e96ec87a9a308aa18f45553a56bAndreas Gustafsson"the `-sil[ent]' option to prevent this message from appearing.\n", stderr);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington result = isc_app_onrun(mctx, global_task, onrun_callback,
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington result = isc_app_onrun(mctx, global_task, getinput, NULL);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson debug("done, and starting to shut down");