⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nslookup.c

📁 bind-3.2.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2000-2003  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. *//* $Id: nslookup.c,v 1.90.2.5 2003/10/09 07:32:30 marka Exp $ */#include <config.h>#include <stdlib.h>#include <isc/app.h>#include <isc/buffer.h>#include <isc/commandline.h>#include <isc/event.h>#include <isc/string.h>#include <isc/timer.h>#include <isc/util.h>#include <isc/task.h>#include <isc/netaddr.h>#include <dns/message.h>#include <dns/name.h>#include <dns/fixedname.h>#include <dns/rdata.h>#include <dns/rdataclass.h>#include <dns/rdataset.h>#include <dns/rdatastruct.h>#include <dns/rdatatype.h>#include <dns/byaddr.h>#include <dig/dig.h>extern ISC_LIST(dig_lookup_t) lookup_list;extern ISC_LIST(dig_server_t) server_list;extern ISC_LIST(dig_searchlist_t) search_list;extern isc_boolean_t have_ipv6, usesearch, qr, debugging;extern in_port_t port;extern unsigned int timeout;extern isc_mem_t *mctx;extern dns_messageid_t id;extern int sendcount;extern int ndots;extern int tries;extern int lookup_counter;extern int exitcode;extern isc_taskmgr_t *taskmgr;extern isc_task_t *global_task;extern char *progname;static isc_boolean_t short_form = ISC_TRUE,	tcpmode = ISC_FALSE, deprecation_msg = ISC_TRUE,	identify = ISC_FALSE, stats = ISC_TRUE,	comments = ISC_TRUE, section_question = ISC_TRUE,	section_answer = ISC_TRUE, section_authority = ISC_TRUE,	section_additional = ISC_TRUE, recurse = ISC_TRUE,	aaonly = ISC_FALSE;static isc_boolean_t in_use = ISC_FALSE;static char defclass[MXRD] = "IN";static char deftype[MXRD] = "A";static isc_event_t *global_event = NULL;static char domainopt[DNS_NAME_MAXTEXT];static const char *rcodetext[] = {	"NOERROR",	"FORMERR",	"SERVFAIL",	"NXDOMAIN",	"NOTIMP",	"REFUSED",	"YXDOMAIN",	"YXRRSET",	"NXRRSET",	"NOTAUTH",	"NOTZONE",	"RESERVED11",	"RESERVED12",	"RESERVED13",	"RESERVED14",	"RESERVED15",	"BADVERS"};static const char *rtypetext[] = {	"rtype_0 = ",			/* 0 */	"internet address = ",		/* 1 */	"nameserver = ",		/* 2 */	"md = ",			/* 3 */	"mf = ",			/* 4 */	"canonical name = ",		/* 5 */	"soa = ",			/* 6 */	"mb = ",			/* 7 */	"mg = ",			/* 8 */	"mr = ",			/* 9 */	"rtype_10 = ",			/* 10 */	"protocol = ",			/* 11 */	"name = ",			/* 12 */	"hinfo = ",			/* 13 */	"minfo = ",			/* 14 */	"mail exchanger = ",		/* 15 */	"text = ",			/* 16 */	"rp = ",       			/* 17 */	"afsdb = ",			/* 18 */	"x25 address = ",		/* 19 */	"isdn address = ",		/* 20 */	"rt = ",			/* 21 */	"nsap = ",			/* 22 */	"nsap_ptr = ",			/* 23 */	"signature = ",			/* 24 */	"key = ",			/* 25 */	"px = ",			/* 26 */	"gpos = ",			/* 27 */	"has AAAA address ",		/* 28 */	"loc = ",			/* 29 */	"next = ",			/* 30 */	"rtype_31 = ",			/* 31 */	"rtype_32 = ",			/* 32 */	"service = ",			/* 33 */	"rtype_34 = ",			/* 34 */	"naptr = ",			/* 35 */	"kx = ",			/* 36 */	"cert = ",			/* 37 */	"v6 address = ",		/* 38 */	"dname = ",			/* 39 */	"rtype_40 = ",			/* 40 */	"optional = "};			/* 41 */#define N_KNOWN_RRTYPES (sizeof(rtypetext) / sizeof(rtypetext[0]))static void flush_lookup_list(void);static void getinput(isc_task_t *task, isc_event_t *event);voiddighost_shutdown(void) {	isc_event_t *event = global_event;	flush_lookup_list();	debug("dighost_shutdown()");	if (!in_use) {		isc_app_shutdown();		return;	}	isc_task_send(global_task, &event);}static voidprintsoa(dns_rdata_t *rdata) {	dns_rdata_soa_t soa;	isc_result_t result;	char namebuf[DNS_NAME_FORMATSIZE];	result = dns_rdata_tostruct(rdata, &soa, NULL);	check_result(result, "dns_rdata_tostruct");	dns_name_format(&soa.origin, namebuf, sizeof(namebuf));	printf("\torigin = %s\n", namebuf);	dns_name_format(&soa.contact, namebuf, sizeof(namebuf));	printf("\tmail addr = %s\n", namebuf);	printf("\tserial = %u\n", soa.serial);	printf("\trefresh = %u\n", soa.refresh);	printf("\tretry = %u\n", soa.retry);	printf("\texpire = %u\n", soa.expire);	printf("\tminimum = %u\n", soa.minimum);	dns_rdata_freestruct(&soa);}static voidprinta(dns_rdata_t *rdata) {	isc_result_t result;	char text[sizeof("255.255.255.255")];	isc_buffer_t b;	isc_buffer_init(&b, text, sizeof(text));	result = dns_rdata_totext(rdata, NULL, &b);	check_result(result, "dns_rdata_totext");	printf("Address: %.*s\n", (int)isc_buffer_usedlength(&b),	       (char *)isc_buffer_base(&b));}static voidprintrdata(dns_rdata_t *rdata) {	isc_result_t result;	isc_buffer_t *b = NULL;	unsigned int size = 1024;	isc_boolean_t done = ISC_FALSE;	if (rdata->type < N_KNOWN_RRTYPES)		printf("%s", rtypetext[rdata->type]);	else		printf("rdata_%d = ", rdata->type);	while (!done) {		result = isc_buffer_allocate(mctx, &b, size);		if (result != ISC_R_SUCCESS)			check_result(result, "isc_buffer_allocate");		result = dns_rdata_totext(rdata, NULL, b);		if (result == ISC_R_SUCCESS) {			printf("%.*s\n", (int)isc_buffer_usedlength(b),			       (char *)isc_buffer_base(b));			done = ISC_TRUE;		} else if (result != ISC_R_NOSPACE)			check_result(result, "dns_rdata_totext");		isc_buffer_free(&b);		size *= 2;	}}static isc_result_tprintsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,	     dns_section_t section) {	isc_result_t result, loopresult;	dns_name_t *name;	dns_rdataset_t *rdataset = NULL;	dns_rdata_t rdata = DNS_RDATA_INIT;	char namebuf[DNS_NAME_FORMATSIZE];	UNUSED(query);	UNUSED(headers);	debug("printsection()");	result = dns_message_firstname(msg, section);	if (result == ISC_R_NOMORE)		return (ISC_R_SUCCESS);	else if (result != ISC_R_SUCCESS)		return (result);	for (;;) {		name = NULL;		dns_message_currentname(msg, section,					&name);		for (rdataset = ISC_LIST_HEAD(name->list);		     rdataset != NULL;		     rdataset = ISC_LIST_NEXT(rdataset, link)) {			loopresult = dns_rdataset_first(rdataset);			while (loopresult == ISC_R_SUCCESS) {				dns_rdataset_current(rdataset, &rdata);				switch (rdata.type) {				case dns_rdatatype_a:					if (section != DNS_SECTION_ANSWER)						goto def_short_section;					dns_name_format(name, namebuf,							sizeof(namebuf));					printf("Name:\t%s\n", namebuf);					printa(&rdata);					break;				case dns_rdatatype_soa:					dns_name_format(name, namebuf,							sizeof(namebuf));					printf("%s\n", namebuf);					printsoa(&rdata);					break;				default:				def_short_section:					dns_name_format(name, namebuf,							sizeof(namebuf));					printf("%s\t", namebuf);					printrdata(&rdata);					break;				}				dns_rdata_reset(&rdata);				loopresult = dns_rdataset_next(rdataset);			}		}		result = dns_message_nextname(msg, section);		if (result == ISC_R_NOMORE)			break;		else if (result != ISC_R_SUCCESS) {			return (result);		}	}	return (ISC_R_SUCCESS);}static isc_result_tdetailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,	     dns_section_t section) {	isc_result_t result, loopresult;	dns_name_t *name;	dns_rdataset_t *rdataset = NULL;	dns_rdata_t rdata = DNS_RDATA_INIT;	char namebuf[DNS_NAME_FORMATSIZE];	UNUSED(query);	debug("detailsection()");	if (headers) {		switch (section) {		case DNS_SECTION_QUESTION:			puts("    QUESTIONS:");			break;		case DNS_SECTION_ANSWER:			puts("    ANSWERS:");			break;		case DNS_SECTION_AUTHORITY:			puts("    AUTHORITY RECORDS:");			break;		case DNS_SECTION_ADDITIONAL:			puts("    ADDITIONAL RECORDS:");			break;		}	}	result = dns_message_firstname(msg, section);	if (result == ISC_R_NOMORE)		return (ISC_R_SUCCESS);	else if (result != ISC_R_SUCCESS)		return (result);	for (;;) {		name = NULL;		dns_message_currentname(msg, section,					&name);		for (rdataset = ISC_LIST_HEAD(name->list);		     rdataset != NULL;		     rdataset = ISC_LIST_NEXT(rdataset, link)) {			if (section == DNS_SECTION_QUESTION) {				dns_name_format(name, namebuf,						sizeof(namebuf));				printf("\t%s, ", namebuf);				dns_rdatatype_format(rdataset->type,						     namebuf,						     sizeof(namebuf));				printf("type = %s, ", namebuf);				dns_rdataclass_format(rdataset->rdclass,						      namebuf,						      sizeof(namebuf));				printf("class = %s\n", namebuf);			}			loopresult = dns_rdataset_first(rdataset);			while (loopresult == ISC_R_SUCCESS) {				dns_rdataset_current(rdataset, &rdata);				dns_name_format(name, namebuf,						sizeof(namebuf));				printf("    ->  %s\n", namebuf);				switch (rdata.type) {				case dns_rdatatype_soa:					printsoa(&rdata);					break;				default:					printf("\t");					printrdata(&rdata);				}				dns_rdata_reset(&rdata);				loopresult = dns_rdataset_next(rdataset);			}		}		result = dns_message_nextname(msg, section);		if (result == ISC_R_NOMORE)			break;		else if (result != ISC_R_SUCCESS) {			return (result);		}	}	return (ISC_R_SUCCESS);}voidreceived(int bytes, isc_sockaddr_t *from, dig_query_t *query){	UNUSED(bytes);	UNUSED(from);	UNUSED(query);}voidtrying(char *frm, dig_lookup_t *lookup) {	UNUSED(frm);	UNUSED(lookup);}isc_result_tprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {	char servtext[ISC_SOCKADDR_FORMATSIZE];		debug("printmessage()");	isc_sockaddr_format(&query->sockaddr, servtext, sizeof(servtext));	printf("Server:\t\t%s\n", query->servname);	printf("Address:\t%s\n", servtext);		puts("");	if (!short_form) {		isc_boolean_t headers = ISC_TRUE;		puts("------------");		/*		detailheader(query, msg);*/		detailsection(query, msg, headers, DNS_SECTION_QUESTION);		detailsection(query, msg, headers, DNS_SECTION_ANSWER);		detailsection(query, msg, headers, DNS_SECTION_AUTHORITY);		detailsection(query, msg, headers, DNS_SECTION_ADDITIONAL);		puts("------------");	}	if (msg->rcode != 0) {		char nametext[DNS_NAME_FORMATSIZE];		dns_name_format(query->lookup->name,				nametext, sizeof(nametext));		printf("** server can't find %s: %s\n", nametext,		       rcodetext[msg->rcode]);		debug("returning with rcode == 0");		return (ISC_R_SUCCESS);	}	if ((msg->flags & DNS_MESSAGEFLAG_AA) == 0)		puts("Non-authoritative answer:");	if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER]))		printsection(query, msg, headers, DNS_SECTION_ANSWER);	else		printf("*** Can't find %s: No answer\n",		       query->lookup->textname);	if (((msg->flags & DNS_MESSAGEFLAG_AA) == 0) &&	    (query->lookup->rdtype != dns_rdatatype_a)) {		puts("\nAuthoritative answers can be found from:");		printsection(query, msg, headers,			     DNS_SECTION_AUTHORITY);		printsection(query, msg, headers,			     DNS_SECTION_ADDITIONAL);	}	return (ISC_R_SUCCESS);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -