#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.41 1999-10-30 05:11:12 itojun Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.55 2000-10-10 05:05:07 guy Exp $ (LBL)";
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
#endif
#include <sys/param.h>
#include <sys/time.h>
-#include <sys/socket.h>
-
-#if __STDC__
-struct mbuf;
-struct rtentry;
-#endif
-#include <net/if.h>
#include <netinet/in.h>
-#include <netinet/if_ether.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip_var.h>
-#include <netinet/udp.h>
-#include <netinet/udp_var.h>
-#include <netinet/tcp.h>
#ifdef NOERROR
#undef NOERROR /* Solaris sucks */
#ifdef NOERROR
#undef T_UNSPEC /* SINIX does too */
#endif
-#include <arpa/nameser.h>
+#include "nameser.h"
#include <stdio.h>
#include <string.h>
register u_int i;
register const u_char *rp;
register int compress;
+ int chars_processed;
+ int data_size = snapend - bp;
i = *cp++;
+ chars_processed = 1;
rp = cp + i;
if ((i & INDIR_MASK) == INDIR_MASK) {
rp = cp + 1;
if ((i & INDIR_MASK) == INDIR_MASK) {
cp = bp + (((i << 8) | *cp) & 0x3fff);
i = *cp++;
+ chars_processed++;
+
+ /*
+ * If we've looked at every character in
+ * the message, this pointer will make
+ * us look at some character again,
+ * which means we're looping.
+ */
+ if (chars_processed >= data_size) {
+ fn_printn(cp, 6, (u_char *)"<LOOP>");
+ if (!compress)
+ rp += i + 1;
+ return (rp);
+ }
continue;
}
if (fn_printn(cp, i, snapend))
break;
cp += i;
+ chars_processed += i;
putchar('.');
i = *cp++;
+ chars_processed++;
if (!compress)
rp += i + 1;
}
nscount = ntohs(np->nscount);
arcount = ntohs(np->arcount);
- if (np->qr) {
+ if (DNS_QR(np)) {
/* this is a response */
- printf(" %d%s%s%s%s%s",
+ printf(" %d%s%s%s%s%s%s",
ntohs(np->id),
- ns_ops[np->opcode],
- ns_resp[np->rcode],
- np->aa? "*" : "",
- np->ra? "" : "-",
- np->tc? "|" : "");
+ 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 */
}
else {
/* this is a request */
- printf(" %d%s%s",
+ printf(" %d%s%s%s",
ntohs(np->id),
- ns_ops[np->opcode],
- np->rd? "+" : "");
+ ns_ops[DNS_OPCODE(np)],
+ DNS_RD(np)? "+" : "",
+ DNS_AD(np)? "$" : "");
/* any weirdness? */
- if (*(((u_short *)np)+1) & htons(0x6ff))
+ if (*(((u_short *)np)+1) & htons(0x6cf))
printf(" [b2&3=0x%x]", ntohs(*(((u_short *)np)+1)));
- if (np->opcode == IQUERY) {
+ if (DNS_OPCODE(np) == IQUERY) {
if (qdcount)
printf(" [%dq]", qdcount);
if (ancount != 1)