]>
git.saurik.com Git - apple/network_cmds.git/blob - tcpdump.tproj/print-domain.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that: (1) source code distributions
30 * retain the above copyright notice and this paragraph in its entirety, (2)
31 * distributions including binary code include the above copyright notice and
32 * this paragraph in its entirety in the documentation or other materials
33 * provided with the distribution, and (3) all advertising materials mentioning
34 * features or use of this software display the following acknowledgement:
35 * ``This product includes software developed by the University of California,
36 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
37 * the University nor the names of its contributors may be used to endorse
38 * or promote products derived from this software without specific prior
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
41 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
46 static const char rcsid
[] =
47 "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-domain.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)";
50 #include <sys/param.h>
52 #include <sys/socket.h>
60 #include <netinet/in.h>
61 #include <netinet/if_ether.h>
62 #include <netinet/in_systm.h>
63 #include <netinet/ip.h>
64 #include <netinet/ip_var.h>
65 #include <netinet/udp.h>
66 #include <netinet/udp_var.h>
67 #include <netinet/tcp.h>
68 #include <netinet/tcpip.h>
70 #undef NOERROR /* Solaris sucks */
71 #undef T_UNSPEC /* SINIX does too */
72 #include <arpa/nameser.h>
76 #include "interface.h"
77 #include "addrtoname.h"
78 #include "extract.h" /* must come after interface.h */
82 #define T_TXT 16 /* text strings */
85 #define T_RP 17 /* responsible person */
88 #define T_AFSDB 18 /* AFS cell database */
91 #define T_X25 19 /* X_25 calling address */
94 #define T_ISDN 20 /* ISDN calling address */
97 #define T_RT 21 /* router */
100 #define T_NSAP 22 /* NSAP address */
103 #define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
106 #define T_SIG 24 /* security signature */
109 #define T_KEY 25 /* security key */
112 #define T_PX 26 /* X.400 mail mapping */
115 #define T_GPOS 27 /* geographical position (withdrawn) */
118 #define T_AAAA 28 /* IP6 Address */
121 #define T_LOC 29 /* Location Information */
125 #define T_UNSPEC 103 /* Unspecified format (binary data) */
128 #define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */
132 #define C_CHAOS 3 /* for chaos net (MIT) */
135 #define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
138 static char *ns_ops
[] = {
139 "", " inv_q", " stat", " op3", " notify", " op5", " op6", " op7",
140 " op8", " updataA", " updateD", " updateDA",
141 " updateM", " updateMA", " zoneInit", " zoneRef",
144 static char *ns_resp
[] = {
145 "", " FormErr", " ServFail", " NXDomain",
146 " NotImp", " Refused", " Resp6", " Resp7",
147 " Resp8", " Resp9", " Resp10", " Resp11",
148 " Resp12", " Resp13", " Resp14", " NoChange",
151 /* skip over a domain name */
152 static const u_char
*
153 ns_nskip(register const u_char
*cp
, register const u_char
*bp
)
157 if (((i
= *cp
++) & INDIR_MASK
) == INDIR_MASK
)
159 while (i
&& cp
< snapend
) {
166 /* print a <domain-name> */
167 static const u_char
*
168 ns_nprint(register const u_char
*cp
, register const u_char
*bp
)
171 register const u_char
*rp
;
172 register int compress
;
176 if ((i
& INDIR_MASK
) == INDIR_MASK
) {
182 while (i
&& cp
< snapend
) {
183 if ((i
& INDIR_MASK
) == INDIR_MASK
) {
184 cp
= bp
+ (((i
<< 8) | *cp
) & 0x3fff);
188 if (fn_printn(cp
, i
, snapend
))
201 /* print a <character-string> */
202 static const u_char
*
203 ns_cprint(register const u_char
*cp
, register const u_char
*bp
)
208 (void)fn_printn(cp
, i
, snapend
);
212 static struct tok type2str
[] = {
217 { T_CNAME
, "CNAME" },
225 { T_HINFO
, "HINFO" },
226 { T_MINFO
, "MINFO" },
230 { T_AFSDB
, "AFSDB" },
235 { T_NSAP_PTR
, "NSAP_PTR" },
242 { T_UINFO
, "UINFO" },
245 { T_UNSPEC
, "UNSPEC" },
246 { T_UNSPECA
, "UNSPECA" },
248 { T_MAILB
, "MAILB" },
249 { T_MAILA
, "MAILA" },
254 static struct tok class2str
[] = {
255 { C_IN
, "IN" }, /* Not used */
256 { C_CHAOS
, "CHAOS)" },
264 ns_qprint(register const u_char
*cp
, register const u_char
*bp
)
266 register const u_char
*np
= cp
;
269 cp
= ns_nskip(cp
, bp
);
271 if (cp
+ 4 > snapend
)
274 /* print the qtype and qclass (if it's not IN) */
277 printf(" %s", tok2str(type2str
, "Type%d", i
));
281 printf(" %s", tok2str(class2str
, "(Class %d)", i
));
288 static const u_char
*
289 ns_rprint(register const u_char
*cp
, register const u_char
*bp
)
292 register u_short typ
, len
;
293 register const u_char
*rp
;
297 cp
= ns_nprint(cp
, bp
);
299 cp
= ns_nskip(cp
, bp
);
301 if (cp
+ 10 > snapend
)
304 /* print the type/qtype and class (if it's not IN) */
310 printf(" %s", tok2str(class2str
, "(Class %d)", i
));
320 printf(" %s", tok2str(type2str
, "Type%d", typ
));
324 printf(" %s", ipaddr_string(cp
));
331 (void)ns_nprint(cp
, bp
);
336 (void)ns_nprint(cp
+ 2, bp
);
337 printf(" %d", EXTRACT_16BITS(cp
));
342 (void)ns_cprint(cp
, bp
);
345 case T_UNSPECA
: /* One long string */
346 printf(" %.*s", len
, cp
);
349 return (rp
); /* XXX This isn't always right */
353 ns_print(register const u_char
*bp
, u_int length
)
355 register const HEADER
*np
;
356 register int qdcount
, ancount
, nscount
, arcount
;
357 register const u_char
*cp
;
359 np
= (const HEADER
*)bp
;
360 /* get the byte-order right */
361 qdcount
= ntohs(np
->qdcount
);
362 ancount
= ntohs(np
->ancount
);
363 nscount
= ntohs(np
->nscount
);
364 arcount
= ntohs(np
->arcount
);
367 /* this is a response */
368 printf(" %d%s%s%s%s%s",
376 printf(" [%dq]", qdcount
);
377 /* Print QUESTION section on -vv */
379 fputs(" q: ", stdout
);
380 cp
= ns_nprint((const u_char
*)(np
+ 1), bp
);
382 cp
= ns_nskip((const u_char
*)(np
+ 1), bp
);
383 printf(" %d/%d/%d", ancount
, nscount
, arcount
);
385 cp
= ns_rprint(cp
+ 4, bp
);
386 while (ancount
-- && cp
< snapend
) {
388 cp
= ns_rprint(cp
, bp
);
393 /* this is a request */
400 if (*(((u_short
*)np
)+1) & htons(0x6ff))
401 printf(" [b2&3=0x%x]", ntohs(*(((u_short
*)np
)+1)));
403 if (np
->opcode
== IQUERY
) {
405 printf(" [%dq]", qdcount
);
407 printf(" [%da]", ancount
);
411 printf(" [%da]", ancount
);
413 printf(" [%dq]", qdcount
);
416 printf(" [%dn]", nscount
);
418 printf(" [%dau]", arcount
);
420 ns_qprint((const u_char
*)(np
+ 1), (const u_char
*)np
);
422 printf(" (%d)", length
);