Deleted Added
full compact
21c21
< * $FreeBSD: head/contrib/tcpdump/print-domain.c 56896 2000-01-30 01:05:24Z fenner $
---
> * $FreeBSD: head/contrib/tcpdump/print-domain.c 75118 2001-04-03 07:50:46Z fenner $
26c26
< "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.42 1999/11/21 09:36:50 fenner Exp $ (LBL)";
---
> "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.64 2001/01/02 23:24:51 guy Exp $ (LBL)";
35d34
< #include <sys/socket.h>
37,42d35
< #if __STDC__
< struct mbuf;
< struct rtentry;
< #endif
< #include <net/if.h>
<
44,50d36
< #include <net/ethernet.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>
58c44
< #include <arpa/nameser.h>
---
> #include "nameser.h"
129c115
< #define T_A6 38 /* IP6 address (ipngwg-dns-lookups) */
---
> #define T_A6 38 /* IP6 address */
130a117,119
> #ifndef T_DNAME
> #define T_DNAME 39 /* non-terminal redirection */
> #endif
131a121,124
> #ifndef T_OPT
> #define T_OPT 41 /* EDNS0 option (meta-RR) */
> #endif
>
166a160,161
> if (cp >= snapend)
> return(NULL);
168c163,175
< cp += i;
---
> if ((i & INDIR_MASK) == EDNS0_MASK) {
> int bitlen, bytelen;
>
> if ((i & ~INDIR_MASK) != EDNS0_ELT_BITLABEL)
> return(NULL); /* unknown ELT */
> if ((bitlen = *cp++) == 0)
> bitlen = 256;
> bytelen = (bitlen + 7) / 8;
> cp += bytelen;
> } else
> cp += i;
> if (cp >= snapend)
> return(NULL);
176c183
< ns_nprint(register const u_char *cp, register const u_char *bp)
---
> blabel_print(const u_char *cp)
177a185,220
> int bitlen, slen, b;
> int truncated = 0;
> const u_char *bitp, *lim;
> char tc;
>
> if (cp >= snapend)
> return(NULL);
> if ((bitlen = *cp) == 0)
> bitlen = 256;
> slen = (bitlen + 3) / 4;
> if ((lim = cp + 1 + slen) > snapend) {
> truncated = 1;
> lim = snapend;
> }
>
> /* print the bit string as a hex string */
> printf("\\[x");
> for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++)
> printf("%02x", *bitp);
> if (bitp == lim)
> printf("...");
> else if (b > 4) {
> tc = *bitp++;
> printf("%02x", tc & (0xff << (8 - b)));
> } else if (b > 0) {
> tc = *bitp++;
> printf("%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b)));
> }
> printf("/%d]", bitlen);
>
> return(truncated ? NULL : lim);
> }
>
> static int
> labellen(const u_char *cp)
> {
179,180d221
< register const u_char *rp;
< register int compress;
182,186c223,235
< i = *cp++;
< rp = cp + i;
< if ((i & INDIR_MASK) == INDIR_MASK) {
< rp = cp + 1;
< compress = 1;
---
> if (cp >= snapend)
> return(-1);
> i = *cp;
> if ((i & INDIR_MASK) == EDNS0_MASK) {
> int bitlen, elt;
>
> if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL)
> return(-1);
> if (cp + 1 >= snapend)
> return(-1);
> if ((bitlen = *(cp + 1)) == 0)
> bitlen = 256;
> return(((bitlen + 7) / 8) + 1);
187a237,255
> return(i);
> }
>
> static const u_char *
> ns_nprint(register const u_char *cp, register const u_char *bp)
> {
> register u_int i, l;
> register const u_char *rp = NULL;
> register int compress = 0;
> int chars_processed;
> int elt;
> int data_size = snapend - bp;
>
> if ((l = labellen(cp)) < 0)
> return(NULL);
> if (cp >= snapend)
> return(NULL);
> chars_processed = 1;
> if (((i = *cp++) & INDIR_MASK) != INDIR_MASK) {
188a257,259
> rp = cp + l;
> }
>
191a263,266
> if (!compress) {
> rp = cp + 1;
> compress = 1;
> }
192a268,271
> if (cp >= snapend)
> return(NULL);
> if ((l = labellen(cp)) < 0)
> return(NULL);
193a273,284
> 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) {
> printf("<LOOP>");
> return (NULL);
> }
196,198c287,304
< if (fn_printn(cp, i, snapend))
< break;
< cp += i;
---
> if ((i & INDIR_MASK) == EDNS0_MASK) {
> elt = (i & ~INDIR_MASK);
> switch(elt) {
> case EDNS0_ELT_BITLABEL:
> blabel_print(cp);
> break;
> default:
> /* unknown ELT */
> printf("<ELT %d>", elt);
> return(NULL);
> }
> } else {
> if (fn_printn(cp, l, snapend))
> break;
> }
>
> cp += l;
> chars_processed += l;
199a306,307
> if (cp >= snapend || (l = labellen(cp)) < 0)
> return(NULL);
200a309
> chars_processed++;
202c311
< rp += i + 1;
---
> rp += l + 1;
214a324,325
> if (cp >= snapend)
> return NULL;
257,259c368,369
< #ifndef T_UINFO
< #define T_UINFO 100
< #endif
---
> { T_DNAME, "DNAME " },
> { T_OPT, "OPT " },
261,263d370
< #ifndef T_UID
< #define T_UID 101
< #endif
265,267d371
< #ifndef T_GID
< #define T_GID 102
< #endif
287c391
< static void
---
> static const u_char *
295,296c399,400
< if (cp + 4 > snapend)
< return;
---
> if (cp + 4 > snapend || cp == NULL)
> return(NULL);
308c412,413
< ns_nprint(np, bp);
---
> cp = ns_nprint(np, bp);
> return(cp ? cp + 4 : NULL);
315c420
< register u_int i;
---
> register u_int class;
321c426,427
< cp = ns_nprint(cp, bp);
---
> if ((cp = ns_nprint(cp, bp)) == NULL)
> return NULL;
325c431
< if (cp + 10 > snapend)
---
> if (cp + 10 > snapend || cp == NULL)
331,334c437,440
< i = *cp++ << 8;
< i |= *cp++;
< if (i != C_IN)
< printf(" %s", tok2str(class2str, "(Class %d)", i));
---
> class = *cp++ << 8;
> class |= *cp++;
> if (class != C_IN && typ != T_OPT)
> printf(" %s", tok2str(class2str, "(Class %d)", class));
345c451,452
< switch (typ) {
---
> if (rp > snapend)
> return(NULL);
346a454
> switch (typ) {
347a456,457
> if (cp + sizeof(struct in_addr) > snapend)
> return(NULL);
355c465
< case T_DNAME: /*XXX not checked as there's no server support yet*/
---
> case T_DNAME:
358c468,469
< (void)ns_nprint(cp, bp);
---
> if (ns_nprint(cp, bp) == NULL)
> return(NULL);
360a472,493
> case T_SOA:
> if (!vflag)
> break;
> putchar(' ');
> if ((cp = ns_nprint(cp, bp)) == NULL)
> return(NULL);
> putchar(' ');
> if ((cp = ns_nprint(cp, bp)) == NULL)
> return(NULL);
> if (cp + 5 * 4 > snapend)
> return(NULL);
> printf(" %u", EXTRACT_32BITS(cp));
> cp += 4;
> printf(" %u", EXTRACT_32BITS(cp));
> cp += 4;
> printf(" %u", EXTRACT_32BITS(cp));
> cp += 4;
> printf(" %u", EXTRACT_32BITS(cp));
> cp += 4;
> printf(" %u", EXTRACT_32BITS(cp));
> cp += 4;
> break;
363c496,499
< (void)ns_nprint(cp + 2, bp);
---
> if (cp + 2 > snapend)
> return(NULL);
> if (ns_nprint(cp + 2, bp) == NULL)
> return(NULL);
373a510,511
> if (cp + sizeof(struct in6_addr) > snapend)
> return(NULL);
377c515
< case T_A6: /*XXX not checked as there's no server support yet*/
---
> case T_A6:
380c518
< int pbyte;
---
> int pbit, pbyte;
382,386c520,534
< 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);
---
> pbit = *cp;
> pbyte = (pbit & ~7) / 8;
> if (pbit > 128) {
> printf(" %u(bad plen)", pbit);
> break;
> } else if (pbit < 128) {
> memset(&a, 0, sizeof(a));
> memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte);
> printf(" %u %s", pbit, ip6addr_string(&a));
> }
> if (pbit > 0) {
> putchar(' ');
> if (ns_nprint(cp + 1 + sizeof(a) - pbyte, bp) == NULL)
> return(NULL);
> }
390a539,542
> case T_OPT:
> printf(" UDPsize=%u", class);
> break;
>
392c544,546
< printf(" %.*s", len, cp);
---
> if (cp + len > snapend)
> return(NULL);
> fn_printn(cp, len, snapend);
403c557
< register const u_char *cp;
---
> register const u_char *cp = NULL;
412c566
< if (np->qr) {
---
> if (DNS_QR(np)) {
414c568
< printf(" %d%s%s%s%s%s",
---
> printf(" %d%s%s%s%s%s%s",
416,420c570,576
< 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)? "%" : "");
>
425,428c581,590
< fputs(" q: ", stdout);
< cp = ns_nprint((const u_char *)(np + 1), bp);
< } else
< cp = ns_nskip((const u_char *)(np + 1), bp);
---
> fputs(" q:", stdout);
> if ((cp = ns_qprint((const u_char *)(np + 1), bp))
> == NULL)
> goto trunc;
> } else {
> if ((cp = ns_nskip((const u_char *)(np + 1), bp))
> == NULL)
> goto trunc;
> cp += 4;
> }
431c593,594
< cp = ns_rprint(cp + 4, bp);
---
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
434c597,598
< cp = ns_rprint(cp, bp);
---
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
436a601,623
> /* Print NS and AR sections on -vv */
> if (vflag > 1) {
> if (nscount-- && cp < snapend) {
> fputs(" ns:", stdout);
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
> while (nscount-- && cp < snapend) {
> putchar(',');
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
> }
> }
> if (arcount-- && cp < snapend) {
> fputs(" ar:", stdout);
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
> while (arcount-- && cp < snapend) {
> putchar(',');
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
> }
> }
> }
440,443c627,629
< printf(" %d%s%s",
< ntohs(np->id),
< ns_ops[np->opcode],
< np->rd? "+" : "");
---
> printf(" %d%s%s%s", ntohs(np->id), ns_ops[DNS_OPCODE(np)],
> DNS_RD(np) ? "+" : "",
> DNS_AD(np) ? "$" : "");
446c632
< if (*(((u_short *)np)+1) & htons(0x6ff))
---
> if (*(((u_short *)np)+1) & htons(0x6cf))
449c635
< if (np->opcode == IQUERY) {
---
> if (DNS_OPCODE(np) == IQUERY) {
466c652,700
< ns_qprint((const u_char *)(np + 1), (const u_char *)np);
---
> if (qdcount--) {
> cp = ns_qprint((const u_char *)(np + 1),
> (const u_char *)np);
> if (!cp)
> goto trunc;
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
> while (qdcount-- && cp < snapend) {
> cp = ns_qprint((const u_char *)cp,
> (const u_char *)np);
> if (!cp)
> goto trunc;
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
> }
> }
>
> /* Print remaining sections on -vv */
> if (vflag > 1) {
> if (ancount--) {
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
> while (ancount-- && cp < snapend) {
> putchar(',');
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
> }
> }
> if (nscount-- && cp < snapend) {
> fputs(" ns:", stdout);
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
> while (nscount-- && cp < snapend) {
> putchar(',');
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
> }
> }
> if (arcount-- && cp < snapend) {
> fputs(" ar:", stdout);
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
> while (arcount-- && cp < snapend) {
> putchar(',');
> if ((cp = ns_rprint(cp, bp)) == NULL)
> goto trunc;
> }
> }
> }
468a703,707
> return;
>
> trunc:
> printf("[|domain]");
> return;