summaryrefslogtreecommitdiff
path: root/usr.sbin/tcpdump/print-domain.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/tcpdump/print-domain.c')
-rw-r--r--usr.sbin/tcpdump/print-domain.c255
1 files changed, 191 insertions, 64 deletions
diff --git a/usr.sbin/tcpdump/print-domain.c b/usr.sbin/tcpdump/print-domain.c
index 7360117cef6..c8ba519d90e 100644
--- a/usr.sbin/tcpdump/print-domain.c
+++ b/usr.sbin/tcpdump/print-domain.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: print-domain.c,v 1.3 1996/06/10 07:47:33 deraadt Exp $ */
+/* $OpenBSD: print-domain.c,v 1.4 1996/07/13 11:01:18 mickey Exp $ */
/*
- * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
+ * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -23,7 +23,7 @@
#ifndef lint
static char rcsid[] =
- "@(#) Header: print-domain.c,v 1.23 94/06/14 20:17:38 leres Exp (LBL)";
+ "@(#) Header: print-domain.c,v 1.29 96/06/19 00:49:25 leres Exp (LBL)";
#endif
#include <sys/param.h>
@@ -31,6 +31,10 @@ static char rcsid[] =
#include <sys/types.h>
#include <sys/socket.h>
+#if __STDC__
+struct mbuf;
+struct rtentry;
+#endif
#include <net/if.h>
#include <netinet/in.h>
@@ -50,9 +54,68 @@ static char rcsid[] =
#include "interface.h"
#include "addrtoname.h"
+#include "extract.h" /* must come after interface.h */
+
+/* Compatiblity */
+#ifndef T_TXT
+#define T_TXT 16 /* text strings */
+#endif
+#ifndef T_RP
+#define T_RP 17 /* responsible person */
+#endif
+#ifndef T_AFSDB
+#define T_AFSDB 18 /* AFS cell database */
+#endif
+#ifndef T_X25
+#define T_X25 19 /* X_25 calling address */
+#endif
+#ifndef T_ISDN
+#define T_ISDN 20 /* ISDN calling address */
+#endif
+#ifndef T_RT
+#define T_RT 21 /* router */
+#endif
+#ifndef T_NSAP
+#define T_NSAP 22 /* NSAP address */
+#endif
+#ifndef T_NSAP_PTR
+#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
+#endif
+#ifndef T_SIG
+#define T_SIG 24 /* security signature */
+#endif
+#ifndef T_KEY
+#define T_KEY 25 /* security key */
+#endif
+#ifndef T_PX
+#define T_PX 26 /* X.400 mail mapping */
+#endif
+#ifndef T_GPOS
+#define T_GPOS 27 /* geographical position (withdrawn) */
+#endif
+#ifndef T_AAAA
+#define T_AAAA 28 /* IP6 Address */
+#endif
+#ifndef T_LOC
+#define T_LOC 29 /* Location Information */
+#endif
+
+#ifndef T_UNSPEC
+#define T_UNSPEC 103 /* Unspecified format (binary data) */
+#endif
+#ifndef T_UNSPECA
+#define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */
+#endif
+
+#ifndef C_CHAOS
+#define C_CHAOS 3 /* for chaos net (MIT) */
+#endif
+#ifndef C_HS
+#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
+#endif
static char *ns_ops[] = {
- "", " inv_q", " stat", " op3", " op4", " op5", " op6", " op7",
+ "", " inv_q", " stat", " op3", " notify", " op5", " op6", " op7",
" op8", " updataA", " updateD", " updateDA",
" updateM", " updateMA", " zoneInit", " zoneRef",
};
@@ -66,30 +129,37 @@ static char *ns_resp[] = {
/* skip over a domain name */
static const u_char *
-ns_nskip(register const u_char *cp)
+ns_nskip(register const u_char *cp, register const u_char *bp)
{
register u_char i;
- if (((i = *cp++) & 0xc0) == 0xc0)
+ if (((i = *cp++) & INDIR_MASK) == INDIR_MASK)
return (cp + 1);
- while (i) {
+ while (i && cp < snapend) {
cp += i;
i = *cp++;
}
return (cp);
}
-/* print a domain name */
-static void
-ns_nprint(register const u_char *cp, register const u_char *bp,
- register const u_char *ep)
+/* print a <domain-name> */
+static const u_char *
+ns_nprint(register const u_char *cp, register const u_char *bp)
{
register u_int i;
-
- putchar(' ');
- if ((i = *cp++) != 0)
- while (i && cp < ep) {
- if ((i & 0xc0) == 0xc0) {
+ register const u_char *rp;
+ register int compress;
+
+ i = *cp++;
+ rp = cp + i;
+ if ((i & INDIR_MASK) == INDIR_MASK) {
+ rp = cp + 1;
+ compress = 1;
+ } else
+ compress = 0;
+ if (i != 0)
+ while (i && cp < snapend) {
+ if ((i & INDIR_MASK) == INDIR_MASK) {
cp = bp + (((i << 8) | *cp) & 0x3fff);
i = *cp++;
continue;
@@ -99,12 +169,29 @@ ns_nprint(register const u_char *cp, register const u_char *bp,
} while (--i);
putchar('.');
i = *cp++;
+ if (!compress)
+ rp += i + 1;
}
else
putchar('.');
+ return (rp);
}
-static struct token type2str[] = {
+/* print a <character-string> */
+static const u_char *
+ns_cprint(register const u_char *cp, register const u_char *bp)
+{
+ register u_int i;
+
+ i = *cp++;
+ if (cp + i < snapend)
+ do {
+ putchar(*cp++);
+ } while (--i);
+ return (cp);
+}
+
+static struct tok type2str[] = {
{ T_A, "A" },
{ T_NS, "NS" },
{ T_MD, "MD" },
@@ -120,12 +207,25 @@ static struct token type2str[] = {
{ 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_NSAP_PTR, "NSAP_PTR" },
+ { T_SIG, "SIG" },
+ { T_KEY, "KEY" },
+ { T_PX, "PX" },
+ { T_GPOS, "GPOS" },
+ { T_AAAA, "AAAA" },
+ { T_LOC , "LOC " },
{ T_UINFO, "UINFO" },
{ T_UID, "UID" },
{ T_GID, "GID" },
-#ifdef T_UNSPEC
{ T_UNSPEC, "UNSPEC" },
-#endif
+ { T_UNSPECA, "UNSPECA" },
{ T_AXFR, "AXFR" },
{ T_MAILB, "MAILB" },
{ T_MAILA, "MAILA" },
@@ -133,17 +233,24 @@ static struct token type2str[] = {
{ 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 void
-ns_qprint(register const u_char *cp, register const u_char *bp,
- register const u_char *ep)
+ns_qprint(register const u_char *cp, register const u_char *bp)
{
- const u_char *np = cp;
+ register const u_char *np = cp;
register u_int i;
- cp = ns_nskip(cp);
+ cp = ns_nskip(cp, bp);
- if (cp + 4 > ep)
+ if (cp + 4 > snapend)
return;
/* print the qtype and qclass (if it's not IN) */
@@ -151,42 +258,47 @@ ns_qprint(register const u_char *cp, register const u_char *bp,
i |= *cp++;
printf(" %s", tok2str(type2str, "Type%d", i));
i = *cp++ << 8;
- if ((i |= *cp++) != C_IN)
- if (i == C_ANY)
- printf("(c_any)");
- else
- printf("(Class %d)", i);
-
- putchar('?');
- ns_nprint(np, bp, ep);
-}
+ i |= *cp++;
+ if (i != C_IN)
+ printf(" %s", tok2str(class2str, "(Class %d)", i));
+ fputs("? ", stdout);
+ ns_nprint(np, bp);
+}
/* print a reply */
-static void
-ns_rprint(register const u_char *cp, register const u_char *bp,
- register const u_char *ep)
+static const u_char *
+ns_rprint(register const u_char *cp, register const u_char *bp)
{
register u_int i;
- u_short typ;
+ register u_short typ, len;
+ register const u_char *rp;
- cp = ns_nskip(cp);
+ if (vflag) {
+ putchar(' ');
+ cp = ns_nprint(cp, bp);
+ } else
+ cp = ns_nskip(cp, bp);
- if (cp + 10 > ep)
- return;
+ if (cp + 10 > snapend)
+ return (snapend);
/* print the type/qtype and class (if it's not IN) */
typ = *cp++ << 8;
typ |= *cp++;
i = *cp++ << 8;
- if ((i |= *cp++) != C_IN)
- if (i == C_ANY)
- printf("(c_any)");
- else
- printf("(Class %d)", i);
-
- /* ignore ttl & len */
- cp += 6;
+ i |= *cp++;
+ if (i != C_IN)
+ printf(" %s", tok2str(class2str, "(Class %d)", i));
+
+ /* ignore ttl */
+ cp += 4;
+
+ len = *cp++ << 8;
+ len |= *cp++;
+
+ rp = cp + len;
+
printf(" %s", tok2str(type2str, "Type%d", typ));
switch (typ) {
@@ -197,29 +309,34 @@ ns_rprint(register const u_char *cp, register const u_char *bp,
case T_NS:
case T_CNAME:
case T_PTR:
- ns_nprint(cp, bp, ep);
+ putchar(' ');
+ (void)ns_nprint(cp, bp);
break;
case T_MX:
- ns_nprint(cp+2, bp, ep);
-#ifndef TCPDUMP_ALIGN
- printf(" %d", *(short *)cp);
-#else
- {
- u_short x = *cp | cp[1] << 8;
- printf(" %d", ntohs(x));
- }
-#endif
+ putchar(' ');
+ (void)ns_nprint(cp + 2, bp);
+ printf(" %d", EXTRACT_SHORT(cp));
+ break;
+
+ case T_TXT:
+ putchar(' ');
+ (void)ns_cprint(cp, bp);
+ break;
+
+ case T_UNSPECA: /* One long string */
+ printf(" %.*s", len, cp);
break;
}
+ return (rp); /* XXX This isn't always right*/
}
void
ns_print(register const u_char *bp, int length)
{
register const HEADER *np;
- int qdcount, ancount, nscount, arcount;
- const u_char *ep = snapend;
+ register int qdcount, ancount, nscount, arcount;
+ register const u_char *cp;
np = (const HEADER *)bp;
/* get the byte-order right */
@@ -239,10 +356,20 @@ ns_print(register const u_char *bp, int length)
np->tc? "|" : "");
if (qdcount != 1)
printf(" [%dq]", qdcount);
+ /* Print QUESTION section on -vv */
+ if (vflag > 1) {
+ fputs(" q: ", stdout);
+ cp = ns_nprint((const u_char *)(np + 1), bp);
+ } else
+ cp = ns_nskip((const u_char *)(np + 1), bp);
printf(" %d/%d/%d", ancount, nscount, arcount);
- if (ancount)
- ns_rprint(ns_nskip((const u_char *)(np + 1)) + 4,
- (const u_char *)np, ep);
+ if (ancount--) {
+ cp = ns_rprint(cp + 4, bp);
+ while (ancount-- && cp < snapend) {
+ putchar(',');
+ cp = ns_rprint(cp, bp);
+ }
+ }
}
else {
/* this is a request */
@@ -272,7 +399,7 @@ ns_print(register const u_char *bp, int length)
if (arcount)
printf(" [%dau]", arcount);
- ns_qprint((const u_char *)(np + 1), (const u_char *)np, ep);
+ ns_qprint((const u_char *)(np + 1), (const u_char *)np);
}
printf(" (%d)", length);
}