print-domain.c (98527) | print-domain.c (127675) |
---|---|
1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 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 --- 4 unchanged lines hidden (view full) --- 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 16 * written permission. 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. 20 * | 1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 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 --- 4 unchanged lines hidden (view full) --- 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 16 * written permission. 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. 20 * |
21 * $FreeBSD: head/contrib/tcpdump/print-domain.c 98527 2002-06-21 00:49:02Z fenner $ | 21 * $FreeBSD: head/contrib/tcpdump/print-domain.c 127675 2004-03-31 14:57:24Z bms $ |
22 */ 23 24#ifndef lint | 22 */ 23 24#ifndef lint |
25static const char rcsid[] = 26 "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.78 2001/10/19 09:00:48 guy Exp $ (LBL)"; | 25static const char rcsid[] _U_ = 26 "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.86.2.3 2004/03/28 20:54:00 fenner Exp $ (LBL)"; |
27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 | 27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 |
33#include <sys/param.h> 34#include <sys/time.h> | 33#include <tcpdump-stdinc.h> |
35 | 34 |
36#include <netinet/in.h> 37 | |
38#include "nameser.h" 39 40#include <stdio.h> 41#include <string.h> 42 43#include "interface.h" 44#include "addrtoname.h" 45#include "extract.h" /* must come after interface.h */ --- 8 unchanged lines hidden (view full) --- 54 "", " FormErr", " ServFail", " NXDomain", 55 " NotImp", " Refused", " YXDomain", " YXRRSet", 56 " NXRRSet", " NotAuth", " NotZone", " Resp11", 57 " Resp12", " Resp13", " Resp14", " NoChange", 58}; 59 60/* skip over a domain name */ 61static const u_char * | 35#include "nameser.h" 36 37#include <stdio.h> 38#include <string.h> 39 40#include "interface.h" 41#include "addrtoname.h" 42#include "extract.h" /* must come after interface.h */ --- 8 unchanged lines hidden (view full) --- 51 "", " FormErr", " ServFail", " NXDomain", 52 " NotImp", " Refused", " YXDomain", " YXRRSet", 53 " NXRRSet", " NotAuth", " NotZone", " Resp11", 54 " Resp12", " Resp13", " Resp14", " NoChange", 55}; 56 57/* skip over a domain name */ 58static const u_char * |
62ns_nskip(register const u_char *cp, register const u_char *bp) | 59ns_nskip(register const u_char *cp) |
63{ 64 register u_char i; 65 66 if (!TTEST2(*cp, 1)) 67 return (NULL); | 60{ 61 register u_char i; 62 63 if (!TTEST2(*cp, 1)) 64 return (NULL); |
68 if (((i = *cp++) & INDIR_MASK) == INDIR_MASK) 69 return (cp + 1); | 65 i = *cp++; |
70 while (i) { | 66 while (i) { |
67 if ((i & INDIR_MASK) == INDIR_MASK) 68 return (cp + 1); |
|
71 if ((i & INDIR_MASK) == EDNS0_MASK) { 72 int bitlen, bytelen; 73 74 if ((i & ~INDIR_MASK) != EDNS0_ELT_BITLABEL) 75 return(NULL); /* unknown ELT */ 76 if (!TTEST2(*cp, 1)) 77 return (NULL); 78 if ((bitlen = *cp++) == 0) --- 9 unchanged lines hidden (view full) --- 88 return (cp); 89} 90 91/* print a <domain-name> */ 92static const u_char * 93blabel_print(const u_char *cp) 94{ 95 int bitlen, slen, b; | 69 if ((i & INDIR_MASK) == EDNS0_MASK) { 70 int bitlen, bytelen; 71 72 if ((i & ~INDIR_MASK) != EDNS0_ELT_BITLABEL) 73 return(NULL); /* unknown ELT */ 74 if (!TTEST2(*cp, 1)) 75 return (NULL); 76 if ((bitlen = *cp++) == 0) --- 9 unchanged lines hidden (view full) --- 86 return (cp); 87} 88 89/* print a <domain-name> */ 90static const u_char * 91blabel_print(const u_char *cp) 92{ 93 int bitlen, slen, b; |
96 int truncated = 0; | |
97 const u_char *bitp, *lim; 98 char tc; 99 100 if (!TTEST2(*cp, 1)) 101 return(NULL); 102 if ((bitlen = *cp) == 0) 103 bitlen = 256; 104 slen = (bitlen + 3) / 4; | 94 const u_char *bitp, *lim; 95 char tc; 96 97 if (!TTEST2(*cp, 1)) 98 return(NULL); 99 if ((bitlen = *cp) == 0) 100 bitlen = 256; 101 slen = (bitlen + 3) / 4; |
105 if ((lim = cp + 1 + slen) > snapend) { 106 truncated = 1; 107 lim = snapend; 108 } | 102 lim = cp + 1 + slen; |
109 110 /* print the bit string as a hex string */ 111 printf("\\[x"); | 103 104 /* print the bit string as a hex string */ 105 printf("\\[x"); |
112 for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) | 106 for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) { 107 TCHECK(*bitp); |
113 printf("%02x", *bitp); | 108 printf("%02x", *bitp); |
114 if (bitp == lim) 115 printf("..."); 116 else if (b > 4) { | 109 } 110 if (b > 4) { 111 TCHECK(*bitp); |
117 tc = *bitp++; 118 printf("%02x", tc & (0xff << (8 - b))); 119 } else if (b > 0) { | 112 tc = *bitp++; 113 printf("%02x", tc & (0xff << (8 - b))); 114 } else if (b > 0) { |
115 TCHECK(*bitp); |
|
120 tc = *bitp++; 121 printf("%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b))); 122 } 123 printf("/%d]", bitlen); | 116 tc = *bitp++; 117 printf("%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b))); 118 } 119 printf("/%d]", bitlen); |
124 125 return(truncated ? NULL : lim); | 120 return lim; 121trunc: 122 printf(".../%d]", bitlen); 123 return NULL; |
126} 127 128static int 129labellen(const u_char *cp) 130{ 131 register u_int i; 132 133 if (!TTEST2(*cp, 1)) --- 18 unchanged lines hidden (view full) --- 152{ 153 register u_int i, l; 154 register const u_char *rp = NULL; 155 register int compress = 0; 156 int chars_processed; 157 int elt; 158 int data_size = snapend - bp; 159 | 124} 125 126static int 127labellen(const u_char *cp) 128{ 129 register u_int i; 130 131 if (!TTEST2(*cp, 1)) --- 18 unchanged lines hidden (view full) --- 150{ 151 register u_int i, l; 152 register const u_char *rp = NULL; 153 register int compress = 0; 154 int chars_processed; 155 int elt; 156 int data_size = snapend - bp; 157 |
160 if ((l = labellen(cp)) < 0) | 158 if ((l = labellen(cp)) == (u_int)-1) |
161 return(NULL); 162 if (!TTEST2(*cp, 1)) 163 return(NULL); 164 chars_processed = 1; 165 if (((i = *cp++) & INDIR_MASK) != INDIR_MASK) { 166 compress = 0; 167 rp = cp + l; 168 } 169 170 if (i != 0) 171 while (i && cp < snapend) { 172 if ((i & INDIR_MASK) == INDIR_MASK) { 173 if (!compress) { 174 rp = cp + 1; 175 compress = 1; 176 } 177 if (!TTEST2(*cp, 1)) 178 return(NULL); 179 cp = bp + (((i << 8) | *cp) & 0x3fff); | 159 return(NULL); 160 if (!TTEST2(*cp, 1)) 161 return(NULL); 162 chars_processed = 1; 163 if (((i = *cp++) & INDIR_MASK) != INDIR_MASK) { 164 compress = 0; 165 rp = cp + l; 166 } 167 168 if (i != 0) 169 while (i && cp < snapend) { 170 if ((i & INDIR_MASK) == INDIR_MASK) { 171 if (!compress) { 172 rp = cp + 1; 173 compress = 1; 174 } 175 if (!TTEST2(*cp, 1)) 176 return(NULL); 177 cp = bp + (((i << 8) | *cp) & 0x3fff); |
180 if ((l = labellen(cp)) < 0) | 178 if ((l = labellen(cp)) == (u_int)-1) |
181 return(NULL); 182 if (!TTEST2(*cp, 1)) 183 return(NULL); 184 i = *cp++; 185 chars_processed++; 186 187 /* 188 * If we've looked at every character in --- 22 unchanged lines hidden (view full) --- 211 } else { 212 if (fn_printn(cp, l, snapend)) 213 return(NULL); 214 } 215 216 cp += l; 217 chars_processed += l; 218 putchar('.'); | 179 return(NULL); 180 if (!TTEST2(*cp, 1)) 181 return(NULL); 182 i = *cp++; 183 chars_processed++; 184 185 /* 186 * If we've looked at every character in --- 22 unchanged lines hidden (view full) --- 209 } else { 210 if (fn_printn(cp, l, snapend)) 211 return(NULL); 212 } 213 214 cp += l; 215 chars_processed += l; 216 putchar('.'); |
219 if ((l = labellen(cp)) < 0) | 217 if ((l = labellen(cp)) == (u_int)-1) |
220 return(NULL); 221 if (!TTEST2(*cp, 1)) 222 return(NULL); 223 i = *cp++; 224 chars_processed++; 225 if (!compress) 226 rp += l + 1; 227 } 228 else 229 putchar('.'); 230 return (rp); 231} 232 233/* print a <character-string> */ 234static const u_char * | 218 return(NULL); 219 if (!TTEST2(*cp, 1)) 220 return(NULL); 221 i = *cp++; 222 chars_processed++; 223 if (!compress) 224 rp += l + 1; 225 } 226 else 227 putchar('.'); 228 return (rp); 229} 230 231/* print a <character-string> */ 232static const u_char * |
235ns_cprint(register const u_char *cp, register const u_char *bp) | 233ns_cprint(register const u_char *cp) |
236{ 237 register u_int i; 238 239 if (!TTEST2(*cp, 1)) 240 return (NULL); 241 i = *cp++; 242 if (fn_printn(cp, i, snapend)) 243 return (NULL); 244 return (cp + i); 245} 246 | 234{ 235 register u_int i; 236 237 if (!TTEST2(*cp, 1)) 238 return (NULL); 239 i = *cp++; 240 if (fn_printn(cp, i, snapend)) 241 return (NULL); 242 return (cp + i); 243} 244 |
245/* http://www.iana.org/assignments/dns-parameters */ |
|
247struct tok ns_type2str[] = { | 246struct tok ns_type2str[] = { |
248 { T_A, "A" }, 249 { T_NS, "NS" }, 250 { T_MD, "MD" }, 251 { T_MF, "MF" }, 252 { T_CNAME, "CNAME" }, 253 { T_SOA, "SOA" }, 254 { T_MB, "MB" }, 255 { T_MG, "MG" }, 256 { T_MR, "MR" }, 257 { T_NULL, "NULL" }, 258 { T_WKS, "WKS" }, 259 { T_PTR, "PTR" }, 260 { T_HINFO, "HINFO" }, 261 { T_MINFO, "MINFO" }, 262 { T_MX, "MX" }, 263 { T_TXT, "TXT" }, 264 { T_RP, "RP" }, 265 { T_AFSDB, "AFSDB" }, 266 { T_X25, "X25" }, 267 { T_ISDN, "ISDN" }, 268 { T_RT, "RT" }, 269 { T_NSAP, "NSAP" }, | 247 { T_A, "A" }, /* RFC 1035 */ 248 { T_NS, "NS" }, /* RFC 1035 */ 249 { T_MD, "MD" }, /* RFC 1035 */ 250 { T_MF, "MF" }, /* RFC 1035 */ 251 { T_CNAME, "CNAME" }, /* RFC 1035 */ 252 { T_SOA, "SOA" }, /* RFC 1035 */ 253 { T_MB, "MB" }, /* RFC 1035 */ 254 { T_MG, "MG" }, /* RFC 1035 */ 255 { T_MR, "MR" }, /* RFC 1035 */ 256 { T_NULL, "NULL" }, /* RFC 1035 */ 257 { T_WKS, "WKS" }, /* RFC 1035 */ 258 { T_PTR, "PTR" }, /* RFC 1035 */ 259 { T_HINFO, "HINFO" }, /* RFC 1035 */ 260 { T_MINFO, "MINFO" }, /* RFC 1035 */ 261 { T_MX, "MX" }, /* RFC 1035 */ 262 { T_TXT, "TXT" }, /* RFC 1035 */ 263 { T_RP, "RP" }, /* RFC 1183 */ 264 { T_AFSDB, "AFSDB" }, /* RFC 1183 */ 265 { T_X25, "X25" }, /* RFC 1183 */ 266 { T_ISDN, "ISDN" }, /* RFC 1183 */ 267 { T_RT, "RT" }, /* RFC 1183 */ 268 { T_NSAP, "NSAP" }, /* RFC 1706 */ |
270 { T_NSAP_PTR, "NSAP_PTR" }, | 269 { T_NSAP_PTR, "NSAP_PTR" }, |
271 { T_SIG, "SIG" }, 272 { T_KEY, "KEY" }, 273 { T_PX, "PX" }, 274 { T_GPOS, "GPOS" }, 275 { T_AAAA, "AAAA" }, 276 { T_LOC, "LOC" }, 277 { T_NXT, "NXT" }, 278 { T_EID, "EID" }, 279 { T_NIMLOC, "NIMLOC" }, 280 { T_SRV, "SRV" }, 281 { T_ATMA, "ATMA" }, 282 { T_NAPTR, "NAPTR" }, 283 { T_A6, "A6" }, 284 { T_DNAME, "DNAME" }, 285 { T_OPT, "OPT" }, | 270 { T_SIG, "SIG" }, /* RFC 2535 */ 271 { T_KEY, "KEY" }, /* RFC 2535 */ 272 { T_PX, "PX" }, /* RFC 2163 */ 273 { T_GPOS, "GPOS" }, /* RFC 1712 */ 274 { T_AAAA, "AAAA" }, /* RFC 1886 */ 275 { T_LOC, "LOC" }, /* RFC 1876 */ 276 { T_NXT, "NXT" }, /* RFC 2535 */ 277 { T_EID, "EID" }, /* Nimrod */ 278 { T_NIMLOC, "NIMLOC" }, /* Nimrod */ 279 { T_SRV, "SRV" }, /* RFC 2782 */ 280 { T_ATMA, "ATMA" }, /* ATM Forum */ 281 { T_NAPTR, "NAPTR" }, /* RFC 2168, RFC 2915 */ 282 { T_A6, "A6" }, /* RFC 2874 */ 283 { T_DNAME, "DNAME" }, /* RFC 2672 */ 284 { T_OPT, "OPT" }, /* RFC 2671 */ |
286 { T_UINFO, "UINFO" }, 287 { T_UID, "UID" }, 288 { T_GID, "GID" }, 289 { T_UNSPEC, "UNSPEC" }, 290 { T_UNSPECA, "UNSPECA" }, | 285 { T_UINFO, "UINFO" }, 286 { T_UID, "UID" }, 287 { T_GID, "GID" }, 288 { T_UNSPEC, "UNSPEC" }, 289 { T_UNSPECA, "UNSPECA" }, |
291 { T_TKEY, "TKEY" }, 292 { T_TSIG, "TSIG" }, 293 { T_IXFR, "IXFR" }, 294 { T_AXFR, "AXFR" }, 295 { T_MAILB, "MAILB" }, 296 { T_MAILA, "MAILA" }, | 290 { T_TKEY, "TKEY" }, /* RFC 2930 */ 291 { T_TSIG, "TSIG" }, /* RFC 2845 */ 292 { T_IXFR, "IXFR" }, /* RFC 1995 */ 293 { T_AXFR, "AXFR" }, /* RFC 1035 */ 294 { T_MAILB, "MAILB" }, /* RFC 1035 */ 295 { T_MAILA, "MAILA" }, /* RFC 1035 */ |
297 { T_ANY, "ANY" }, 298 { 0, NULL } 299}; 300 301struct tok ns_class2str[] = { 302 { C_IN, "IN" }, /* Not used */ 303 { C_CHAOS, "CHAOS" }, 304 { C_HS, "HS" }, 305 { C_ANY, "ANY" }, 306 { 0, NULL } 307}; 308 309/* print a query */ 310static const u_char * | 296 { T_ANY, "ANY" }, 297 { 0, NULL } 298}; 299 300struct tok ns_class2str[] = { 301 { C_IN, "IN" }, /* Not used */ 302 { C_CHAOS, "CHAOS" }, 303 { C_HS, "HS" }, 304 { C_ANY, "ANY" }, 305 { 0, NULL } 306}; 307 308/* print a query */ 309static const u_char * |
311ns_qprint(register const u_char *cp, register const u_char *bp) | 310ns_qprint(register const u_char *cp, register const u_char *bp, int is_mdns) |
312{ 313 register const u_char *np = cp; 314 register u_int i; 315 | 311{ 312 register const u_char *np = cp; 313 register u_int i; 314 |
316 cp = ns_nskip(cp, bp); | 315 cp = ns_nskip(cp); |
317 318 if (cp == NULL || !TTEST2(*cp, 4)) 319 return(NULL); 320 321 /* print the qtype and qclass (if it's not IN) */ | 316 317 if (cp == NULL || !TTEST2(*cp, 4)) 318 return(NULL); 319 320 /* print the qtype and qclass (if it's not IN) */ |
322 i = *cp++ << 8; 323 i |= *cp++; | 321 i = EXTRACT_16BITS(cp); 322 cp += 2; |
324 printf(" %s", tok2str(ns_type2str, "Type%d", i)); | 323 printf(" %s", tok2str(ns_type2str, "Type%d", i)); |
325 i = *cp++ << 8; 326 i |= *cp++; 327 if (i != C_IN) | 324 i = EXTRACT_16BITS(cp); 325 cp += 2; 326 if (is_mdns && i == (C_IN|C_CACHE_FLUSH)) 327 printf(" (Cache flush)"); 328 else if (i != C_IN) |
328 printf(" %s", tok2str(ns_class2str, "(Class %d)", i)); 329 330 fputs("? ", stdout); 331 cp = ns_nprint(np, bp); 332 return(cp ? cp + 4 : NULL); 333} 334 335/* print a reply */ 336static const u_char * | 329 printf(" %s", tok2str(ns_class2str, "(Class %d)", i)); 330 331 fputs("? ", stdout); 332 cp = ns_nprint(np, bp); 333 return(cp ? cp + 4 : NULL); 334} 335 336/* print a reply */ 337static const u_char * |
337ns_rprint(register const u_char *cp, register const u_char *bp) | 338ns_rprint(register const u_char *cp, register const u_char *bp, int is_mdns) |
338{ 339 register u_int class; 340 register u_short typ, len; 341 register const u_char *rp; 342 343 if (vflag) { 344 putchar(' '); 345 if ((cp = ns_nprint(cp, bp)) == NULL) 346 return NULL; 347 } else | 339{ 340 register u_int class; 341 register u_short typ, len; 342 register const u_char *rp; 343 344 if (vflag) { 345 putchar(' '); 346 if ((cp = ns_nprint(cp, bp)) == NULL) 347 return NULL; 348 } else |
348 cp = ns_nskip(cp, bp); | 349 cp = ns_nskip(cp); |
349 350 if (cp == NULL || !TTEST2(*cp, 10)) 351 return (snapend); 352 353 /* print the type/qtype and class (if it's not IN) */ | 350 351 if (cp == NULL || !TTEST2(*cp, 10)) 352 return (snapend); 353 354 /* print the type/qtype and class (if it's not IN) */ |
354 typ = *cp++ << 8; 355 typ |= *cp++; 356 class = *cp++ << 8; 357 class |= *cp++; 358 if (class != C_IN && typ != T_OPT) | 355 typ = EXTRACT_16BITS(cp); 356 cp += 2; 357 class = EXTRACT_16BITS(cp); 358 cp += 2; 359 if (is_mdns && class == (C_IN|C_CACHE_FLUSH)) 360 printf(" (Cache flush)"); 361 else if (class != C_IN && typ != T_OPT) |
359 printf(" %s", tok2str(ns_class2str, "(Class %d)", class)); 360 361 /* ignore ttl */ 362 cp += 4; 363 | 362 printf(" %s", tok2str(ns_class2str, "(Class %d)", class)); 363 364 /* ignore ttl */ 365 cp += 4; 366 |
364 len = *cp++ << 8; 365 len |= *cp++; | 367 len = EXTRACT_16BITS(cp); 368 cp += 2; |
366 367 rp = cp + len; 368 369 printf(" %s", tok2str(ns_type2str, "Type%d", typ)); 370 if (rp > snapend) 371 return(NULL); 372 373 switch (typ) { --- 41 unchanged lines hidden (view full) --- 415 if (!TTEST2(*cp, 2)) 416 return(NULL); 417 if (ns_nprint(cp + 2, bp) == NULL) 418 return(NULL); 419 printf(" %d", EXTRACT_16BITS(cp)); 420 break; 421 422 case T_TXT: | 369 370 rp = cp + len; 371 372 printf(" %s", tok2str(ns_type2str, "Type%d", typ)); 373 if (rp > snapend) 374 return(NULL); 375 376 switch (typ) { --- 41 unchanged lines hidden (view full) --- 418 if (!TTEST2(*cp, 2)) 419 return(NULL); 420 if (ns_nprint(cp + 2, bp) == NULL) 421 return(NULL); 422 printf(" %d", EXTRACT_16BITS(cp)); 423 break; 424 425 case T_TXT: |
426 while (cp < rp) { 427 printf(" \""); 428 cp = ns_cprint(cp); 429 if (cp == NULL) 430 return(NULL); 431 putchar('"'); 432 } 433 break; 434 435 case T_SRV: |
|
423 putchar(' '); | 436 putchar(' '); |
424 (void)ns_cprint(cp, bp); | 437 if (!TTEST2(*cp, 6)) 438 return(NULL); 439 if (ns_nprint(cp + 6, bp) == NULL) 440 return(NULL); 441 printf(":%d %d %d", EXTRACT_16BITS(cp + 4), 442 EXTRACT_16BITS(cp), EXTRACT_16BITS(cp + 2)); |
425 break; 426 427#ifdef INET6 428 case T_AAAA: 429 if (!TTEST2(*cp, sizeof(struct in6_addr))) 430 return(NULL); 431 printf(" %s", ip6addr_string(cp)); 432 break; --- 68 unchanged lines hidden (view full) --- 501 printf(" otherlen=%u", EXTRACT_16BITS(cp)); 502 cp += 2; 503 } 504 } 505 return (rp); /* XXX This isn't always right */ 506} 507 508void | 443 break; 444 445#ifdef INET6 446 case T_AAAA: 447 if (!TTEST2(*cp, sizeof(struct in6_addr))) 448 return(NULL); 449 printf(" %s", ip6addr_string(cp)); 450 break; --- 68 unchanged lines hidden (view full) --- 519 printf(" otherlen=%u", EXTRACT_16BITS(cp)); 520 cp += 2; 521 } 522 } 523 return (rp); /* XXX This isn't always right */ 524} 525 526void |
509ns_print(register const u_char *bp, u_int length) | 527ns_print(register const u_char *bp, u_int length, int is_mdns) |
510{ 511 register const HEADER *np; 512 register int qdcount, ancount, nscount, arcount; 513 register const u_char *cp; | 528{ 529 register const HEADER *np; 530 register int qdcount, ancount, nscount, arcount; 531 register const u_char *cp; |
532 u_int16_t b2; |
|
514 515 np = (const HEADER *)bp; 516 TCHECK(*np); 517 /* get the byte-order right */ | 533 534 np = (const HEADER *)bp; 535 TCHECK(*np); 536 /* get the byte-order right */ |
518 qdcount = ntohs(np->qdcount); 519 ancount = ntohs(np->ancount); 520 nscount = ntohs(np->nscount); 521 arcount = ntohs(np->arcount); | 537 qdcount = EXTRACT_16BITS(&np->qdcount); 538 ancount = EXTRACT_16BITS(&np->ancount); 539 nscount = EXTRACT_16BITS(&np->nscount); 540 arcount = EXTRACT_16BITS(&np->arcount); |
522 523 if (DNS_QR(np)) { 524 /* this is a response */ 525 printf(" %d%s%s%s%s%s%s", | 541 542 if (DNS_QR(np)) { 543 /* this is a response */ 544 printf(" %d%s%s%s%s%s%s", |
526 ntohs(np->id), | 545 EXTRACT_16BITS(&np->id), |
527 ns_ops[DNS_OPCODE(np)], 528 ns_resp[DNS_RCODE(np)], 529 DNS_AA(np)? "*" : "", 530 DNS_RA(np)? "" : "-", 531 DNS_TC(np)? "|" : "", | 546 ns_ops[DNS_OPCODE(np)], 547 ns_resp[DNS_RCODE(np)], 548 DNS_AA(np)? "*" : "", 549 DNS_RA(np)? "" : "-", 550 DNS_TC(np)? "|" : "", |
532 DNS_CD(np)? "%" : ""); | 551 DNS_AD(np)? "$" : ""); |
533 534 if (qdcount != 1) 535 printf(" [%dq]", qdcount); 536 /* Print QUESTION section on -vv */ 537 cp = (const u_char *)(np + 1); 538 while (qdcount--) { | 552 553 if (qdcount != 1) 554 printf(" [%dq]", qdcount); 555 /* Print QUESTION section on -vv */ 556 cp = (const u_char *)(np + 1); 557 while (qdcount--) { |
539 if (qdcount < ntohs(np->qdcount) - 1) | 558 if (qdcount < EXTRACT_16BITS(&np->qdcount) - 1) |
540 putchar(','); 541 if (vflag > 1) { 542 fputs(" q:", stdout); | 559 putchar(','); 560 if (vflag > 1) { 561 fputs(" q:", stdout); |
543 if ((cp = ns_qprint(cp, bp)) == NULL) | 562 if ((cp = ns_qprint(cp, bp, is_mdns)) == NULL) |
544 goto trunc; 545 } else { | 563 goto trunc; 564 } else { |
546 if ((cp = ns_nskip(cp, bp)) == NULL) | 565 if ((cp = ns_nskip(cp)) == NULL) |
547 goto trunc; 548 cp += 4; /* skip QTYPE and QCLASS */ 549 } 550 } 551 printf(" %d/%d/%d", ancount, nscount, arcount); 552 if (ancount--) { | 566 goto trunc; 567 cp += 4; /* skip QTYPE and QCLASS */ 568 } 569 } 570 printf(" %d/%d/%d", ancount, nscount, arcount); 571 if (ancount--) { |
553 if ((cp = ns_rprint(cp, bp)) == NULL) | 572 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) |
554 goto trunc; 555 while (cp < snapend && ancount--) { 556 putchar(','); | 573 goto trunc; 574 while (cp < snapend && ancount--) { 575 putchar(','); |
557 if ((cp = ns_rprint(cp, bp)) == NULL) | 576 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) |
558 goto trunc; 559 } 560 } 561 if (ancount > 0) 562 goto trunc; 563 /* Print NS and AR sections on -vv */ 564 if (vflag > 1) { 565 if (cp < snapend && nscount--) { 566 fputs(" ns:", stdout); | 577 goto trunc; 578 } 579 } 580 if (ancount > 0) 581 goto trunc; 582 /* Print NS and AR sections on -vv */ 583 if (vflag > 1) { 584 if (cp < snapend && nscount--) { 585 fputs(" ns:", stdout); |
567 if ((cp = ns_rprint(cp, bp)) == NULL) | 586 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) |
568 goto trunc; 569 while (cp < snapend && nscount--) { 570 putchar(','); | 587 goto trunc; 588 while (cp < snapend && nscount--) { 589 putchar(','); |
571 if ((cp = ns_rprint(cp, bp)) == NULL) | 590 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) |
572 goto trunc; 573 } 574 } 575 if (nscount > 0) 576 goto trunc; 577 if (cp < snapend && arcount--) { 578 fputs(" ar:", stdout); | 591 goto trunc; 592 } 593 } 594 if (nscount > 0) 595 goto trunc; 596 if (cp < snapend && arcount--) { 597 fputs(" ar:", stdout); |
579 if ((cp = ns_rprint(cp, bp)) == NULL) | 598 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) |
580 goto trunc; 581 while (cp < snapend && arcount--) { 582 putchar(','); | 599 goto trunc; 600 while (cp < snapend && arcount--) { 601 putchar(','); |
583 if ((cp = ns_rprint(cp, bp)) == NULL) | 602 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) |
584 goto trunc; 585 } 586 } 587 if (arcount > 0) 588 goto trunc; 589 } 590 } 591 else { 592 /* this is a request */ | 603 goto trunc; 604 } 605 } 606 if (arcount > 0) 607 goto trunc; 608 } 609 } 610 else { 611 /* this is a request */ |
593 printf(" %d%s%s%s", ntohs(np->id), ns_ops[DNS_OPCODE(np)], | 612 printf(" %d%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], |
594 DNS_RD(np) ? "+" : "", | 613 DNS_RD(np) ? "+" : "", |
595 DNS_AD(np) ? "$" : ""); | 614 DNS_CD(np) ? "%" : ""); |
596 597 /* any weirdness? */ | 615 616 /* any weirdness? */ |
598 if (*(((u_short *)np)+1) & htons(0x6cf)) 599 printf(" [b2&3=0x%x]", ntohs(*(((u_short *)np)+1))); | 617 b2 = EXTRACT_16BITS(((u_short *)np)+1); 618 if (b2 & 0x6cf) 619 printf(" [b2&3=0x%x]", b2); |
600 601 if (DNS_OPCODE(np) == IQUERY) { 602 if (qdcount) 603 printf(" [%dq]", qdcount); 604 if (ancount != 1) 605 printf(" [%da]", ancount); 606 } 607 else { --- 4 unchanged lines hidden (view full) --- 612 } 613 if (nscount) 614 printf(" [%dn]", nscount); 615 if (arcount) 616 printf(" [%dau]", arcount); 617 618 cp = (const u_char *)(np + 1); 619 if (qdcount--) { | 620 621 if (DNS_OPCODE(np) == IQUERY) { 622 if (qdcount) 623 printf(" [%dq]", qdcount); 624 if (ancount != 1) 625 printf(" [%da]", ancount); 626 } 627 else { --- 4 unchanged lines hidden (view full) --- 632 } 633 if (nscount) 634 printf(" [%dn]", nscount); 635 if (arcount) 636 printf(" [%dau]", arcount); 637 638 cp = (const u_char *)(np + 1); 639 if (qdcount--) { |
620 cp = ns_qprint(cp, (const u_char *)np); | 640 cp = ns_qprint(cp, (const u_char *)np, is_mdns); |
621 if (!cp) 622 goto trunc; 623 while (cp < snapend && qdcount--) { 624 cp = ns_qprint((const u_char *)cp, | 641 if (!cp) 642 goto trunc; 643 while (cp < snapend && qdcount--) { 644 cp = ns_qprint((const u_char *)cp, |
625 (const u_char *)np); | 645 (const u_char *)np, 646 is_mdns); |
626 if (!cp) 627 goto trunc; 628 } 629 } 630 if (qdcount > 0) 631 goto trunc; 632 633 /* Print remaining sections on -vv */ 634 if (vflag > 1) { 635 if (ancount--) { | 647 if (!cp) 648 goto trunc; 649 } 650 } 651 if (qdcount > 0) 652 goto trunc; 653 654 /* Print remaining sections on -vv */ 655 if (vflag > 1) { 656 if (ancount--) { |
636 if ((cp = ns_rprint(cp, bp)) == NULL) | 657 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) |
637 goto trunc; 638 while (cp < snapend && ancount--) { 639 putchar(','); | 658 goto trunc; 659 while (cp < snapend && ancount--) { 660 putchar(','); |
640 if ((cp = ns_rprint(cp, bp)) == NULL) | 661 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) |
641 goto trunc; 642 } 643 } 644 if (ancount > 0) 645 goto trunc; 646 if (cp < snapend && nscount--) { 647 fputs(" ns:", stdout); | 662 goto trunc; 663 } 664 } 665 if (ancount > 0) 666 goto trunc; 667 if (cp < snapend && nscount--) { 668 fputs(" ns:", stdout); |
648 if ((cp = ns_rprint(cp, bp)) == NULL) | 669 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) |
649 goto trunc; 650 while (nscount-- && cp < snapend) { 651 putchar(','); | 670 goto trunc; 671 while (nscount-- && cp < snapend) { 672 putchar(','); |
652 if ((cp = ns_rprint(cp, bp)) == NULL) | 673 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) |
653 goto trunc; 654 } 655 } 656 if (nscount > 0) 657 goto trunc; 658 if (cp < snapend && arcount--) { 659 fputs(" ar:", stdout); | 674 goto trunc; 675 } 676 } 677 if (nscount > 0) 678 goto trunc; 679 if (cp < snapend && arcount--) { 680 fputs(" ar:", stdout); |
660 if ((cp = ns_rprint(cp, bp)) == NULL) | 681 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) |
661 goto trunc; 662 while (cp < snapend && arcount--) { 663 putchar(','); | 682 goto trunc; 683 while (cp < snapend && arcount--) { 684 putchar(','); |
664 if ((cp = ns_rprint(cp, bp)) == NULL) | 685 if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) |
665 goto trunc; 666 } 667 } 668 if (arcount > 0) 669 goto trunc; 670 } 671 } 672 printf(" (%d)", length); 673 return; 674 675 trunc: 676 printf("[|domain]"); 677 return; 678} | 686 goto trunc; 687 } 688 } 689 if (arcount > 0) 690 goto trunc; 691 } 692 } 693 printf(" (%d)", length); 694 return; 695 696 trunc: 697 printf("[|domain]"); 698 return; 699} |