]>
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.49 2000-09-23 08:54:27 guy Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <netinet/in_systm.h>
43 #undef NOERROR /* Solaris sucks */
46 #undef T_UNSPEC /* SINIX does too */
53 #include "interface.h"
54 #include "addrtoname.h"
55 #include "extract.h" /* must come after interface.h */
59 #define T_TXT 16 /* text strings */
62 #define T_RP 17 /* responsible person */
65 #define T_AFSDB 18 /* AFS cell database */
68 #define T_X25 19 /* X_25 calling address */
71 #define T_ISDN 20 /* ISDN calling address */
74 #define T_RT 21 /* router */
77 #define T_NSAP 22 /* NSAP address */
80 #define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
83 #define T_SIG 24 /* security signature */
86 #define T_KEY 25 /* security key */
89 #define T_PX 26 /* X.400 mail mapping */
92 #define T_GPOS 27 /* geographical position (withdrawn) */
95 #define T_AAAA 28 /* IP6 Address */
98 #define T_LOC 29 /* Location Information */
101 #define T_NXT 30 /* Next Valid Name in Zone */
104 #define T_EID 31 /* Endpoint identifier */
107 #define T_NIMLOC 32 /* Nimrod locator */
110 #define T_SRV 33 /* Server selection */
113 #define T_ATMA 34 /* ATM Address */
116 #define T_NAPTR 35 /* Naming Authority PoinTeR */
119 #define T_A6 38 /* IP6 address (ipngwg-dns-lookups) */
123 #define T_UNSPEC 103 /* Unspecified format (binary data) */
126 #define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */
130 #define C_CHAOS 3 /* for chaos net (MIT) */
133 #define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
136 static char *ns_ops
[] = {
137 "", " inv_q", " stat", " op3", " notify", " op5", " op6", " op7",
138 " op8", " updataA", " updateD", " updateDA",
139 " updateM", " updateMA", " zoneInit", " zoneRef",
142 static char *ns_resp
[] = {
143 "", " FormErr", " ServFail", " NXDomain",
144 " NotImp", " Refused", " Resp6", " Resp7",
145 " Resp8", " Resp9", " Resp10", " Resp11",
146 " Resp12", " Resp13", " Resp14", " NoChange",
149 /* skip over a domain name */
150 static const u_char
*
151 ns_nskip(register const u_char
*cp
, register const u_char
*bp
)
155 if (((i
= *cp
++) & INDIR_MASK
) == INDIR_MASK
)
157 while (i
&& cp
< snapend
) {
164 /* print a <domain-name> */
165 static const u_char
*
166 ns_nprint(register const u_char
*cp
, register const u_char
*bp
)
169 register const u_char
*rp
;
170 register int compress
;
172 int data_size
= snapend
- bp
;
177 if ((i
& INDIR_MASK
) == INDIR_MASK
) {
183 while (i
&& cp
< snapend
) {
184 if ((i
& INDIR_MASK
) == INDIR_MASK
) {
185 cp
= bp
+ (((i
<< 8) | *cp
) & 0x3fff);
190 * If we've looked at every character in
191 * the message, this pointer will make
192 * us look at some character again,
193 * which means we're looping.
195 if (chars_processed
>= data_size
) {
196 fn_printn(cp
, 6, "<LOOP>");
203 if (fn_printn(cp
, i
, snapend
))
206 chars_processed
+= i
;
218 /* print a <character-string> */
219 static const u_char
*
220 ns_cprint(register const u_char
*cp
, register const u_char
*bp
)
225 (void)fn_printn(cp
, i
, snapend
);
229 static struct tok type2str
[] = {
234 { T_CNAME
, "CNAME" },
242 { T_HINFO
, "HINFO" },
243 { T_MINFO
, "MINFO" },
247 { T_AFSDB
, "AFSDB" },
252 { T_NSAP_PTR
, "NSAP_PTR" },
261 { T_NIMLOC
, "NIMLOC " },
264 { T_NAPTR
, "NAPTR " },
269 { T_UINFO
, "UINFO" },
278 { T_UNSPEC
, "UNSPEC" },
279 { T_UNSPECA
, "UNSPECA" },
281 { T_MAILB
, "MAILB" },
282 { T_MAILA
, "MAILA" },
287 static struct tok class2str
[] = {
288 { C_IN
, "IN" }, /* Not used */
289 { C_CHAOS
, "CHAOS)" },
297 ns_qprint(register const u_char
*cp
, register const u_char
*bp
)
299 register const u_char
*np
= cp
;
302 cp
= ns_nskip(cp
, bp
);
304 if (cp
+ 4 > snapend
)
307 /* print the qtype and qclass (if it's not IN) */
310 printf(" %s", tok2str(type2str
, "Type%d", i
));
314 printf(" %s", tok2str(class2str
, "(Class %d)", i
));
321 static const u_char
*
322 ns_rprint(register const u_char
*cp
, register const u_char
*bp
)
325 register u_short typ
, len
;
326 register const u_char
*rp
;
330 cp
= ns_nprint(cp
, bp
);
332 cp
= ns_nskip(cp
, bp
);
334 if (cp
+ 10 > snapend
)
337 /* print the type/qtype and class (if it's not IN) */
343 printf(" %s", tok2str(class2str
, "(Class %d)", i
));
353 printf(" %s", tok2str(type2str
, "Type%d", typ
));
357 printf(" %s", ipaddr_string(cp
));
364 case T_DNAME
: /*XXX not checked as there's no server support yet*/
367 (void)ns_nprint(cp
, bp
);
372 (void)ns_nprint(cp
+ 2, bp
);
373 printf(" %d", EXTRACT_16BITS(cp
));
378 (void)ns_cprint(cp
, bp
);
383 printf(" %s", ip6addr_string(cp
));
386 case T_A6
: /*XXX not checked as there's no server support yet*/
391 pbyte
= (*cp
+ 7) / 8;
392 memset(&a
, 0, sizeof(a
));
393 memcpy(&a
, cp
+ 1, pbyte
);
394 printf(" %u %s ", *cp
, ip6addr_string(&a
));
395 (void)ns_nprint(cp
+ 1 + pbyte
, bp
);
400 case T_UNSPECA
: /* One long string */
401 printf(" %.*s", len
, cp
);
404 return (rp
); /* XXX This isn't always right */
408 ns_print(register const u_char
*bp
, u_int length
)
410 register const HEADER
*np
;
411 register int qdcount
, ancount
, nscount
, arcount
;
412 register const u_char
*cp
;
414 np
= (const HEADER
*)bp
;
415 /* get the byte-order right */
416 qdcount
= ntohs(np
->qdcount
);
417 ancount
= ntohs(np
->ancount
);
418 nscount
= ntohs(np
->nscount
);
419 arcount
= ntohs(np
->arcount
);
422 /* this is a response */
423 printf(" %d%s%s%s%s%s%s",
433 printf(" [%dq]", qdcount
);
434 /* Print QUESTION section on -vv */
436 fputs(" q: ", stdout
);
437 cp
= ns_nprint((const u_char
*)(np
+ 1), bp
);
439 cp
= ns_nskip((const u_char
*)(np
+ 1), bp
);
440 printf(" %d/%d/%d", ancount
, nscount
, arcount
);
442 cp
= ns_rprint(cp
+ 4, bp
);
443 while (ancount
-- && cp
< snapend
) {
445 cp
= ns_rprint(cp
, bp
);
450 /* this is a request */
458 if (*(((u_short
*)np
)+1) & htons(0x6cf))
459 printf(" [b2&3=0x%x]", ntohs(*(((u_short
*)np
)+1)));
461 if (np
->opcode
== IQUERY
) {
463 printf(" [%dq]", qdcount
);
465 printf(" [%da]", ancount
);
469 printf(" [%da]", ancount
);
471 printf(" [%dq]", qdcount
);
474 printf(" [%dn]", nscount
);
476 printf(" [%dau]", arcount
);
478 ns_qprint((const u_char
*)(np
+ 1), (const u_char
*)np
);
480 printf(" (%d)", length
);