]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-domain.c
Allow tcpdump to work with earlier libpcaps.
[tcpdump] / print-domain.c
index ad3ee457996f95c86a751e8ab1fafa074ed7ea1b..98eb3a5e313dc249133bcc4a30966b85faf49fbb 100644 (file)
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.39 1999-10-07 23:47:11 mcr 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>
-#include <netinet/tcpip.h>
 
 #ifdef NOERROR
 #undef NOERROR                                 /* Solaris sucks */
@@ -50,9 +39,10 @@ struct rtentry;
 #ifdef NOERROR
 #undef T_UNSPEC                                        /* SINIX does too */
 #endif
-#include <arpa/nameser.h>
+#include "nameser.h"
 
 #include <stdio.h>
+#include <string.h>
 
 #include "interface.h"
 #include "addrtoname.h"
@@ -101,6 +91,27 @@ struct rtentry;
 #ifndef T_LOC
 #define T_LOC          29              /* Location Information */
 #endif
+#ifndef T_NXT
+#define T_NXT          30              /* Next Valid Name in Zone */
+#endif
+#ifndef T_EID
+#define T_EID          31              /* Endpoint identifier */
+#endif
+#ifndef T_NIMLOC
+#define T_NIMLOC       32              /* Nimrod locator */
+#endif
+#ifndef T_SRV
+#define T_SRV          33              /* Server selection */
+#endif
+#ifndef T_ATMA
+#define T_ATMA         34              /* ATM Address */
+#endif
+#ifndef T_NAPTR
+#define T_NAPTR                35              /* Naming Authority PoinTeR */
+#endif
+#ifndef T_A6
+#define T_A6           38              /* IP6 address (ipngwg-dns-lookups) */
+#endif
 
 #ifndef T_UNSPEC
 #define T_UNSPEC       103             /* Unspecified format (binary data) */
@@ -151,8 +162,11 @@ ns_nprint(register const u_char *cp, register const u_char *bp)
        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;
@@ -164,13 +178,29 @@ ns_nprint(register const u_char *cp, register const u_char *bp)
                        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;
                }
@@ -219,7 +249,14 @@ static struct tok type2str[] = {
        { T_PX,         "PX" },
        { T_GPOS,       "GPOS" },
        { T_AAAA,       "AAAA" },
-       { T_LOC ,       "LOC " },
+       { T_LOC,        "LOC " },
+       { T_NXT,        "NXT " },
+       { T_EID,        "EID " },
+       { T_NIMLOC,     "NIMLOC " },
+       { T_SRV,        "SRV " },
+       { T_ATMA,       "ATMA " },
+       { T_NAPTR,      "NAPTR " },
+       { T_A6,         "A6 " },
 #ifndef T_UINFO
 #define T_UINFO 100
 #endif
@@ -317,6 +354,9 @@ ns_rprint(register const u_char *cp, register const u_char *bp)
        case T_NS:
        case T_CNAME:
        case T_PTR:
+#ifdef T_DNAME
+       case T_DNAME:   /*XXX not checked as there's no server support yet*/
+#endif
                putchar(' ');
                (void)ns_nprint(cp, bp);
                break;
@@ -332,6 +372,25 @@ ns_rprint(register const u_char *cp, register const u_char *bp)
                (void)ns_cprint(cp, bp);
                break;
 
+#ifdef INET6
+       case T_AAAA:
+               printf(" %s", ip6addr_string(cp));
+               break;
+
+       case T_A6:      /*XXX not checked as there's no server support yet*/
+           {
+               struct in6_addr a;
+               int pbyte;
+
+               pbyte = (*cp + 7) / 8;
+               memset(&a, 0, sizeof(a));
+               memcpy(&a, cp + 1, pbyte);
+               printf(" %u %s ", *cp, ip6addr_string(&a));
+               (void)ns_nprint(cp + 1 + pbyte, bp);
+               break;
+           }
+#endif /*INET6*/
+
        case T_UNSPECA:         /* One long string */
                printf(" %.*s", len, cp);
                break;
@@ -353,15 +412,17 @@ ns_print(register const u_char *bp, u_int length)
        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 */
@@ -381,16 +442,17 @@ ns_print(register const u_char *bp, u_int length)
        }
        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)