X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/5c335855de2af3dd5432265eabeaf1c4dc9e524f..e66df58c88b4f953198826f444b7dbe1c8acdf6b:/print-domain.c diff --git a/print-domain.c b/print-domain.c index 2a21f2b8..4bf1a52d 100644 --- a/print-domain.c +++ b/print-domain.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.92 2006-04-07 08:58:29 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.98 2007-12-09 01:40:32 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -144,7 +144,7 @@ labellen(const u_char *cp) return(i); } -static const u_char * +const u_char * ns_nprint(register const u_char *cp, register const u_char *bp) { register u_int i, l; @@ -320,23 +320,32 @@ static const u_char * 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; + register u_int i, class; cp = ns_nskip(cp); if (cp == NULL || !TTEST2(*cp, 4)) return(NULL); - /* print the qtype and qclass (if it's not IN) */ + /* print the qtype */ i = EXTRACT_16BITS(cp); cp += 2; printf(" %s", tok2str(ns_type2str, "Type%d", i)); + /* print the qclass (if it's not 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)); + if (is_mdns) + class = (i & ~C_QU); + else + class = i; + if (class != C_IN) + printf(" %s", tok2str(ns_class2str, "(Class %d)", class)); + if (is_mdns) { + if (i & C_QU) + printf(" (QU)"); + else + printf(" (QM)"); + } fputs("? ", stdout); cp = ns_nprint(np, bp); @@ -347,7 +356,7 @@ ns_qprint(register const u_char *cp, register const u_char *bp, int is_mdns) static const u_char * ns_rprint(register const u_char *cp, register const u_char *bp, int is_mdns) { - register u_int class, opt_flags = 0; + register u_int i, class, opt_flags = 0; register u_short typ, len; register const u_char *rp; @@ -361,23 +370,39 @@ ns_rprint(register const u_char *cp, register const u_char *bp, int is_mdns) if (cp == NULL || !TTEST2(*cp, 10)) return (snapend); - /* print the type/qtype and class (if it's not IN) */ + /* print the type/qtype */ typ = EXTRACT_16BITS(cp); cp += 2; - class = EXTRACT_16BITS(cp); + /* print the class (if it's not IN and the type isn't OPT) */ + i = 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) + if (is_mdns) + class = (i & ~C_CACHE_FLUSH); + else + class = i; + if (class != C_IN && typ != T_OPT) printf(" %s", tok2str(ns_class2str, "(Class %d)", class)); + if (is_mdns) { + if (i & C_CACHE_FLUSH) + printf(" (Cache flush)"); + } - /* ignore ttl */ - cp += 2; - /* if T_OPT, save opt_flags */ - if (typ == T_OPT) + if (typ == T_OPT) { + /* get opt flags */ + cp += 2; opt_flags = EXTRACT_16BITS(cp); - /* ignore rest of ttl */ - cp += 2; + /* ignore rest of ttl field */ + cp += 2; + } else if (vflag > 2) { + /* print ttl */ + printf(" ["); + relts_print(EXTRACT_32BITS(cp)); + printf("]"); + cp += 4; + } else { + /* ignore ttl */ + cp += 4; + } len = EXTRACT_16BITS(cp); cp += 2; @@ -392,7 +417,7 @@ ns_rprint(register const u_char *cp, register const u_char *bp, int is_mdns) case T_A: if (!TTEST2(*cp, sizeof(struct in_addr))) return(NULL); - printf(" %s", ipaddr_string(cp)); + printf(" %s", intoa(htonl(EXTRACT_32BITS(cp)))); break; case T_NS: @@ -459,15 +484,24 @@ ns_rprint(register const u_char *cp, register const u_char *bp, int is_mdns) #ifdef INET6 case T_AAAA: + { + struct in6_addr addr; + char ntop_buf[INET6_ADDRSTRLEN]; + if (!TTEST2(*cp, sizeof(struct in6_addr))) return(NULL); - printf(" %s", ip6addr_string(cp)); + memcpy(&addr, cp, sizeof(struct in6_addr)); + printf(" %s", + inet_ntop(AF_INET6, &addr, ntop_buf, sizeof(ntop_buf))); + break; + } case T_A6: { struct in6_addr a; int pbit, pbyte; + char ntop_buf[INET6_ADDRSTRLEN]; if (!TTEST2(*cp, 1)) return(NULL); @@ -481,7 +515,8 @@ ns_rprint(register const u_char *cp, register const u_char *bp, int is_mdns) return(NULL); memset(&a, 0, sizeof(a)); memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte); - printf(" %u %s", pbit, ip6addr_string(&a)); + printf(" %u %s", pbit, + inet_ntop(AF_INET6, &a, ntop_buf, sizeof(ntop_buf))); } if (pbit > 0) { putchar(' '); @@ -558,7 +593,7 @@ ns_print(register const u_char *bp, u_int length, int is_mdns) if (DNS_QR(np)) { /* this is a response */ - printf(" %d%s%s%s%s%s%s", + printf("%d%s%s%s%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], ns_resp[DNS_RCODE(np)], @@ -626,7 +661,7 @@ ns_print(register const u_char *bp, u_int length, int is_mdns) } else { /* this is a request */ - printf(" %d%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], + printf("%d%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], DNS_RD(np) ? "+" : "", DNS_CD(np) ? "%" : "");