]>
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.41 1999-10-30 05:11:12 itojun Exp $ (LBL)";
27 #include <sys/param.h>
29 #include <sys/socket.h>
37 #include <netinet/in.h>
38 #include <netinet/if_ether.h>
39 #include <netinet/in_systm.h>
40 #include <netinet/ip.h>
41 #include <netinet/ip_var.h>
42 #include <netinet/udp.h>
43 #include <netinet/udp_var.h>
44 #include <netinet/tcp.h>
47 #undef NOERROR /* Solaris sucks */
50 #undef T_UNSPEC /* SINIX does too */
52 #include <arpa/nameser.h>
57 #include "interface.h"
58 #include "addrtoname.h"
59 #include "extract.h" /* must come after interface.h */
63 #define T_TXT 16 /* text strings */
66 #define T_RP 17 /* responsible person */
69 #define T_AFSDB 18 /* AFS cell database */
72 #define T_X25 19 /* X_25 calling address */
75 #define T_ISDN 20 /* ISDN calling address */
78 #define T_RT 21 /* router */
81 #define T_NSAP 22 /* NSAP address */
84 #define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
87 #define T_SIG 24 /* security signature */
90 #define T_KEY 25 /* security key */
93 #define T_PX 26 /* X.400 mail mapping */
96 #define T_GPOS 27 /* geographical position (withdrawn) */
99 #define T_AAAA 28 /* IP6 Address */
102 #define T_LOC 29 /* Location Information */
105 #define T_NXT 30 /* Next Valid Name in Zone */
108 #define T_EID 31 /* Endpoint identifier */
111 #define T_NIMLOC 32 /* Nimrod locator */
114 #define T_SRV 33 /* Server selection */
117 #define T_ATMA 34 /* ATM Address */
120 #define T_NAPTR 35 /* Naming Authority PoinTeR */
123 #define T_A6 38 /* IP6 address (ipngwg-dns-lookups) */
127 #define T_UNSPEC 103 /* Unspecified format (binary data) */
130 #define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */
134 #define C_CHAOS 3 /* for chaos net (MIT) */
137 #define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
140 static char *ns_ops
[] = {
141 "", " inv_q", " stat", " op3", " notify", " op5", " op6", " op7",
142 " op8", " updataA", " updateD", " updateDA",
143 " updateM", " updateMA", " zoneInit", " zoneRef",
146 static char *ns_resp
[] = {
147 "", " FormErr", " ServFail", " NXDomain",
148 " NotImp", " Refused", " Resp6", " Resp7",
149 " Resp8", " Resp9", " Resp10", " Resp11",
150 " Resp12", " Resp13", " Resp14", " NoChange",
153 /* skip over a domain name */
154 static const u_char
*
155 ns_nskip(register const u_char
*cp
, register const u_char
*bp
)
159 if (((i
= *cp
++) & INDIR_MASK
) == INDIR_MASK
)
161 while (i
&& cp
< snapend
) {
168 /* print a <domain-name> */
169 static const u_char
*
170 ns_nprint(register const u_char
*cp
, register const u_char
*bp
)
173 register const u_char
*rp
;
174 register int compress
;
178 if ((i
& INDIR_MASK
) == INDIR_MASK
) {
184 while (i
&& cp
< snapend
) {
185 if ((i
& INDIR_MASK
) == INDIR_MASK
) {
186 cp
= bp
+ (((i
<< 8) | *cp
) & 0x3fff);
190 if (fn_printn(cp
, i
, snapend
))
203 /* print a <character-string> */
204 static const u_char
*
205 ns_cprint(register const u_char
*cp
, register const u_char
*bp
)
210 (void)fn_printn(cp
, i
, snapend
);
214 static struct tok type2str
[] = {
219 { T_CNAME
, "CNAME" },
227 { T_HINFO
, "HINFO" },
228 { T_MINFO
, "MINFO" },
232 { T_AFSDB
, "AFSDB" },
237 { T_NSAP_PTR
, "NSAP_PTR" },
246 { T_NIMLOC
, "NIMLOC " },
249 { T_NAPTR
, "NAPTR " },
254 { T_UINFO
, "UINFO" },
263 { T_UNSPEC
, "UNSPEC" },
264 { T_UNSPECA
, "UNSPECA" },
266 { T_MAILB
, "MAILB" },
267 { T_MAILA
, "MAILA" },
272 static struct tok class2str
[] = {
273 { C_IN
, "IN" }, /* Not used */
274 { C_CHAOS
, "CHAOS)" },
282 ns_qprint(register const u_char
*cp
, register const u_char
*bp
)
284 register const u_char
*np
= cp
;
287 cp
= ns_nskip(cp
, bp
);
289 if (cp
+ 4 > snapend
)
292 /* print the qtype and qclass (if it's not IN) */
295 printf(" %s", tok2str(type2str
, "Type%d", i
));
299 printf(" %s", tok2str(class2str
, "(Class %d)", i
));
306 static const u_char
*
307 ns_rprint(register const u_char
*cp
, register const u_char
*bp
)
310 register u_short typ
, len
;
311 register const u_char
*rp
;
315 cp
= ns_nprint(cp
, bp
);
317 cp
= ns_nskip(cp
, bp
);
319 if (cp
+ 10 > snapend
)
322 /* print the type/qtype and class (if it's not IN) */
328 printf(" %s", tok2str(class2str
, "(Class %d)", i
));
338 printf(" %s", tok2str(type2str
, "Type%d", typ
));
342 printf(" %s", ipaddr_string(cp
));
349 case T_DNAME
: /*XXX not checked as there's no server support yet*/
352 (void)ns_nprint(cp
, bp
);
357 (void)ns_nprint(cp
+ 2, bp
);
358 printf(" %d", EXTRACT_16BITS(cp
));
363 (void)ns_cprint(cp
, bp
);
368 printf(" %s", ip6addr_string(cp
));
371 case T_A6
: /*XXX not checked as there's no server support yet*/
376 pbyte
= (*cp
+ 7) / 8;
377 memset(&a
, 0, sizeof(a
));
378 memcpy(&a
, cp
+ 1, pbyte
);
379 printf(" %u %s ", *cp
, ip6addr_string(&a
));
380 (void)ns_nprint(cp
+ 1 + pbyte
, bp
);
385 case T_UNSPECA
: /* One long string */
386 printf(" %.*s", len
, cp
);
389 return (rp
); /* XXX This isn't always right */
393 ns_print(register const u_char
*bp
, u_int length
)
395 register const HEADER
*np
;
396 register int qdcount
, ancount
, nscount
, arcount
;
397 register const u_char
*cp
;
399 np
= (const HEADER
*)bp
;
400 /* get the byte-order right */
401 qdcount
= ntohs(np
->qdcount
);
402 ancount
= ntohs(np
->ancount
);
403 nscount
= ntohs(np
->nscount
);
404 arcount
= ntohs(np
->arcount
);
407 /* this is a response */
408 printf(" %d%s%s%s%s%s",
416 printf(" [%dq]", qdcount
);
417 /* Print QUESTION section on -vv */
419 fputs(" q: ", stdout
);
420 cp
= ns_nprint((const u_char
*)(np
+ 1), bp
);
422 cp
= ns_nskip((const u_char
*)(np
+ 1), bp
);
423 printf(" %d/%d/%d", ancount
, nscount
, arcount
);
425 cp
= ns_rprint(cp
+ 4, bp
);
426 while (ancount
-- && cp
< snapend
) {
428 cp
= ns_rprint(cp
, bp
);
433 /* this is a request */
440 if (*(((u_short
*)np
)+1) & htons(0x6ff))
441 printf(" [b2&3=0x%x]", ntohs(*(((u_short
*)np
)+1)));
443 if (np
->opcode
== IQUERY
) {
445 printf(" [%dq]", qdcount
);
447 printf(" [%da]", ancount
);
451 printf(" [%da]", ancount
);
453 printf(" [%dq]", qdcount
);
456 printf(" [%dn]", nscount
);
458 printf(" [%dau]", arcount
);
460 ns_qprint((const u_char
*)(np
+ 1), (const u_char
*)np
);
462 printf(" (%d)", length
);