X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/b09ea5197b84075954abd9ba9ff7e10f018c242f..5c77a341d4e766eef8beebaecd9e69bd2cc7b59b:/print-domain.c diff --git a/print-domain.c b/print-domain.c index b55d362d..5a67d214 100644 --- a/print-domain.c +++ b/print-domain.c @@ -20,8 +20,8 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.83 2003-04-04 00:18:54 fenner Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.88 2003-11-16 09:36:18 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -240,56 +240,57 @@ ns_cprint(register const u_char *cp) return (cp + i); } +/* http://www.iana.org/assignments/dns-parameters */ struct tok ns_type2str[] = { - { T_A, "A" }, - { T_NS, "NS" }, - { T_MD, "MD" }, - { T_MF, "MF" }, - { T_CNAME, "CNAME" }, - { T_SOA, "SOA" }, - { T_MB, "MB" }, - { T_MG, "MG" }, - { T_MR, "MR" }, - { T_NULL, "NULL" }, - { T_WKS, "WKS" }, - { T_PTR, "PTR" }, - { T_HINFO, "HINFO" }, - { T_MINFO, "MINFO" }, - { T_MX, "MX" }, - { T_TXT, "TXT" }, - { T_RP, "RP" }, - { T_AFSDB, "AFSDB" }, - { T_X25, "X25" }, - { T_ISDN, "ISDN" }, - { T_RT, "RT" }, - { T_NSAP, "NSAP" }, + { T_A, "A" }, /* RFC 1035 */ + { T_NS, "NS" }, /* RFC 1035 */ + { T_MD, "MD" }, /* RFC 1035 */ + { T_MF, "MF" }, /* RFC 1035 */ + { T_CNAME, "CNAME" }, /* RFC 1035 */ + { T_SOA, "SOA" }, /* RFC 1035 */ + { T_MB, "MB" }, /* RFC 1035 */ + { T_MG, "MG" }, /* RFC 1035 */ + { T_MR, "MR" }, /* RFC 1035 */ + { T_NULL, "NULL" }, /* RFC 1035 */ + { T_WKS, "WKS" }, /* RFC 1035 */ + { T_PTR, "PTR" }, /* RFC 1035 */ + { T_HINFO, "HINFO" }, /* RFC 1035 */ + { T_MINFO, "MINFO" }, /* RFC 1035 */ + { T_MX, "MX" }, /* RFC 1035 */ + { T_TXT, "TXT" }, /* RFC 1035 */ + { T_RP, "RP" }, /* RFC 1183 */ + { T_AFSDB, "AFSDB" }, /* RFC 1183 */ + { T_X25, "X25" }, /* RFC 1183 */ + { T_ISDN, "ISDN" }, /* RFC 1183 */ + { T_RT, "RT" }, /* RFC 1183 */ + { T_NSAP, "NSAP" }, /* RFC 1706 */ { 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_SIG, "SIG" }, /* RFC 2535 */ + { T_KEY, "KEY" }, /* RFC 2535 */ + { T_PX, "PX" }, /* RFC 2163 */ + { T_GPOS, "GPOS" }, /* RFC 1712 */ + { T_AAAA, "AAAA" }, /* RFC 1886 */ + { T_LOC, "LOC" }, /* RFC 1876 */ + { T_NXT, "NXT" }, /* RFC 2535 */ + { T_EID, "EID" }, /* Nimrod */ + { T_NIMLOC, "NIMLOC" }, /* Nimrod */ + { T_SRV, "SRV" }, /* RFC 2782 */ + { T_ATMA, "ATMA" }, /* ATM Forum */ + { T_NAPTR, "NAPTR" }, /* RFC 2168, RFC 2915 */ + { T_A6, "A6" }, /* RFC 2874 */ + { T_DNAME, "DNAME" }, /* RFC 2672 */ + { T_OPT, "OPT" }, /* RFC 2671 */ { T_UINFO, "UINFO" }, { T_UID, "UID" }, { T_GID, "GID" }, { T_UNSPEC, "UNSPEC" }, { T_UNSPECA, "UNSPECA" }, - { T_TKEY, "TKEY" }, - { T_TSIG, "TSIG" }, - { T_IXFR, "IXFR" }, - { T_AXFR, "AXFR" }, - { T_MAILB, "MAILB" }, - { T_MAILA, "MAILA" }, + { T_TKEY, "TKEY" }, /* RFC 2930 */ + { T_TSIG, "TSIG" }, /* RFC 2845 */ + { T_IXFR, "IXFR" }, /* RFC 1995 */ + { T_AXFR, "AXFR" }, /* RFC 1035 */ + { T_MAILB, "MAILB" }, /* RFC 1035 */ + { T_MAILA, "MAILA" }, /* RFC 1035 */ { T_ANY, "ANY" }, { 0, NULL } }; @@ -304,7 +305,7 @@ struct tok ns_class2str[] = { /* print a query */ static const u_char * -ns_qprint(register const u_char *cp, register const u_char *bp) +ns_qprint(register const u_char *cp, register const u_char *bp, int is_mdns) { register const u_char *np = cp; register u_int i; @@ -315,12 +316,14 @@ ns_qprint(register const u_char *cp, register const u_char *bp) return(NULL); /* print the qtype and qclass (if it's not IN) */ - i = *cp++ << 8; - i |= *cp++; + i = EXTRACT_16BITS(cp); + cp += 2; printf(" %s", tok2str(ns_type2str, "Type%d", i)); - i = *cp++ << 8; - i |= *cp++; - if (i != C_IN) + i = EXTRACT_16BITS(cp); + cp += 2; + if (is_mdns && i == (C_IN|C_CACHE_FLUSH)) + printf(" (Cache flush)"); + else if (i != C_IN) printf(" %s", tok2str(ns_class2str, "(Class %d)", i)); fputs("? ", stdout); @@ -330,7 +333,7 @@ ns_qprint(register const u_char *cp, register const u_char *bp) /* print a reply */ static const u_char * -ns_rprint(register const u_char *cp, register const u_char *bp) +ns_rprint(register const u_char *cp, register const u_char *bp, int is_mdns) { register u_int class; register u_short typ, len; @@ -347,18 +350,20 @@ ns_rprint(register const u_char *cp, register const u_char *bp) 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) + typ = EXTRACT_16BITS(cp); + cp += 2; + class = EXTRACT_16BITS(cp); + cp += 2; + if (is_mdns && class == (C_IN|C_CACHE_FLUSH)) + printf(" (Cache flush)"); + else if (class != C_IN && typ != T_OPT) printf(" %s", tok2str(ns_class2str, "(Class %d)", class)); /* ignore ttl */ cp += 4; - len = *cp++ << 8; - len |= *cp++; + len = EXTRACT_16BITS(cp); + cp += 2; rp = cp + len; @@ -416,8 +421,13 @@ ns_rprint(register const u_char *cp, register const u_char *bp) break; case T_TXT: - putchar(' '); - (void)ns_cprint(cp); + while (cp < rp) { + printf(" \""); + cp = ns_cprint(cp); + if (cp == NULL) + return(NULL); + putchar('"'); + } break; case T_SRV: @@ -512,7 +522,7 @@ ns_rprint(register const u_char *cp, register const u_char *bp) } void -ns_print(register const u_char *bp, u_int length) +ns_print(register const u_char *bp, u_int length, int is_mdns) { register const HEADER *np; register int qdcount, ancount, nscount, arcount; @@ -536,7 +546,7 @@ ns_print(register const u_char *bp, u_int length) DNS_AA(np)? "*" : "", DNS_RA(np)? "" : "-", DNS_TC(np)? "|" : "", - DNS_CD(np)? "%" : ""); + DNS_AD(np)? "$" : ""); if (qdcount != 1) printf(" [%dq]", qdcount); @@ -547,7 +557,7 @@ ns_print(register const u_char *bp, u_int length) putchar(','); if (vflag > 1) { fputs(" q:", stdout); - if ((cp = ns_qprint(cp, bp)) == NULL) + if ((cp = ns_qprint(cp, bp, is_mdns)) == NULL) goto trunc; } else { if ((cp = ns_nskip(cp)) == NULL) @@ -557,11 +567,11 @@ ns_print(register const u_char *bp, u_int length) } printf(" %d/%d/%d", ancount, nscount, arcount); if (ancount--) { - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; while (cp < snapend && ancount--) { putchar(','); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; } } @@ -571,11 +581,11 @@ ns_print(register const u_char *bp, u_int length) if (vflag > 1) { if (cp < snapend && nscount--) { fputs(" ns:", stdout); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; while (cp < snapend && nscount--) { putchar(','); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; } } @@ -583,11 +593,11 @@ ns_print(register const u_char *bp, u_int length) goto trunc; if (cp < snapend && arcount--) { fputs(" ar:", stdout); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; while (cp < snapend && arcount--) { putchar(','); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; } } @@ -599,7 +609,7 @@ ns_print(register const u_char *bp, u_int length) /* this is a request */ printf(" %d%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], DNS_RD(np) ? "+" : "", - DNS_AD(np) ? "$" : ""); + DNS_CD(np) ? "%" : ""); /* any weirdness? */ b2 = EXTRACT_16BITS(((u_short *)np)+1); @@ -625,12 +635,13 @@ ns_print(register const u_char *bp, u_int length) cp = (const u_char *)(np + 1); if (qdcount--) { - cp = ns_qprint(cp, (const u_char *)np); + cp = ns_qprint(cp, (const u_char *)np, is_mdns); if (!cp) goto trunc; while (cp < snapend && qdcount--) { cp = ns_qprint((const u_char *)cp, - (const u_char *)np); + (const u_char *)np, + is_mdns); if (!cp) goto trunc; } @@ -641,11 +652,11 @@ ns_print(register const u_char *bp, u_int length) /* Print remaining sections on -vv */ if (vflag > 1) { if (ancount--) { - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; while (cp < snapend && ancount--) { putchar(','); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; } } @@ -653,11 +664,11 @@ ns_print(register const u_char *bp, u_int length) goto trunc; if (cp < snapend && nscount--) { fputs(" ns:", stdout); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; while (nscount-- && cp < snapend) { putchar(','); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; } } @@ -665,11 +676,11 @@ ns_print(register const u_char *bp, u_int length) goto trunc; if (cp < snapend && arcount--) { fputs(" ar:", stdout); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; while (cp < snapend && arcount--) { putchar(','); - if ((cp = ns_rprint(cp, bp)) == NULL) + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) goto trunc; } }