print-domain.c (80234) | print-domain.c (98527) |
---|---|
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 80234 2001-07-23 23:15:44Z fenner $ | 21 * $FreeBSD: head/contrib/tcpdump/print-domain.c 98527 2002-06-21 00:49:02Z fenner $ |
22 */ 23 24#ifndef lint 25static const char rcsid[] = | 22 */ 23 24#ifndef lint 25static const char rcsid[] = |
26 "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.64.2.1 2001/02/21 09:01:20 guy Exp $ (LBL)"; | 26 "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.78 2001/10/19 09:00:48 guy Exp $ (LBL)"; |
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> 35 36#include <netinet/in.h> 37 | 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> 35 36#include <netinet/in.h> 37 |
38#ifdef NOERROR 39#undef NOERROR /* Solaris sucks */ 40#endif 41#ifdef NOERROR 42#undef T_UNSPEC /* SINIX does too */ 43#endif | |
44#include "nameser.h" 45 46#include <stdio.h> 47#include <string.h> 48 49#include "interface.h" 50#include "addrtoname.h" 51#include "extract.h" /* must come after interface.h */ 52 | 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 */ 46 |
53/* Compatibility */ 54#ifndef T_TXT 55#define T_TXT 16 /* text strings */ 56#endif 57#ifndef T_RP 58#define T_RP 17 /* responsible person */ 59#endif 60#ifndef T_AFSDB 61#define T_AFSDB 18 /* AFS cell database */ 62#endif 63#ifndef T_X25 64#define T_X25 19 /* X_25 calling address */ 65#endif 66#ifndef T_ISDN 67#define T_ISDN 20 /* ISDN calling address */ 68#endif 69#ifndef T_RT 70#define T_RT 21 /* router */ 71#endif 72#ifndef T_NSAP 73#define T_NSAP 22 /* NSAP address */ 74#endif 75#ifndef T_NSAP_PTR 76#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */ 77#endif 78#ifndef T_SIG 79#define T_SIG 24 /* security signature */ 80#endif 81#ifndef T_KEY 82#define T_KEY 25 /* security key */ 83#endif 84#ifndef T_PX 85#define T_PX 26 /* X.400 mail mapping */ 86#endif 87#ifndef T_GPOS 88#define T_GPOS 27 /* geographical position (withdrawn) */ 89#endif 90#ifndef T_AAAA 91#define T_AAAA 28 /* IP6 Address */ 92#endif 93#ifndef T_LOC 94#define T_LOC 29 /* Location Information */ 95#endif 96#ifndef T_NXT 97#define T_NXT 30 /* Next Valid Name in Zone */ 98#endif 99#ifndef T_EID 100#define T_EID 31 /* Endpoint identifier */ 101#endif 102#ifndef T_NIMLOC 103#define T_NIMLOC 32 /* Nimrod locator */ 104#endif 105#ifndef T_SRV 106#define T_SRV 33 /* Server selection */ 107#endif 108#ifndef T_ATMA 109#define T_ATMA 34 /* ATM Address */ 110#endif 111#ifndef T_NAPTR 112#define T_NAPTR 35 /* Naming Authority PoinTeR */ 113#endif 114#ifndef T_A6 115#define T_A6 38 /* IP6 address */ 116#endif 117#ifndef T_DNAME 118#define T_DNAME 39 /* non-terminal redirection */ 119#endif 120 121#ifndef T_OPT 122#define T_OPT 41 /* EDNS0 option (meta-RR) */ 123#endif 124 125#ifndef T_UNSPEC 126#define T_UNSPEC 103 /* Unspecified format (binary data) */ 127#endif 128#ifndef T_UNSPECA 129#define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */ 130#endif 131 132#ifndef C_CHAOS 133#define C_CHAOS 3 /* for chaos net (MIT) */ 134#endif 135#ifndef C_HS 136#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */ 137#endif 138 139static char *ns_ops[] = { 140 "", " inv_q", " stat", " op3", " notify", " op5", " op6", " op7", | 47static const char *ns_ops[] = { 48 "", " inv_q", " stat", " op3", " notify", " update", " op6", " op7", |
141 " op8", " updataA", " updateD", " updateDA", 142 " updateM", " updateMA", " zoneInit", " zoneRef", 143}; 144 | 49 " op8", " updataA", " updateD", " updateDA", 50 " updateM", " updateMA", " zoneInit", " zoneRef", 51}; 52 |
145static char *ns_resp[] = { | 53static const char *ns_resp[] = { |
146 "", " FormErr", " ServFail", " NXDomain", | 54 "", " FormErr", " ServFail", " NXDomain", |
147 " NotImp", " Refused", " Resp6", " Resp7", 148 " Resp8", " Resp9", " Resp10", " Resp11", | 55 " NotImp", " Refused", " YXDomain", " YXRRSet", 56 " NXRRSet", " NotAuth", " NotZone", " Resp11", |
149 " Resp12", " Resp13", " Resp14", " NoChange", 150}; 151 152/* skip over a domain name */ 153static const u_char * 154ns_nskip(register const u_char *cp, register const u_char *bp) 155{ 156 register u_char i; 157 | 57 " Resp12", " Resp13", " Resp14", " NoChange", 58}; 59 60/* skip over a domain name */ 61static const u_char * 62ns_nskip(register const u_char *cp, register const u_char *bp) 63{ 64 register u_char i; 65 |
66 if (!TTEST2(*cp, 1)) 67 return (NULL); |
|
158 if (((i = *cp++) & INDIR_MASK) == INDIR_MASK) 159 return (cp + 1); | 68 if (((i = *cp++) & INDIR_MASK) == INDIR_MASK) 69 return (cp + 1); |
160 if (cp >= snapend) 161 return(NULL); 162 while (i && cp < snapend) { | 70 while (i) { |
163 if ((i & INDIR_MASK) == EDNS0_MASK) { 164 int bitlen, bytelen; 165 166 if ((i & ~INDIR_MASK) != EDNS0_ELT_BITLABEL) 167 return(NULL); /* unknown ELT */ | 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); |
|
168 if ((bitlen = *cp++) == 0) 169 bitlen = 256; 170 bytelen = (bitlen + 7) / 8; 171 cp += bytelen; 172 } else 173 cp += i; | 78 if ((bitlen = *cp++) == 0) 79 bitlen = 256; 80 bytelen = (bitlen + 7) / 8; 81 cp += bytelen; 82 } else 83 cp += i; |
174 if (cp >= snapend) 175 return(NULL); | 84 if (!TTEST2(*cp, 1)) 85 return (NULL); |
176 i = *cp++; 177 } 178 return (cp); 179} 180 181/* print a <domain-name> */ 182static const u_char * 183blabel_print(const u_char *cp) 184{ 185 int bitlen, slen, b; 186 int truncated = 0; 187 const u_char *bitp, *lim; 188 char tc; 189 | 86 i = *cp++; 87 } 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; 96 int truncated = 0; 97 const u_char *bitp, *lim; 98 char tc; 99 |
190 if (cp >= snapend) | 100 if (!TTEST2(*cp, 1)) |
191 return(NULL); 192 if ((bitlen = *cp) == 0) 193 bitlen = 256; 194 slen = (bitlen + 3) / 4; 195 if ((lim = cp + 1 + slen) > snapend) { 196 truncated = 1; 197 lim = snapend; 198 } --- 16 unchanged lines hidden (view full) --- 215 return(truncated ? NULL : lim); 216} 217 218static int 219labellen(const u_char *cp) 220{ 221 register u_int i; 222 | 101 return(NULL); 102 if ((bitlen = *cp) == 0) 103 bitlen = 256; 104 slen = (bitlen + 3) / 4; 105 if ((lim = cp + 1 + slen) > snapend) { 106 truncated = 1; 107 lim = snapend; 108 } --- 16 unchanged lines hidden (view full) --- 125 return(truncated ? NULL : lim); 126} 127 128static int 129labellen(const u_char *cp) 130{ 131 register u_int i; 132 |
223 if (cp >= snapend) | 133 if (!TTEST2(*cp, 1)) |
224 return(-1); 225 i = *cp; 226 if ((i & INDIR_MASK) == EDNS0_MASK) { 227 int bitlen, elt; 228 229 if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL) 230 return(-1); | 134 return(-1); 135 i = *cp; 136 if ((i & INDIR_MASK) == EDNS0_MASK) { 137 int bitlen, elt; 138 139 if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL) 140 return(-1); |
231 if (cp + 1 >= snapend) | 141 if (!TTEST2(*(cp + 1), 1)) |
232 return(-1); 233 if ((bitlen = *(cp + 1)) == 0) 234 bitlen = 256; 235 return(((bitlen + 7) / 8) + 1); 236 } else 237 return(i); 238} 239 --- 4 unchanged lines hidden (view full) --- 244 register const u_char *rp = NULL; 245 register int compress = 0; 246 int chars_processed; 247 int elt; 248 int data_size = snapend - bp; 249 250 if ((l = labellen(cp)) < 0) 251 return(NULL); | 142 return(-1); 143 if ((bitlen = *(cp + 1)) == 0) 144 bitlen = 256; 145 return(((bitlen + 7) / 8) + 1); 146 } else 147 return(i); 148} 149 --- 4 unchanged lines hidden (view full) --- 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 160 if ((l = labellen(cp)) < 0) 161 return(NULL); |
252 if (cp >= snapend) | 162 if (!TTEST2(*cp, 1)) |
253 return(NULL); 254 chars_processed = 1; 255 if (((i = *cp++) & INDIR_MASK) != INDIR_MASK) { 256 compress = 0; 257 rp = cp + l; 258 } 259 260 if (i != 0) 261 while (i && cp < snapend) { 262 if ((i & INDIR_MASK) == INDIR_MASK) { 263 if (!compress) { 264 rp = cp + 1; 265 compress = 1; 266 } | 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 } |
267 cp = bp + (((i << 8) | *cp) & 0x3fff); 268 if (cp >= snapend) | 177 if (!TTEST2(*cp, 1)) |
269 return(NULL); | 178 return(NULL); |
179 cp = bp + (((i << 8) | *cp) & 0x3fff); |
|
270 if ((l = labellen(cp)) < 0) 271 return(NULL); | 180 if ((l = labellen(cp)) < 0) 181 return(NULL); |
182 if (!TTEST2(*cp, 1)) 183 return(NULL); |
|
272 i = *cp++; 273 chars_processed++; 274 275 /* 276 * If we've looked at every character in 277 * the message, this pointer will make 278 * us look at some character again, 279 * which means we're looping. 280 */ 281 if (chars_processed >= data_size) { 282 printf("<LOOP>"); 283 return (NULL); 284 } 285 continue; 286 } 287 if ((i & INDIR_MASK) == EDNS0_MASK) { 288 elt = (i & ~INDIR_MASK); 289 switch(elt) { 290 case EDNS0_ELT_BITLABEL: | 184 i = *cp++; 185 chars_processed++; 186 187 /* 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. 192 */ 193 if (chars_processed >= data_size) { 194 printf("<LOOP>"); 195 return (NULL); 196 } 197 continue; 198 } 199 if ((i & INDIR_MASK) == EDNS0_MASK) { 200 elt = (i & ~INDIR_MASK); 201 switch(elt) { 202 case EDNS0_ELT_BITLABEL: |
291 blabel_print(cp); | 203 if (blabel_print(cp) == NULL) 204 return (NULL); |
292 break; 293 default: 294 /* unknown ELT */ 295 printf("<ELT %d>", elt); 296 return(NULL); 297 } 298 } else { 299 if (fn_printn(cp, l, snapend)) | 205 break; 206 default: 207 /* unknown ELT */ 208 printf("<ELT %d>", elt); 209 return(NULL); 210 } 211 } else { 212 if (fn_printn(cp, l, snapend)) |
300 break; | 213 return(NULL); |
301 } 302 303 cp += l; 304 chars_processed += l; 305 putchar('.'); | 214 } 215 216 cp += l; 217 chars_processed += l; 218 putchar('.'); |
306 if (cp >= snapend || (l = labellen(cp)) < 0) | 219 if ((l = labellen(cp)) < 0) |
307 return(NULL); | 220 return(NULL); |
221 if (!TTEST2(*cp, 1)) 222 return(NULL); |
|
308 i = *cp++; 309 chars_processed++; 310 if (!compress) 311 rp += l + 1; 312 } 313 else 314 putchar('.'); 315 return (rp); 316} 317 318/* print a <character-string> */ 319static const u_char * 320ns_cprint(register const u_char *cp, register const u_char *bp) 321{ 322 register u_int i; 323 | 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 * 235ns_cprint(register const u_char *cp, register const u_char *bp) 236{ 237 register u_int i; 238 |
324 if (cp >= snapend) 325 return NULL; | 239 if (!TTEST2(*cp, 1)) 240 return (NULL); |
326 i = *cp++; | 241 i = *cp++; |
327 (void)fn_printn(cp, i, snapend); | 242 if (fn_printn(cp, i, snapend)) 243 return (NULL); |
328 return (cp + i); 329} 330 | 244 return (cp + i); 245} 246 |
331static struct tok type2str[] = { | 247struct tok ns_type2str[] = { |
332 { T_A, "A" }, 333 { T_NS, "NS" }, 334 { T_MD, "MD" }, 335 { T_MF, "MF" }, 336 { T_CNAME, "CNAME" }, 337 { T_SOA, "SOA" }, 338 { T_MB, "MB" }, 339 { T_MG, "MG" }, --- 12 unchanged lines hidden (view full) --- 352 { T_RT, "RT" }, 353 { T_NSAP, "NSAP" }, 354 { T_NSAP_PTR, "NSAP_PTR" }, 355 { T_SIG, "SIG" }, 356 { T_KEY, "KEY" }, 357 { T_PX, "PX" }, 358 { T_GPOS, "GPOS" }, 359 { T_AAAA, "AAAA" }, | 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" }, --- 12 unchanged lines hidden (view full) --- 268 { T_RT, "RT" }, 269 { T_NSAP, "NSAP" }, 270 { 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" }, |
360 { T_LOC, "LOC " }, 361 { T_NXT, "NXT " }, 362 { T_EID, "EID " }, 363 { T_NIMLOC, "NIMLOC " }, 364 { T_SRV, "SRV " }, 365 { T_ATMA, "ATMA " }, 366 { T_NAPTR, "NAPTR " }, 367 { T_A6, "A6 " }, 368 { T_DNAME, "DNAME " }, 369 { T_OPT, "OPT " }, | 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" }, |
370 { T_UINFO, "UINFO" }, 371 { T_UID, "UID" }, 372 { T_GID, "GID" }, 373 { T_UNSPEC, "UNSPEC" }, 374 { T_UNSPECA, "UNSPECA" }, | 286 { T_UINFO, "UINFO" }, 287 { T_UID, "UID" }, 288 { T_GID, "GID" }, 289 { T_UNSPEC, "UNSPEC" }, 290 { T_UNSPECA, "UNSPECA" }, |
291 { T_TKEY, "TKEY" }, 292 { T_TSIG, "TSIG" }, 293 { T_IXFR, "IXFR" }, |
|
375 { T_AXFR, "AXFR" }, 376 { T_MAILB, "MAILB" }, 377 { T_MAILA, "MAILA" }, 378 { T_ANY, "ANY" }, 379 { 0, NULL } 380}; 381 | 294 { T_AXFR, "AXFR" }, 295 { T_MAILB, "MAILB" }, 296 { T_MAILA, "MAILA" }, 297 { T_ANY, "ANY" }, 298 { 0, NULL } 299}; 300 |
382static struct tok class2str[] = { | 301struct tok ns_class2str[] = { |
383 { C_IN, "IN" }, /* Not used */ | 302 { C_IN, "IN" }, /* Not used */ |
384 { C_CHAOS, "CHAOS)" }, | 303 { C_CHAOS, "CHAOS" }, |
385 { C_HS, "HS" }, 386 { C_ANY, "ANY" }, 387 { 0, NULL } 388}; 389 390/* print a query */ 391static const u_char * 392ns_qprint(register const u_char *cp, register const u_char *bp) 393{ 394 register const u_char *np = cp; 395 register u_int i; 396 397 cp = ns_nskip(cp, bp); 398 | 304 { C_HS, "HS" }, 305 { C_ANY, "ANY" }, 306 { 0, NULL } 307}; 308 309/* print a query */ 310static const u_char * 311ns_qprint(register const u_char *cp, register const u_char *bp) 312{ 313 register const u_char *np = cp; 314 register u_int i; 315 316 cp = ns_nskip(cp, bp); 317 |
399 if (cp + 4 > snapend || cp == NULL) | 318 if (cp == NULL || !TTEST2(*cp, 4)) |
400 return(NULL); 401 402 /* print the qtype and qclass (if it's not IN) */ 403 i = *cp++ << 8; 404 i |= *cp++; | 319 return(NULL); 320 321 /* print the qtype and qclass (if it's not IN) */ 322 i = *cp++ << 8; 323 i |= *cp++; |
405 printf(" %s", tok2str(type2str, "Type%d", i)); | 324 printf(" %s", tok2str(ns_type2str, "Type%d", i)); |
406 i = *cp++ << 8; 407 i |= *cp++; 408 if (i != C_IN) | 325 i = *cp++ << 8; 326 i |= *cp++; 327 if (i != C_IN) |
409 printf(" %s", tok2str(class2str, "(Class %d)", i)); | 328 printf(" %s", tok2str(ns_class2str, "(Class %d)", i)); |
410 411 fputs("? ", stdout); 412 cp = ns_nprint(np, bp); 413 return(cp ? cp + 4 : NULL); 414} 415 416/* print a reply */ 417static const u_char * --- 5 unchanged lines hidden (view full) --- 423 424 if (vflag) { 425 putchar(' '); 426 if ((cp = ns_nprint(cp, bp)) == NULL) 427 return NULL; 428 } else 429 cp = ns_nskip(cp, bp); 430 | 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 * --- 5 unchanged lines hidden (view full) --- 342 343 if (vflag) { 344 putchar(' '); 345 if ((cp = ns_nprint(cp, bp)) == NULL) 346 return NULL; 347 } else 348 cp = ns_nskip(cp, bp); 349 |
431 if (cp + 10 > snapend || cp == NULL) | 350 if (cp == NULL || !TTEST2(*cp, 10)) |
432 return (snapend); 433 434 /* print the type/qtype and class (if it's not IN) */ 435 typ = *cp++ << 8; 436 typ |= *cp++; 437 class = *cp++ << 8; 438 class |= *cp++; 439 if (class != C_IN && typ != T_OPT) | 351 return (snapend); 352 353 /* 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) |
440 printf(" %s", tok2str(class2str, "(Class %d)", class)); | 359 printf(" %s", tok2str(ns_class2str, "(Class %d)", class)); |
441 442 /* ignore ttl */ 443 cp += 4; 444 445 len = *cp++ << 8; 446 len |= *cp++; 447 448 rp = cp + len; 449 | 360 361 /* ignore ttl */ 362 cp += 4; 363 364 len = *cp++ << 8; 365 len |= *cp++; 366 367 rp = cp + len; 368 |
450 printf(" %s", tok2str(type2str, "Type%d", typ)); | 369 printf(" %s", tok2str(ns_type2str, "Type%d", typ)); |
451 if (rp > snapend) 452 return(NULL); 453 454 switch (typ) { 455 case T_A: | 370 if (rp > snapend) 371 return(NULL); 372 373 switch (typ) { 374 case T_A: |
456 if (cp + sizeof(struct in_addr) > snapend) | 375 if (!TTEST2(*cp, sizeof(struct in_addr))) |
457 return(NULL); 458 printf(" %s", ipaddr_string(cp)); 459 break; 460 461 case T_NS: 462 case T_CNAME: 463 case T_PTR: 464#ifdef T_DNAME --- 8 unchanged lines hidden (view full) --- 473 if (!vflag) 474 break; 475 putchar(' '); 476 if ((cp = ns_nprint(cp, bp)) == NULL) 477 return(NULL); 478 putchar(' '); 479 if ((cp = ns_nprint(cp, bp)) == NULL) 480 return(NULL); | 376 return(NULL); 377 printf(" %s", ipaddr_string(cp)); 378 break; 379 380 case T_NS: 381 case T_CNAME: 382 case T_PTR: 383#ifdef T_DNAME --- 8 unchanged lines hidden (view full) --- 392 if (!vflag) 393 break; 394 putchar(' '); 395 if ((cp = ns_nprint(cp, bp)) == NULL) 396 return(NULL); 397 putchar(' '); 398 if ((cp = ns_nprint(cp, bp)) == NULL) 399 return(NULL); |
481 if (cp + 5 * 4 > snapend) | 400 if (!TTEST2(*cp, 5 * 4)) |
482 return(NULL); 483 printf(" %u", EXTRACT_32BITS(cp)); 484 cp += 4; 485 printf(" %u", EXTRACT_32BITS(cp)); 486 cp += 4; 487 printf(" %u", EXTRACT_32BITS(cp)); 488 cp += 4; 489 printf(" %u", EXTRACT_32BITS(cp)); 490 cp += 4; 491 printf(" %u", EXTRACT_32BITS(cp)); 492 cp += 4; 493 break; 494 case T_MX: 495 putchar(' '); | 401 return(NULL); 402 printf(" %u", EXTRACT_32BITS(cp)); 403 cp += 4; 404 printf(" %u", EXTRACT_32BITS(cp)); 405 cp += 4; 406 printf(" %u", EXTRACT_32BITS(cp)); 407 cp += 4; 408 printf(" %u", EXTRACT_32BITS(cp)); 409 cp += 4; 410 printf(" %u", EXTRACT_32BITS(cp)); 411 cp += 4; 412 break; 413 case T_MX: 414 putchar(' '); |
496 if (cp + 2 > snapend) | 415 if (!TTEST2(*cp, 2)) |
497 return(NULL); 498 if (ns_nprint(cp + 2, bp) == NULL) 499 return(NULL); 500 printf(" %d", EXTRACT_16BITS(cp)); 501 break; 502 503 case T_TXT: 504 putchar(' '); 505 (void)ns_cprint(cp, bp); 506 break; 507 508#ifdef INET6 509 case T_AAAA: | 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: 423 putchar(' '); 424 (void)ns_cprint(cp, bp); 425 break; 426 427#ifdef INET6 428 case T_AAAA: |
510 if (cp + sizeof(struct in6_addr) > snapend) | 429 if (!TTEST2(*cp, sizeof(struct in6_addr))) |
511 return(NULL); 512 printf(" %s", ip6addr_string(cp)); 513 break; 514 515 case T_A6: 516 { 517 struct in6_addr a; 518 int pbit, pbyte; 519 | 430 return(NULL); 431 printf(" %s", ip6addr_string(cp)); 432 break; 433 434 case T_A6: 435 { 436 struct in6_addr a; 437 int pbit, pbyte; 438 |
439 if (!TTEST2(*cp, 1)) 440 return(NULL); |
|
520 pbit = *cp; 521 pbyte = (pbit & ~7) / 8; 522 if (pbit > 128) { 523 printf(" %u(bad plen)", pbit); 524 break; 525 } else if (pbit < 128) { | 441 pbit = *cp; 442 pbyte = (pbit & ~7) / 8; 443 if (pbit > 128) { 444 printf(" %u(bad plen)", pbit); 445 break; 446 } else if (pbit < 128) { |
447 if (!TTEST2(*(cp + 1), sizeof(a) - pbyte)) 448 return(NULL); |
|
526 memset(&a, 0, sizeof(a)); 527 memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte); 528 printf(" %u %s", pbit, ip6addr_string(&a)); 529 } 530 if (pbit > 0) { 531 putchar(' '); 532 if (ns_nprint(cp + 1 + sizeof(a) - pbyte, bp) == NULL) 533 return(NULL); 534 } 535 break; 536 } 537#endif /*INET6*/ 538 539 case T_OPT: 540 printf(" UDPsize=%u", class); 541 break; 542 543 case T_UNSPECA: /* One long string */ | 449 memset(&a, 0, sizeof(a)); 450 memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte); 451 printf(" %u %s", pbit, ip6addr_string(&a)); 452 } 453 if (pbit > 0) { 454 putchar(' '); 455 if (ns_nprint(cp + 1 + sizeof(a) - pbyte, bp) == NULL) 456 return(NULL); 457 } 458 break; 459 } 460#endif /*INET6*/ 461 462 case T_OPT: 463 printf(" UDPsize=%u", class); 464 break; 465 466 case T_UNSPECA: /* One long string */ |
544 if (cp + len > snapend) | 467 if (!TTEST2(*cp, len)) |
545 return(NULL); | 468 return(NULL); |
546 fn_printn(cp, len, snapend); | 469 if (fn_printn(cp, len, snapend)) 470 return(NULL); |
547 break; | 471 break; |
472 473 case T_TSIG: 474 { 475 if (cp + len > snapend) 476 return(NULL); 477 if (!vflag) 478 break; 479 putchar(' '); 480 if ((cp = ns_nprint(cp, bp)) == NULL) 481 return(NULL); 482 cp += 6; 483 if (!TTEST2(*cp, 2)) 484 return(NULL); 485 printf(" fudge=%u", EXTRACT_16BITS(cp)); 486 cp += 2; 487 if (!TTEST2(*cp, 2)) 488 return(NULL); 489 printf(" maclen=%u", EXTRACT_16BITS(cp)); 490 cp += 2 + EXTRACT_16BITS(cp); 491 if (!TTEST2(*cp, 2)) 492 return(NULL); 493 printf(" origid=%u", EXTRACT_16BITS(cp)); 494 cp += 2; 495 if (!TTEST2(*cp, 2)) 496 return(NULL); 497 printf(" error=%u", EXTRACT_16BITS(cp)); 498 cp += 2; 499 if (!TTEST2(*cp, 2)) 500 return(NULL); 501 printf(" otherlen=%u", EXTRACT_16BITS(cp)); 502 cp += 2; 503 } |
|
548 } 549 return (rp); /* XXX This isn't always right */ 550} 551 552void 553ns_print(register const u_char *bp, u_int length) 554{ 555 register const HEADER *np; 556 register int qdcount, ancount, nscount, arcount; | 504 } 505 return (rp); /* XXX This isn't always right */ 506} 507 508void 509ns_print(register const u_char *bp, u_int length) 510{ 511 register const HEADER *np; 512 register int qdcount, ancount, nscount, arcount; |
557 register const u_char *cp = NULL; | 513 register const u_char *cp; |
558 559 np = (const HEADER *)bp; 560 TCHECK(*np); 561 /* get the byte-order right */ 562 qdcount = ntohs(np->qdcount); 563 ancount = ntohs(np->ancount); 564 nscount = ntohs(np->nscount); 565 arcount = ntohs(np->arcount); --- 7 unchanged lines hidden (view full) --- 573 DNS_AA(np)? "*" : "", 574 DNS_RA(np)? "" : "-", 575 DNS_TC(np)? "|" : "", 576 DNS_CD(np)? "%" : ""); 577 578 if (qdcount != 1) 579 printf(" [%dq]", qdcount); 580 /* Print QUESTION section on -vv */ | 514 515 np = (const HEADER *)bp; 516 TCHECK(*np); 517 /* 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); --- 7 unchanged lines hidden (view full) --- 529 DNS_AA(np)? "*" : "", 530 DNS_RA(np)? "" : "-", 531 DNS_TC(np)? "|" : "", 532 DNS_CD(np)? "%" : ""); 533 534 if (qdcount != 1) 535 printf(" [%dq]", qdcount); 536 /* Print QUESTION section on -vv */ |
581 if (vflag > 1) { 582 fputs(" q:", stdout); 583 if ((cp = ns_qprint((const u_char *)(np + 1), bp)) 584 == NULL) 585 goto trunc; 586 } else { 587 if ((cp = ns_nskip((const u_char *)(np + 1), bp)) 588 == NULL) 589 goto trunc; 590 cp += 4; | 537 cp = (const u_char *)(np + 1); 538 while (qdcount--) { 539 if (qdcount < ntohs(np->qdcount) - 1) 540 putchar(','); 541 if (vflag > 1) { 542 fputs(" q:", stdout); 543 if ((cp = ns_qprint(cp, bp)) == NULL) 544 goto trunc; 545 } else { 546 if ((cp = ns_nskip(cp, bp)) == NULL) 547 goto trunc; 548 cp += 4; /* skip QTYPE and QCLASS */ 549 } |
591 } 592 printf(" %d/%d/%d", ancount, nscount, arcount); 593 if (ancount--) { 594 if ((cp = ns_rprint(cp, bp)) == NULL) 595 goto trunc; | 550 } 551 printf(" %d/%d/%d", ancount, nscount, arcount); 552 if (ancount--) { 553 if ((cp = ns_rprint(cp, bp)) == NULL) 554 goto trunc; |
596 while (ancount-- && cp < snapend) { | 555 while (cp < snapend && ancount--) { |
597 putchar(','); 598 if ((cp = ns_rprint(cp, bp)) == NULL) 599 goto trunc; 600 } 601 } | 556 putchar(','); 557 if ((cp = ns_rprint(cp, bp)) == NULL) 558 goto trunc; 559 } 560 } |
561 if (ancount > 0) 562 goto trunc; |
|
602 /* Print NS and AR sections on -vv */ 603 if (vflag > 1) { | 563 /* Print NS and AR sections on -vv */ 564 if (vflag > 1) { |
604 if (nscount-- && cp < snapend) { | 565 if (cp < snapend && nscount--) { |
605 fputs(" ns:", stdout); 606 if ((cp = ns_rprint(cp, bp)) == NULL) 607 goto trunc; | 566 fputs(" ns:", stdout); 567 if ((cp = ns_rprint(cp, bp)) == NULL) 568 goto trunc; |
608 while (nscount-- && cp < snapend) { | 569 while (cp < snapend && nscount--) { |
609 putchar(','); 610 if ((cp = ns_rprint(cp, bp)) == NULL) 611 goto trunc; 612 } 613 } | 570 putchar(','); 571 if ((cp = ns_rprint(cp, bp)) == NULL) 572 goto trunc; 573 } 574 } |
614 if (arcount-- && cp < snapend) { | 575 if (nscount > 0) 576 goto trunc; 577 if (cp < snapend && arcount--) { |
615 fputs(" ar:", stdout); 616 if ((cp = ns_rprint(cp, bp)) == NULL) 617 goto trunc; | 578 fputs(" ar:", stdout); 579 if ((cp = ns_rprint(cp, bp)) == NULL) 580 goto trunc; |
618 while (arcount-- && cp < snapend) { | 581 while (cp < snapend && arcount--) { |
619 putchar(','); 620 if ((cp = ns_rprint(cp, bp)) == NULL) 621 goto trunc; 622 } 623 } | 582 putchar(','); 583 if ((cp = ns_rprint(cp, bp)) == NULL) 584 goto trunc; 585 } 586 } |
587 if (arcount > 0) 588 goto trunc; |
|
624 } 625 } 626 else { 627 /* this is a request */ 628 printf(" %d%s%s%s", ntohs(np->id), ns_ops[DNS_OPCODE(np)], 629 DNS_RD(np) ? "+" : "", 630 DNS_AD(np) ? "$" : ""); 631 --- 13 unchanged lines hidden (view full) --- 645 if (qdcount != 1) 646 printf(" [%dq]", qdcount); 647 } 648 if (nscount) 649 printf(" [%dn]", nscount); 650 if (arcount) 651 printf(" [%dau]", arcount); 652 | 589 } 590 } 591 else { 592 /* this is a request */ 593 printf(" %d%s%s%s", ntohs(np->id), ns_ops[DNS_OPCODE(np)], 594 DNS_RD(np) ? "+" : "", 595 DNS_AD(np) ? "$" : ""); 596 --- 13 unchanged lines hidden (view full) --- 610 if (qdcount != 1) 611 printf(" [%dq]", qdcount); 612 } 613 if (nscount) 614 printf(" [%dn]", nscount); 615 if (arcount) 616 printf(" [%dau]", arcount); 617 |
618 cp = (const u_char *)(np + 1); |
|
653 if (qdcount--) { | 619 if (qdcount--) { |
654 cp = ns_qprint((const u_char *)(np + 1), 655 (const u_char *)np); | 620 cp = ns_qprint(cp, (const u_char *)np); |
656 if (!cp) 657 goto trunc; | 621 if (!cp) 622 goto trunc; |
658 if ((cp = ns_rprint(cp, bp)) == NULL) 659 goto trunc; 660 while (qdcount-- && cp < snapend) { | 623 while (cp < snapend && qdcount--) { |
661 cp = ns_qprint((const u_char *)cp, 662 (const u_char *)np); 663 if (!cp) 664 goto trunc; | 624 cp = ns_qprint((const u_char *)cp, 625 (const u_char *)np); 626 if (!cp) 627 goto trunc; |
665 if ((cp = ns_rprint(cp, bp)) == NULL) 666 goto trunc; | |
667 } 668 } | 628 } 629 } |
630 if (qdcount > 0) 631 goto trunc; |
|
669 670 /* Print remaining sections on -vv */ 671 if (vflag > 1) { 672 if (ancount--) { 673 if ((cp = ns_rprint(cp, bp)) == NULL) 674 goto trunc; | 632 633 /* Print remaining sections on -vv */ 634 if (vflag > 1) { 635 if (ancount--) { 636 if ((cp = ns_rprint(cp, bp)) == NULL) 637 goto trunc; |
675 while (ancount-- && cp < snapend) { | 638 while (cp < snapend && ancount--) { |
676 putchar(','); 677 if ((cp = ns_rprint(cp, bp)) == NULL) 678 goto trunc; 679 } 680 } | 639 putchar(','); 640 if ((cp = ns_rprint(cp, bp)) == NULL) 641 goto trunc; 642 } 643 } |
681 if (nscount-- && cp < snapend) { | 644 if (ancount > 0) 645 goto trunc; 646 if (cp < snapend && nscount--) { |
682 fputs(" ns:", stdout); 683 if ((cp = ns_rprint(cp, bp)) == NULL) 684 goto trunc; 685 while (nscount-- && cp < snapend) { 686 putchar(','); 687 if ((cp = ns_rprint(cp, bp)) == NULL) 688 goto trunc; 689 } 690 } | 647 fputs(" ns:", stdout); 648 if ((cp = ns_rprint(cp, bp)) == NULL) 649 goto trunc; 650 while (nscount-- && cp < snapend) { 651 putchar(','); 652 if ((cp = ns_rprint(cp, bp)) == NULL) 653 goto trunc; 654 } 655 } |
691 if (arcount-- && cp < snapend) { | 656 if (nscount > 0) 657 goto trunc; 658 if (cp < snapend && arcount--) { |
692 fputs(" ar:", stdout); 693 if ((cp = ns_rprint(cp, bp)) == NULL) 694 goto trunc; | 659 fputs(" ar:", stdout); 660 if ((cp = ns_rprint(cp, bp)) == NULL) 661 goto trunc; |
695 while (arcount-- && cp < snapend) { | 662 while (cp < snapend && arcount--) { |
696 putchar(','); 697 if ((cp = ns_rprint(cp, bp)) == NULL) 698 goto trunc; 699 } 700 } | 663 putchar(','); 664 if ((cp = ns_rprint(cp, bp)) == NULL) 665 goto trunc; 666 } 667 } |
668 if (arcount > 0) 669 goto trunc; |
|
701 } 702 } 703 printf(" (%d)", length); 704 return; 705 706 trunc: 707 printf("[|domain]"); 708 return; 709} | 670 } 671 } 672 printf(" (%d)", length); 673 return; 674 675 trunc: 676 printf("[|domain]"); 677 return; 678} |