📄 print-domain.c
字号:
{ T_NSAP_PTR, "NSAP_PTR" }, { T_SIG, "SIG" }, { T_KEY, "KEY" }, { T_PX, "PX" }, { T_GPOS, "GPOS" }, { T_AAAA, "AAAA" }, { T_LOC, "LOC " }, { T_NXT, "NXT " }, { T_EID, "EID " }, { T_NIMLOC, "NIMLOC " }, { T_SRV, "SRV " }, { T_ATMA, "ATMA " }, { T_NAPTR, "NAPTR " }, { T_A6, "A6 " }, { T_DNAME, "DNAME " }, { T_OPT, "OPT " }, { T_UINFO, "UINFO" }, { T_UID, "UID" }, { T_GID, "GID" }, { T_UNSPEC, "UNSPEC" }, { T_UNSPECA, "UNSPECA" }, { T_AXFR, "AXFR" }, { T_MAILB, "MAILB" }, { T_MAILA, "MAILA" }, { T_ANY, "ANY" }, { 0, NULL }};static struct tok class2str[] = { { C_IN, "IN" }, /* Not used */ { C_CHAOS, "CHAOS)" }, { C_HS, "HS" }, { C_ANY, "ANY" }, { 0, NULL }};/* print a query */static const u_char *ns_qprint(register const u_char *cp, register const u_char *bp){ register const u_char *np = cp; register u_int i; cp = ns_nskip(cp, bp); if (cp + 4 > snapend || cp == NULL) return(NULL); /* print the qtype and qclass (if it's not IN) */ i = *cp++ << 8; i |= *cp++; printf(" %s", tok2str(type2str, "Type%d", i)); i = *cp++ << 8; i |= *cp++; if (i != C_IN) printf(" %s", tok2str(class2str, "(Class %d)", i)); fputs("? ", stdout); cp = ns_nprint(np, bp); return(cp ? cp + 4 : NULL);}/* print a reply */static const u_char *ns_rprint(register const u_char *cp, register const u_char *bp){ register u_int class; register u_short typ, len; register const u_char *rp; if (vflag) { putchar(' '); if ((cp = ns_nprint(cp, bp)) == NULL) return NULL; } else cp = ns_nskip(cp, bp); if (cp + 10 > snapend || cp == NULL) return (snapend); /* print the type/qtype and class (if it's not IN) */ typ = *cp++ << 8; typ |= *cp++; class = *cp++ << 8; class |= *cp++; if (class != C_IN && typ != T_OPT) printf(" %s", tok2str(class2str, "(Class %d)", class)); /* ignore ttl */ cp += 4; len = *cp++ << 8; len |= *cp++; rp = cp + len; printf(" %s", tok2str(type2str, "Type%d", typ)); if (rp > snapend) return(NULL); switch (typ) { case T_A: if (cp + sizeof(struct in_addr) > snapend) return(NULL); printf(" %s", ipaddr_string(cp)); break; case T_NS: case T_CNAME: case T_PTR:#ifdef T_DNAME case T_DNAME:#endif putchar(' '); if (ns_nprint(cp, bp) == NULL) return(NULL); break; case T_SOA: if (!vflag) break; putchar(' '); if ((cp = ns_nprint(cp, bp)) == NULL) return(NULL); putchar(' '); if ((cp = ns_nprint(cp, bp)) == NULL) return(NULL); if (cp + 5 * 4 > snapend) return(NULL); printf(" %u", EXTRACT_32BITS(cp)); cp += 4; printf(" %u", EXTRACT_32BITS(cp)); cp += 4; printf(" %u", EXTRACT_32BITS(cp)); cp += 4; printf(" %u", EXTRACT_32BITS(cp)); cp += 4; printf(" %u", EXTRACT_32BITS(cp)); cp += 4; break; case T_MX: putchar(' '); if (cp + 2 > snapend) return(NULL); if (ns_nprint(cp + 2, bp) == NULL) return(NULL); printf(" %d", EXTRACT_16BITS(cp)); break; case T_TXT: putchar(' '); (void)ns_cprint(cp, bp); break;#ifdef INET6 case T_AAAA: if (cp + sizeof(struct in6_addr) > snapend) return(NULL); printf(" %s", ip6addr_string(cp)); break; case T_A6: { struct in6_addr a; int pbit, pbyte; pbit = *cp; pbyte = (pbit & ~7) / 8; if (pbit > 128) { printf(" %u(bad plen)", pbit); break; } else if (pbit < 128) { memset(&a, 0, sizeof(a)); memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte); printf(" %u %s", pbit, ip6addr_string(&a)); } if (pbit > 0) { putchar(' '); if (ns_nprint(cp + 1 + sizeof(a) - pbyte, bp) == NULL) return(NULL); } break; }#endif /*INET6*/ case T_OPT: printf(" UDPsize=%u", class); break; case T_UNSPECA: /* One long string */ if (cp + len > snapend) return(NULL); fn_printn(cp, len, snapend); break; } return (rp); /* XXX This isn't always right */}voidns_print(register const u_char *bp, u_int length){ register const HEADER *np; register int qdcount, ancount, nscount, arcount; register const u_char *cp = NULL; np = (const HEADER *)bp; /* get the byte-order right */ qdcount = ntohs(np->qdcount); ancount = ntohs(np->ancount); nscount = ntohs(np->nscount); arcount = ntohs(np->arcount); if (DNS_QR(np)) { /* this is a response */ printf(" %d%s%s%s%s%s%s", ntohs(np->id), ns_ops[DNS_OPCODE(np)], ns_resp[DNS_RCODE(np)], DNS_AA(np)? "*" : "", DNS_RA(np)? "" : "-", DNS_TC(np)? "|" : "", DNS_CD(np)? "%" : ""); if (qdcount != 1) printf(" [%dq]", qdcount); /* Print QUESTION section on -vv */ if (vflag > 1) { fputs(" q:", stdout); if ((cp = ns_qprint((const u_char *)(np + 1), bp)) == NULL) goto trunc; } else { if ((cp = ns_nskip((const u_char *)(np + 1), bp)) == NULL) goto trunc; cp += 4; } printf(" %d/%d/%d", ancount, nscount, arcount); if (ancount--) { if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; while (ancount-- && cp < snapend) { putchar(','); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; } } /* Print NS and AR sections on -vv */ if (vflag > 1) { if (nscount-- && cp < snapend) { fputs(" ns:", stdout); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; while (nscount-- && cp < snapend) { putchar(','); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; } } if (arcount-- && cp < snapend) { fputs(" ar:", stdout); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; while (arcount-- && cp < snapend) { putchar(','); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; } } } } else { /* this is a request */ printf(" %d%s%s%s", ntohs(np->id), ns_ops[DNS_OPCODE(np)], DNS_RD(np) ? "+" : "", DNS_AD(np) ? "$" : ""); /* any weirdness? */ if (*(((u_short *)np)+1) & htons(0x6cf)) printf(" [b2&3=0x%x]", ntohs(*(((u_short *)np)+1))); if (DNS_OPCODE(np) == IQUERY) { if (qdcount) printf(" [%dq]", qdcount); if (ancount != 1) printf(" [%da]", ancount); } else { if (ancount) printf(" [%da]", ancount); if (qdcount != 1) printf(" [%dq]", qdcount); } if (nscount) printf(" [%dn]", nscount); if (arcount) printf(" [%dau]", arcount); if (qdcount--) { cp = ns_qprint((const u_char *)(np + 1), (const u_char *)np); if (!cp) goto trunc; if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; while (qdcount-- && cp < snapend) { cp = ns_qprint((const u_char *)cp, (const u_char *)np); if (!cp) goto trunc; if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; } } /* Print remaining sections on -vv */ if (vflag > 1) { if (ancount--) { if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; while (ancount-- && cp < snapend) { putchar(','); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; } } if (nscount-- && cp < snapend) { fputs(" ns:", stdout); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; while (nscount-- && cp < snapend) { putchar(','); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; } } if (arcount-- && cp < snapend) { fputs(" ar:", stdout); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; while (arcount-- && cp < snapend) { putchar(','); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; } } } } printf(" (%d)", length); return; trunc: printf("[|domain]"); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -