]>
The Tcpdump Group git mirrors - tcpdump/blob - print-domain.c
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static const char rcsid
[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.53 2000-10-03 09:13:25 guy Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
38 #include <netinet/in.h>
41 #undef NOERROR /* Solaris sucks */
44 #undef T_UNSPEC /* SINIX does too */
51 #include "interface.h"
52 #include "addrtoname.h"
53 #include "extract.h" /* must come after interface.h */
57 #define T_TXT 16 /* text strings */
60 #define T_RP 17 /* responsible person */
63 #define T_AFSDB 18 /* AFS cell database */
66 #define T_X25 19 /* X_25 calling address */
69 #define T_ISDN 20 /* ISDN calling address */
72 #define T_RT 21 /* router */
75 #define T_NSAP 22 /* NSAP address */
78 #define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
81 #define T_SIG 24 /* security signature */
84 #define T_KEY 25 /* security key */
87 #define T_PX 26 /* X.400 mail mapping */
90 #define T_GPOS 27 /* geographical position (withdrawn) */
93 #define T_AAAA 28 /* IP6 Address */
96 #define T_LOC 29 /* Location Information */
99 #define T_NXT 30 /* Next Valid Name in Zone */
102 #define T_EID 31 /* Endpoint identifier */
105 #define T_NIMLOC 32 /* Nimrod locator */
108 #define T_SRV 33 /* Server selection */
111 #define T_ATMA 34 /* ATM Address */
114 #define T_NAPTR 35 /* Naming Authority PoinTeR */
117 #define T_A6 38 /* IP6 address (ipngwg-dns-lookups) */
121 #define T_UNSPEC 103 /* Unspecified format (binary data) */
124 #define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */
128 #define C_CHAOS 3 /* for chaos net (MIT) */
131 #define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
134 static char *ns_ops
[] = {
135 "", " inv_q", " stat", " op3", " notify", " op5", " op6", " op7",
136 " op8", " updataA", " updateD", " updateDA",
137 " updateM", " updateMA", " zoneInit", " zoneRef",
140 static char *ns_resp
[] = {
141 "", " FormErr", " ServFail", " NXDomain",
142 " NotImp", " Refused", " Resp6", " Resp7",
143 " Resp8", " Resp9", " Resp10", " Resp11",
144 " Resp12", " Resp13", " Resp14", " NoChange",
147 /* skip over a domain name */
148 static const u_char
*
149 ns_nskip(register const u_char
*cp
, register const u_char
*bp
)
153 if (((i
= *cp
++) & INDIR_MASK
) == INDIR_MASK
)
155 while (i
&& cp
< snapend
) {
162 /* print a <domain-name> */
163 static const u_char
*
164 ns_nprint(register const u_char
*cp
, register const u_char
*bp
)
167 register const u_char
*rp
;
168 register int compress
;
170 int data_size
= snapend
- bp
;
175 if ((i
& INDIR_MASK
) == INDIR_MASK
) {
181 while (i
&& cp
< snapend
) {
182 if ((i
& INDIR_MASK
) == INDIR_MASK
) {
183 cp
= bp
+ (((i
<< 8) | *cp
) & 0x3fff);
188 * If we've looked at every character in
189 * the message, this pointer will make
190 * us look at some character again,
191 * which means we're looping.
193 if (chars_processed
>= data_size
) {
194 fn_printn(cp
, 6, (u_char
*)"<LOOP>");
201 if (fn_printn(cp
, i
, snapend
))
204 chars_processed
+= i
;
216 /* print a <character-string> */
217 static const u_char
*
218 ns_cprint(register const u_char
*cp
, register const u_char
*bp
)
223 (void)fn_printn(cp
, i
, snapend
);
227 static struct tok type2str
[] = {
232 { T_CNAME
, "CNAME" },
240 { T_HINFO
, "HINFO" },
241 { T_MINFO
, "MINFO" },
245 { T_AFSDB
, "AFSDB" },
250 { T_NSAP_PTR
, "NSAP_PTR" },
259 { T_NIMLOC
, "NIMLOC " },
262 { T_NAPTR
, "NAPTR " },
267 { T_UINFO
, "UINFO" },
276 { T_UNSPEC
, "UNSPEC" },
277 { T_UNSPECA
, "UNSPECA" },
279 { T_MAILB
, "MAILB" },
280 { T_MAILA
, "MAILA" },
285 static struct tok class2str
[] = {
286 { C_IN
, "IN" }, /* Not used */
287 { C_CHAOS
, "CHAOS)" },
295 ns_qprint(register const u_char
*cp
, register const u_char
*bp
)
297 register const u_char
*np
= cp
;
300 cp
= ns_nskip(cp
, bp
);
302 if (cp
+ 4 > snapend
)
305 /* print the qtype and qclass (if it's not IN) */
308 printf(" %s", tok2str(type2str
, "Type%d", i
));
312 printf(" %s", tok2str(class2str
, "(Class %d)", i
));
319 static const u_char
*
320 ns_rprint(register const u_char
*cp
, register const u_char
*bp
)
323 register u_short typ
, len
;
324 register const u_char
*rp
;
328 cp
= ns_nprint(cp
, bp
);
330 cp
= ns_nskip(cp
, bp
);
332 if (cp
+ 10 > snapend
)
335 /* print the type/qtype and class (if it's not IN) */
341 printf(" %s", tok2str(class2str
, "(Class %d)", i
));
351 printf(" %s", tok2str(type2str
, "Type%d", typ
));
355 printf(" %s", ipaddr_string(cp
));
362 case T_DNAME
: /*XXX not checked as there's no server support yet*/
365 (void)ns_nprint(cp
, bp
);
370 (void)ns_nprint(cp
+ 2, bp
);
371 printf(" %d", EXTRACT_16BITS(cp
));
376 (void)ns_cprint(cp
, bp
);
381 printf(" %s", ip6addr_string(cp
));
384 case T_A6
: /*XXX not checked as there's no server support yet*/
389 pbyte
= (*cp
+ 7) / 8;
390 memset(&a
, 0, sizeof(a
));
391 memcpy(&a
, cp
+ 1, pbyte
);
392 printf(" %u %s ", *cp
, ip6addr_string(&a
));
393 (void)ns_nprint(cp
+ 1 + pbyte
, bp
);
398 case T_UNSPECA
: /* One long string */
399 printf(" %.*s", len
, cp
);
402 return (rp
); /* XXX This isn't always right */
406 ns_print(register const u_char
*bp
, u_int length
)
408 register const HEADER
*np
;
409 register int qdcount
, ancount
, nscount
, arcount
;
410 register const u_char
*cp
;
412 np
= (const HEADER
*)bp
;
413 /* get the byte-order right */
414 qdcount
= ntohs(np
->qdcount
);
415 ancount
= ntohs(np
->ancount
);
416 nscount
= ntohs(np
->nscount
);
417 arcount
= ntohs(np
->arcount
);
420 /* this is a response */
421 printf(" %d%s%s%s%s%s%s",
423 ns_ops
[DNS_OPCODE(np
)],
424 ns_resp
[DNS_RCODE(np
)],
425 DNS_AA(np
)? "*" : "",
426 DNS_RA(np
)? "" : "-",
427 DNS_TC(np
)? "|" : "",
428 DNS_CD(np
)? "%" : "");
431 printf(" [%dq]", qdcount
);
432 /* Print QUESTION section on -vv */
434 fputs(" q: ", stdout
);
435 cp
= ns_nprint((const u_char
*)(np
+ 1), bp
);
437 cp
= ns_nskip((const u_char
*)(np
+ 1), bp
);
438 printf(" %d/%d/%d", ancount
, nscount
, arcount
);
440 cp
= ns_rprint(cp
+ 4, bp
);
441 while (ancount
-- && cp
< snapend
) {
443 cp
= ns_rprint(cp
, bp
);
448 /* this is a request */
451 ns_ops
[DNS_OPCODE(np
)],
452 DNS_RD(np
)? "+" : "",
453 DNS_AD(np
)? "$" : "");
456 if (*(((u_short
*)np
)+1) & htons(0x6cf))
457 printf(" [b2&3=0x%x]", ntohs(*(((u_short
*)np
)+1)));
459 if (DNS_OPCODE(np
) == IQUERY
) {
461 printf(" [%dq]", qdcount
);
463 printf(" [%da]", ancount
);
467 printf(" [%da]", ancount
);
469 printf(" [%dq]", qdcount
);
472 printf(" [%dn]", nscount
);
474 printf(" [%dau]", arcount
);
476 ns_qprint((const u_char
*)(np
+ 1), (const u_char
*)np
);
478 printf(" (%d)", length
);