📄 host.c
字号:
if (type == T_A) adrname = strcpy(adrnamebuf, rname); else if (type == T_NS) subname = strcpy(subnamebuf, rname); else if (type == T_SOA) soaname = strcpy(soanamebuf, rname); }/* * Print type specific data, if appropriate. */ switch (type) { case T_A: switch (class) { case C_IN: case C_HS: if (dlen == sizeof(ipaddr_t)) { bcopy((char *)cp, (char *)&inaddr, sizeof(inaddr)); address = inaddr.s_addr; doprintf("\t%s", inet_ntoa(inaddr)); cp += dlen; break; } else if (dlen == sizeof(ipaddr_t) + 3) { bcopy((char *)cp, (char *)&inaddr, sizeof(inaddr)); address = inaddr.s_addr; doprintf("\t%s", inet_ntoa(inaddr)); n = cp[4]; doprintf(", protocol = %s", itoa(n)); n = (cp[5] << 8) + cp[6]; doprintf(", port = %s", itoa(n)); cp += dlen; break; } address = 0; break; default: address = 0; cp += dlen; break; } break; case T_MX: if (check_size(rname, type, cp, msg, eor, sizeof(u_short)) < 0) break; n = _getshort(cp); if (verbose || ttlprint) doprintf("\t%s ", itoa(n)); else doprintf("\t"); cp += sizeof(u_short); n = expand_name(rname, type, cp, msg, eom, dname); if (n < 0) break; doprintf("%s", pr_name(dname)); cp += n; break; case T_NS: case T_PTR: case T_CNAME: n = expand_name(rname, type, cp, msg, eom, dname); if (n < 0) break; doprintf("\t%s", pr_name(dname)); cp += n; break; case T_SOA: n = expand_name(rname, type, cp, msg, eom, dname); if (n < 0) break; doprintf("\t%s", pr_name(dname)); cp += n; n = expand_name(rname, type, cp, msg, eom, dname); if (n < 0) break; doprintf(" %s", pr_name(dname)); cp += n; n = 5*sizeof(u_int); if (check_size(rname, type, cp, msg, eor, n) < 0) break; n = _getlong(cp); doprintf(" (\n\t\t\t%s\t;serial (version)", itoa(n)); cp += sizeof(u_int); n = _getlong(cp); doprintf("\n\t\t\t%s\t;refresh period", itoa(n)); cp += sizeof(u_int); n = _getlong(cp); doprintf("\n\t\t\t%s\t;retry refresh time", itoa(n)); cp += sizeof(u_int); n = _getlong(cp); doprintf("\n\t\t\t%s\t;expiration period", itoa(n)); cp += sizeof(u_int); n = _getlong(cp); doprintf("\n\t\t\t%s\t;default ttl\n\t\t\t)", itoa(n)); cp += sizeof(u_int); break; case T_WKS: if (check_size(rname, type, cp, msg, eor, sizeof(ipaddr_t)) < 0) break; bcopy((char *)cp, (char *)&inaddr, sizeof(inaddr)); doprintf("\t%s", inet_ntoa(inaddr)); cp += sizeof(ipaddr_t); if (check_size(rname, type, cp, msg, eor, 1) < 0) break; n = *cp++; protocol = getprotobynumber(n); if (protocol != NULL) doprintf(" %s", protocol->p_name); else doprintf(" %s", itoa(n)); doprintf(" ("); n = 0; while (cp < eor) { register int c; c = *cp++; do { if (c & 0200) { if (protocol != NULL) service = getservbyport(htons(n), protocol->p_name); else service = NULL; if (service != NULL) doprintf(" %s", service->s_name); else doprintf(" %s", itoa(n)); } c <<= 1; } while (++n & 07); } doprintf(" )"); break; case T_HINFO: if (check_size(rname, type, cp, msg, eor, 1) < 0) break; n = *cp++; doprintf("\t\"%s\"", stoa(cp, n)); cp += n; if (check_size(rname, type, cp, msg, eor, 1) < 0) break; n = *cp++; doprintf("\t\"%s\"", stoa(cp, n)); cp += n; break; case T_MINFO: n = expand_name(rname, type, cp, msg, eom, dname); if (n < 0) break; doprintf("\t%s", pr_name(dname)); cp += n; n = expand_name(rname, type, cp, msg, eom, dname); if (n < 0) break; doprintf(" %s", pr_name(dname)); cp += n; break; case T_MB: case T_MG: case T_MR: case T_MD: case T_MF: n = expand_name(rname, type, cp, msg, eom, dname); if (n < 0) break; doprintf("\t%s", pr_name(dname)); cp += n; break;#ifdef obsolete case T_TXT: if (dlen > 0) { doprintf("\t%s", stoa(cp, dlen)); cp += dlen; } break;#endif case T_TXT: if (check_size(rname, type, cp, msg, eor, 1) < 0) break; n = *cp++; doprintf("\t\"%s", stoa(cp, n)); cp += n; while (cp < eor) { if (check_size(rname, type, cp, msg, eor, 1) < 0) break; n = *cp++; doprintf("%s", stoa(cp, n)); cp += n; } doprintf("\""); break; case T_UINFO: doprintf("\t\"%s\"", stoa(cp, dlen)); cp += dlen; break; case T_UID: case T_GID: if (dlen == sizeof(int)) { n = _getlong(cp); doprintf("\t%s", itoa(n)); cp += dlen; } break; case T_UNSPEC: case T_NULL: cp += dlen; break; case T_RP: n = expand_name(rname, type, cp, msg, eom, dname); if (n < 0) break; doprintf("\t%s", pr_name(dname)); cp += n; n = expand_name(rname, type, cp, msg, eom, dname); if (n < 0) break; doprintf(" %s", pr_name(dname)); cp += n; break; case T_RT: case T_AFSDB: if (check_size(rname, type, cp, msg, eor, sizeof(u_short)) < 0) break; n = _getshort(cp); if (verbose || ttlprint) doprintf("\t%s ", itoa(n)); else doprintf("\t"); cp += sizeof(u_short); n = expand_name(rname, type, cp, msg, eom, dname); if (n < 0) break; doprintf("%s", pr_name(dname)); cp += n; break; case T_X25: if (check_size(rname, type, cp, msg, eor, 1) < 0) break; n = *cp++; if (n > 0) { doprintf("\t%s", stoa(cp, n)); cp += n; } break; case T_ISDN: if (check_size(rname, type, cp, msg, eor, 1) < 0) break; n = *cp++; if (n > 0) { doprintf("\t%s", stoa(cp, n)); cp += n; } if (cp < eor) { if (check_size(rname, type, cp, msg, eor, 1) < 0) break; n = *cp++; if (n > 0) { doprintf("\t%s", stoa(cp, n)); cp += n; } } break; case T_NSAP: case T_NSAPPTR: doprintf("\t(not yet implemented)"); cp += dlen; break; default: doprintf("\t???"); cp += dlen; break; } doprintf("\n");/* * Check validity of the name of this resource record. * Currently only during zone listing and if requested. */ if (listing && illegal && !valid_name(rname, TRUE)) { pr_warning("illegal %s record name %s", pr_type(type), rname); }/* * Save the CNAME alias for cname chain tracing. * Save the MR or MG alias for MB chain tracing. */ if (!listmode && classmatch) { if ((type == T_CNAME) && n > 0 && cp == eor) cname = strcpy(cnamebuf, dname); else if ((type == T_MR || type == T_MG) && n > 0 && cp == eor) mname = strcpy(mnamebuf, dname); }/* * Check if we have reached the exact end of this record. */ if (cp != eor) { pr_error("size error in %s record for %s, off by = %s", pr_type(type), rname, itoa(cp - eor)); /* we believe value of dlen; should perhaps return(NULL) */ cp = eor; } return(cp);}/*** SKIP_QREC -- Skip the query record in the nameserver answer buffer** ------------------------------------------------------------------**** Returns:** Pointer to position in answer buffer after current record.** NULL if there was a format error in the current record.*/u_char *skip_qrec(name, cp, msg, eom)input char *name; /* full name we are querying about */register u_char *cp; /* current position in answer buf */input u_char *msg, *eom; /* begin and end of answer buf */{ char rname[MAXDNAME+1]; /* record name in LHS */ int type, class; /* fixed values in query record */ register int n; n = expand_name(name, T_NONE, cp, msg, eom, rname); if (n < 0) return(NULL); cp += n; n = 2*sizeof(u_short); if (check_size(rname, T_NONE, cp, msg, eom, n) < 0) return(NULL); type = _getshort(cp); cp += sizeof(u_short); class = _getshort(cp); cp += sizeof(u_short);#ifdef lint if (verbose) printf("%-20s\t%s\t%s\n", rname, pr_class(class), pr_type(type));#endif return(cp);}/* * Nameserver information. * Stores names and addresses of all servers that are to be queried * for a zone transfer of the desired zone. Normally these are the * authoritative primary and/or secondary nameservers for the zone. */#define MAXNSNAME 16 /* maximum count of nameservers per zone */#define MAXIPADDR 10 /* maximum count of addresses per nameserver */char nsname[MAXNSNAME][MAXDNAME+1]; /* nameserver hostname */struct in_addr ipaddr[MAXNSNAME][MAXIPADDR]; /* nameserver addresses */int naddrs[MAXNSNAME]; /* count of addresses */int nservers = 0; /* count of nameservers */#ifdef notyettypedef struct ns_data { char nsname[MAXDNAME+1]; /* nameserver hostname */ struct in_addr ipaddr[MAXIPADDR]; /* nameserver addresses */ int naddrs; /* count of addresses */} ns_data_t;ns_data_t nsinfo[MAXNSNAME]; /* nameserver info */#endifbool authserver; /* server is supposed to be authoritative *//* * Host information. * Stores names and (single) addresses encountered during the zone listing * of all A records that belong to the zone. Non-authoritative glue records * that do not belong to the zone are not stored. Glue records that belong * to a delegated zone will be filtered out later during the host count scan. * The host names are allocated dynamically.#ifdef notyet * The host data should have been allocated dynamically to avoid static * limits, but this is less important since it is not saved across calls.#endif */#define MAXHOSTS 25000 /* maximum count of hostnames per zone */char *hostname[MAXHOSTS]; /* hostname of host in zone */ipaddr_t hostaddr[MAXHOSTS]; /* first host address */bool multaddr[MAXHOSTS]; /* set if this is a multiple address host */int hostcount = 0; /* count of hosts in zone */#ifdef notyettypedef struct host_data { char *hostname; /* hostname of host in zone */ ipaddr_t hostaddr; /* first host address */ bool multaddr; /* set if this is a multiple address host */} host_data_t;host_data_t hostlist[MAXHOSTS]; /* info on hosts in zone */#endif/* * Delegated zone information. * Stores the names of the delegated zones encountered during the zone * listing. The names and the list itself are allocated dynamically. */char **zonename = NULL; /* names of delegated zones within zone */int zonecount = 0; /* count of delegated zones within zone *//* * Address information. * Stores the (single) addresses of hosts found in all zones traversed. * Used to search for duplicate hosts (same address but different name). * The list of addresses is allocated dynamically, and remains allocated. * This has now been implemented as a hashed list, using the low-order * address bits as the hash key. */#ifdef obsoleteipaddr_t *addrlist = NULL; /* global list of addresses */int addrcount = 0; /* count of global addresses */#endiftypedef struct addr_data { ipaddr_t *addrlist; /* global list of addresses */ int addrcount; /* count of global addresses */} addr_data_t;#define AHASHSIZE 0x2000#define AHASHMASK 0x1fffaddr_data_t hlist[AHASHSIZE]; /* hash list of global addresses *//* * SOA record information. */typedef struct soa_data { char pname[MAXDNAME+1]; /* name of primary server */ char mname[MAXDNAME+1]; /* name of hostmaster mailbox */ int serial; /* serial (version) number */ int refresh; /* refresh time in seconds */ int retry; /* refresh retry time in seconds */ int expire; /* expiration time in seconds */ int defttl; /* default time_to_live */} soa_data_t;soa_data_t soa; /* buffer to store soa data *//*** LIST_ZONE -- Basic routine to do complete zone listing and checking** -------------------------------------------------------------------**** Returns:** TRUE if the requested info was processed successfully.** FALSE otherwise.*/int total_calls = 0; /* number of calls for zone processing */int total_check = 0; /* number of zones successfully processe
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -