代码如何理解···菜鸟初学···求高手帮忙
下列代码如何理解,是否可用类C进行编写。
[sigma]# dig @ 10.1.1.100 version.bind chaos txt
;<<>\>Dig 8.1 <<>\>@ 10.1.1.100 version.bind chaos txt
;{ 1 server found }
;;res options: init recurs defnam dnsrch
;;got answer:
;;->\>HEADER<<- opcode: QUERY, status: NOERROR, id: 10
;;flags: qr aa rd ra ; QUERY: 1, ANSWER: 1,AUTHORITY: 0,ADDITIONAL: 0
;;QUERY SECTION:
;;version.bind, type-txt, class-CHAOS
;;ANSWER SECTION:
VERSION BIND, OS CHAOS TXT “8.2.2”
[itchy]# nolookup
Defailt server:localhost.attackers.org
Address: 127.0.0.1
> server 10.1.1.100
Default server:dns.victim.net
Address: 10.1.1.100
> hash.attackers.org
Server:dns.victim.net
Address:10.1.1.100
[解决办法]
在贴一点 还是没贴完
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));}#ifdef DIG_SIGCHASE/* Just for compatibility : not use in host program */isc_result_tprintrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset, isc_buffer_t *target){ UNUSED(owner_name); UNUSED(rdataset); UNUSED(target); return(ISC_FALSE);}#endifstatic 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);}