The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 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 |
| 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 |
| 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 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 22 | #define NETDISSECT_REWORKED |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 23 | #ifdef HAVE_CONFIG_H |
| 24 | #include "config.h" |
| 25 | #endif |
| 26 | |
| 27 | #include <tcpdump-stdinc.h> |
| 28 | |
| 29 | #include "nameser.h" |
| 30 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 31 | #include <string.h> |
| 32 | |
| 33 | #include "interface.h" |
| 34 | #include "addrtoname.h" |
| 35 | #include "extract.h" /* must come after interface.h */ |
| 36 | |
| 37 | static const char *ns_ops[] = { |
| 38 | "", " inv_q", " stat", " op3", " notify", " update", " op6", " op7", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 39 | " op8", " updateA", " updateD", " updateDA", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 40 | " updateM", " updateMA", " zoneInit", " zoneRef", |
| 41 | }; |
| 42 | |
| 43 | static const char *ns_resp[] = { |
| 44 | "", " FormErr", " ServFail", " NXDomain", |
| 45 | " NotImp", " Refused", " YXDomain", " YXRRSet", |
| 46 | " NXRRSet", " NotAuth", " NotZone", " Resp11", |
| 47 | " Resp12", " Resp13", " Resp14", " NoChange", |
| 48 | }; |
| 49 | |
| 50 | /* skip over a domain name */ |
| 51 | static const u_char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 52 | ns_nskip(netdissect_options *ndo, |
| 53 | register const u_char *cp) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 54 | { |
| 55 | register u_char i; |
| 56 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 57 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 58 | return (NULL); |
| 59 | i = *cp++; |
| 60 | while (i) { |
| 61 | if ((i & INDIR_MASK) == INDIR_MASK) |
| 62 | return (cp + 1); |
| 63 | if ((i & INDIR_MASK) == EDNS0_MASK) { |
| 64 | int bitlen, bytelen; |
| 65 | |
| 66 | if ((i & ~INDIR_MASK) != EDNS0_ELT_BITLABEL) |
| 67 | return(NULL); /* unknown ELT */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 68 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 69 | return (NULL); |
| 70 | if ((bitlen = *cp++) == 0) |
| 71 | bitlen = 256; |
| 72 | bytelen = (bitlen + 7) / 8; |
| 73 | cp += bytelen; |
| 74 | } else |
| 75 | cp += i; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 76 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 77 | return (NULL); |
| 78 | i = *cp++; |
| 79 | } |
| 80 | return (cp); |
| 81 | } |
| 82 | |
| 83 | /* print a <domain-name> */ |
| 84 | static const u_char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 85 | blabel_print(netdissect_options *ndo, |
| 86 | const u_char *cp) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 87 | { |
| 88 | int bitlen, slen, b; |
| 89 | const u_char *bitp, *lim; |
| 90 | char tc; |
| 91 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 92 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 93 | return(NULL); |
| 94 | if ((bitlen = *cp) == 0) |
| 95 | bitlen = 256; |
| 96 | slen = (bitlen + 3) / 4; |
| 97 | lim = cp + 1 + slen; |
| 98 | |
| 99 | /* print the bit string as a hex string */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 100 | ND_PRINT((ndo, "\\[x")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 101 | for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 102 | ND_TCHECK(*bitp); |
| 103 | ND_PRINT((ndo, "%02x", *bitp)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 104 | } |
| 105 | if (b > 4) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 106 | ND_TCHECK(*bitp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 107 | tc = *bitp++; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 108 | ND_PRINT((ndo, "%02x", tc & (0xff << (8 - b)))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 109 | } else if (b > 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 110 | ND_TCHECK(*bitp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 111 | tc = *bitp++; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 112 | ND_PRINT((ndo, "%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b)))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 113 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 114 | ND_PRINT((ndo, "/%d]", bitlen)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 115 | return lim; |
| 116 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 117 | ND_PRINT((ndo, ".../%d]", bitlen)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 118 | return NULL; |
| 119 | } |
| 120 | |
| 121 | static int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 122 | labellen(netdissect_options *ndo, |
| 123 | const u_char *cp) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 124 | { |
| 125 | register u_int i; |
| 126 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 127 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 128 | return(-1); |
| 129 | i = *cp; |
| 130 | if ((i & INDIR_MASK) == EDNS0_MASK) { |
| 131 | int bitlen, elt; |
| 132 | if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 133 | ND_PRINT((ndo, "<ELT %d>", elt)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 134 | return(-1); |
| 135 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 136 | if (!ND_TTEST2(*(cp + 1), 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 137 | return(-1); |
| 138 | if ((bitlen = *(cp + 1)) == 0) |
| 139 | bitlen = 256; |
| 140 | return(((bitlen + 7) / 8) + 1); |
| 141 | } else |
| 142 | return(i); |
| 143 | } |
| 144 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 145 | const u_char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 146 | ns_nprint(netdissect_options *ndo, |
| 147 | register const u_char *cp, register const u_char *bp) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 148 | { |
| 149 | register u_int i, l; |
| 150 | register const u_char *rp = NULL; |
| 151 | register int compress = 0; |
| 152 | int chars_processed; |
| 153 | int elt; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 154 | int data_size = ndo->ndo_snapend - bp; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 155 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 156 | if ((l = labellen(ndo, cp)) == (u_int)-1) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 157 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 158 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 159 | return(NULL); |
| 160 | chars_processed = 1; |
| 161 | if (((i = *cp++) & INDIR_MASK) != INDIR_MASK) { |
| 162 | compress = 0; |
| 163 | rp = cp + l; |
| 164 | } |
| 165 | |
| 166 | if (i != 0) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 167 | while (i && cp < ndo->ndo_snapend) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 168 | if ((i & INDIR_MASK) == INDIR_MASK) { |
| 169 | if (!compress) { |
| 170 | rp = cp + 1; |
| 171 | compress = 1; |
| 172 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 173 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 174 | return(NULL); |
| 175 | cp = bp + (((i << 8) | *cp) & 0x3fff); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 176 | if ((l = labellen(ndo, cp)) == (u_int)-1) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 177 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 178 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 179 | return(NULL); |
| 180 | i = *cp++; |
| 181 | chars_processed++; |
| 182 | |
| 183 | /* |
| 184 | * If we've looked at every character in |
| 185 | * the message, this pointer will make |
| 186 | * us look at some character again, |
| 187 | * which means we're looping. |
| 188 | */ |
| 189 | if (chars_processed >= data_size) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 190 | ND_PRINT((ndo, "<LOOP>")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 191 | return (NULL); |
| 192 | } |
| 193 | continue; |
| 194 | } |
| 195 | if ((i & INDIR_MASK) == EDNS0_MASK) { |
| 196 | elt = (i & ~INDIR_MASK); |
| 197 | switch(elt) { |
| 198 | case EDNS0_ELT_BITLABEL: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 199 | if (blabel_print(ndo, cp) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 200 | return (NULL); |
| 201 | break; |
| 202 | default: |
| 203 | /* unknown ELT */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 204 | ND_PRINT((ndo, "<ELT %d>", elt)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 205 | return(NULL); |
| 206 | } |
| 207 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 208 | if (fn_printn(ndo, cp, l, ndo->ndo_snapend)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 209 | return(NULL); |
| 210 | } |
| 211 | |
| 212 | cp += l; |
| 213 | chars_processed += l; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 214 | ND_PRINT((ndo, ".")); |
| 215 | if ((l = labellen(ndo, cp)) == (u_int)-1) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 216 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 217 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 218 | return(NULL); |
| 219 | i = *cp++; |
| 220 | chars_processed++; |
| 221 | if (!compress) |
| 222 | rp += l + 1; |
| 223 | } |
| 224 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 225 | ND_PRINT((ndo, ".")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 226 | return (rp); |
| 227 | } |
| 228 | |
| 229 | /* print a <character-string> */ |
| 230 | static const u_char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 231 | ns_cprint(netdissect_options *ndo, |
| 232 | register const u_char *cp) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 233 | { |
| 234 | register u_int i; |
| 235 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 236 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 237 | return (NULL); |
| 238 | i = *cp++; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 239 | if (fn_printn(ndo, cp, i, ndo->ndo_snapend)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 240 | return (NULL); |
| 241 | return (cp + i); |
| 242 | } |
| 243 | |
| 244 | /* http://www.iana.org/assignments/dns-parameters */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 245 | const struct tok ns_type2str[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 246 | { T_A, "A" }, /* RFC 1035 */ |
| 247 | { T_NS, "NS" }, /* RFC 1035 */ |
| 248 | { T_MD, "MD" }, /* RFC 1035 */ |
| 249 | { T_MF, "MF" }, /* RFC 1035 */ |
| 250 | { T_CNAME, "CNAME" }, /* RFC 1035 */ |
| 251 | { T_SOA, "SOA" }, /* RFC 1035 */ |
| 252 | { T_MB, "MB" }, /* RFC 1035 */ |
| 253 | { T_MG, "MG" }, /* RFC 1035 */ |
| 254 | { T_MR, "MR" }, /* RFC 1035 */ |
| 255 | { T_NULL, "NULL" }, /* RFC 1035 */ |
| 256 | { T_WKS, "WKS" }, /* RFC 1035 */ |
| 257 | { T_PTR, "PTR" }, /* RFC 1035 */ |
| 258 | { T_HINFO, "HINFO" }, /* RFC 1035 */ |
| 259 | { T_MINFO, "MINFO" }, /* RFC 1035 */ |
| 260 | { T_MX, "MX" }, /* RFC 1035 */ |
| 261 | { T_TXT, "TXT" }, /* RFC 1035 */ |
| 262 | { T_RP, "RP" }, /* RFC 1183 */ |
| 263 | { T_AFSDB, "AFSDB" }, /* RFC 1183 */ |
| 264 | { T_X25, "X25" }, /* RFC 1183 */ |
| 265 | { T_ISDN, "ISDN" }, /* RFC 1183 */ |
| 266 | { T_RT, "RT" }, /* RFC 1183 */ |
| 267 | { T_NSAP, "NSAP" }, /* RFC 1706 */ |
| 268 | { T_NSAP_PTR, "NSAP_PTR" }, |
| 269 | { T_SIG, "SIG" }, /* RFC 2535 */ |
| 270 | { T_KEY, "KEY" }, /* RFC 2535 */ |
| 271 | { T_PX, "PX" }, /* RFC 2163 */ |
| 272 | { T_GPOS, "GPOS" }, /* RFC 1712 */ |
| 273 | { T_AAAA, "AAAA" }, /* RFC 1886 */ |
| 274 | { T_LOC, "LOC" }, /* RFC 1876 */ |
| 275 | { T_NXT, "NXT" }, /* RFC 2535 */ |
| 276 | { T_EID, "EID" }, /* Nimrod */ |
| 277 | { T_NIMLOC, "NIMLOC" }, /* Nimrod */ |
| 278 | { T_SRV, "SRV" }, /* RFC 2782 */ |
| 279 | { T_ATMA, "ATMA" }, /* ATM Forum */ |
| 280 | { T_NAPTR, "NAPTR" }, /* RFC 2168, RFC 2915 */ |
| 281 | { T_KX, "KX" }, /* RFC 2230 */ |
| 282 | { T_CERT, "CERT" }, /* RFC 2538 */ |
| 283 | { T_A6, "A6" }, /* RFC 2874 */ |
| 284 | { T_DNAME, "DNAME" }, /* RFC 2672 */ |
| 285 | { T_SINK, "SINK" }, |
| 286 | { T_OPT, "OPT" }, /* RFC 2671 */ |
| 287 | { T_APL, "APL" }, /* RFC 3123 */ |
| 288 | { T_DS, "DS" }, /* RFC 4034 */ |
| 289 | { T_SSHFP, "SSHFP" }, /* RFC 4255 */ |
| 290 | { T_IPSECKEY, "IPSECKEY" }, /* RFC 4025 */ |
| 291 | { T_RRSIG, "RRSIG" }, /* RFC 4034 */ |
| 292 | { T_NSEC, "NSEC" }, /* RFC 4034 */ |
| 293 | { T_DNSKEY, "DNSKEY" }, /* RFC 4034 */ |
| 294 | { T_SPF, "SPF" }, /* RFC-schlitt-spf-classic-02.txt */ |
| 295 | { T_UINFO, "UINFO" }, |
| 296 | { T_UID, "UID" }, |
| 297 | { T_GID, "GID" }, |
| 298 | { T_UNSPEC, "UNSPEC" }, |
| 299 | { T_UNSPECA, "UNSPECA" }, |
| 300 | { T_TKEY, "TKEY" }, /* RFC 2930 */ |
| 301 | { T_TSIG, "TSIG" }, /* RFC 2845 */ |
| 302 | { T_IXFR, "IXFR" }, /* RFC 1995 */ |
| 303 | { T_AXFR, "AXFR" }, /* RFC 1035 */ |
| 304 | { T_MAILB, "MAILB" }, /* RFC 1035 */ |
| 305 | { T_MAILA, "MAILA" }, /* RFC 1035 */ |
| 306 | { T_ANY, "ANY" }, |
| 307 | { 0, NULL } |
| 308 | }; |
| 309 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 310 | const struct tok ns_class2str[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 311 | { C_IN, "IN" }, /* Not used */ |
| 312 | { C_CHAOS, "CHAOS" }, |
| 313 | { C_HS, "HS" }, |
| 314 | { C_ANY, "ANY" }, |
| 315 | { 0, NULL } |
| 316 | }; |
| 317 | |
| 318 | /* print a query */ |
| 319 | static const u_char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 320 | ns_qprint(netdissect_options *ndo, |
| 321 | register const u_char *cp, register const u_char *bp, int is_mdns) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 322 | { |
| 323 | register const u_char *np = cp; |
| 324 | register u_int i, class; |
| 325 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 326 | cp = ns_nskip(ndo, cp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 327 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 328 | if (cp == NULL || !ND_TTEST2(*cp, 4)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 329 | return(NULL); |
| 330 | |
| 331 | /* print the qtype */ |
| 332 | i = EXTRACT_16BITS(cp); |
| 333 | cp += 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 334 | ND_PRINT((ndo, " %s", tok2str(ns_type2str, "Type%d", i))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 335 | /* print the qclass (if it's not IN) */ |
| 336 | i = EXTRACT_16BITS(cp); |
| 337 | cp += 2; |
| 338 | if (is_mdns) |
| 339 | class = (i & ~C_QU); |
| 340 | else |
| 341 | class = i; |
| 342 | if (class != C_IN) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 343 | ND_PRINT((ndo, " %s", tok2str(ns_class2str, "(Class %d)", class))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 344 | if (is_mdns) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 345 | ND_PRINT((ndo, i & C_QU ? " (QU)" : " (QM)")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 348 | ND_PRINT((ndo, "? ")); |
| 349 | cp = ns_nprint(ndo, np, bp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 350 | return(cp ? cp + 4 : NULL); |
| 351 | } |
| 352 | |
| 353 | /* print a reply */ |
| 354 | static const u_char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 355 | ns_rprint(netdissect_options *ndo, |
| 356 | register const u_char *cp, register const u_char *bp, int is_mdns) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 357 | { |
| 358 | register u_int i, class, opt_flags = 0; |
| 359 | register u_short typ, len; |
| 360 | register const u_char *rp; |
| 361 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 362 | if (ndo->ndo_vflag) { |
| 363 | ND_PRINT((ndo, " ")); |
| 364 | if ((cp = ns_nprint(ndo, cp, bp)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 365 | return NULL; |
| 366 | } else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 367 | cp = ns_nskip(ndo, cp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 368 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 369 | if (cp == NULL || !ND_TTEST2(*cp, 10)) |
| 370 | return (ndo->ndo_snapend); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 371 | |
| 372 | /* print the type/qtype */ |
| 373 | typ = EXTRACT_16BITS(cp); |
| 374 | cp += 2; |
| 375 | /* print the class (if it's not IN and the type isn't OPT) */ |
| 376 | i = EXTRACT_16BITS(cp); |
| 377 | cp += 2; |
| 378 | if (is_mdns) |
| 379 | class = (i & ~C_CACHE_FLUSH); |
| 380 | else |
| 381 | class = i; |
| 382 | if (class != C_IN && typ != T_OPT) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 383 | ND_PRINT((ndo, " %s", tok2str(ns_class2str, "(Class %d)", class))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 384 | if (is_mdns) { |
| 385 | if (i & C_CACHE_FLUSH) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 386 | ND_PRINT((ndo, " (Cache flush)")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 387 | } |
| 388 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 389 | if (typ == T_OPT) { |
| 390 | /* get opt flags */ |
| 391 | cp += 2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 392 | opt_flags = EXTRACT_16BITS(cp); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 393 | /* ignore rest of ttl field */ |
| 394 | cp += 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 395 | } else if (ndo->ndo_vflag > 2) { |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 396 | /* print ttl */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 397 | ND_PRINT((ndo, " [")); |
| 398 | relts_print(ndo, EXTRACT_32BITS(cp)); |
| 399 | ND_PRINT((ndo, "]")); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 400 | cp += 4; |
| 401 | } else { |
| 402 | /* ignore ttl */ |
| 403 | cp += 4; |
| 404 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 405 | |
| 406 | len = EXTRACT_16BITS(cp); |
| 407 | cp += 2; |
| 408 | |
| 409 | rp = cp + len; |
| 410 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 411 | ND_PRINT((ndo, " %s", tok2str(ns_type2str, "Type%d", typ))); |
| 412 | if (rp > ndo->ndo_snapend) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 413 | return(NULL); |
| 414 | |
| 415 | switch (typ) { |
| 416 | case T_A: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 417 | if (!ND_TTEST2(*cp, sizeof(struct in_addr))) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 418 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 419 | ND_PRINT((ndo, " %s", intoa(htonl(EXTRACT_32BITS(cp))))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 420 | break; |
| 421 | |
| 422 | case T_NS: |
| 423 | case T_CNAME: |
| 424 | case T_PTR: |
| 425 | #ifdef T_DNAME |
| 426 | case T_DNAME: |
| 427 | #endif |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 428 | ND_PRINT((ndo, " ")); |
| 429 | if (ns_nprint(ndo, cp, bp) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 430 | return(NULL); |
| 431 | break; |
| 432 | |
| 433 | case T_SOA: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 434 | if (!ndo->ndo_vflag) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 435 | break; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 436 | ND_PRINT((ndo, " ")); |
| 437 | if ((cp = ns_nprint(ndo, cp, bp)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 438 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 439 | ND_PRINT((ndo, " ")); |
| 440 | if ((cp = ns_nprint(ndo, cp, bp)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 441 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 442 | if (!ND_TTEST2(*cp, 5 * 4)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 443 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 444 | ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 445 | cp += 4; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 446 | ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 447 | cp += 4; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 448 | ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 449 | cp += 4; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 450 | ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 451 | cp += 4; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 452 | ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 453 | cp += 4; |
| 454 | break; |
| 455 | case T_MX: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 456 | ND_PRINT((ndo, " ")); |
| 457 | if (!ND_TTEST2(*cp, 2)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 458 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 459 | if (ns_nprint(ndo, cp + 2, bp) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 460 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 461 | ND_PRINT((ndo, " %d", EXTRACT_16BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 462 | break; |
| 463 | |
| 464 | case T_TXT: |
| 465 | while (cp < rp) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 466 | ND_PRINT((ndo, " \"")); |
| 467 | cp = ns_cprint(ndo, cp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 468 | if (cp == NULL) |
| 469 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 470 | ND_PRINT((ndo, "\"")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 471 | } |
| 472 | break; |
| 473 | |
| 474 | case T_SRV: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 475 | ND_PRINT((ndo, " ")); |
| 476 | if (!ND_TTEST2(*cp, 6)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 477 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 478 | if (ns_nprint(ndo, cp + 6, bp) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 479 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 480 | ND_PRINT((ndo, ":%d %d %d", EXTRACT_16BITS(cp + 4), |
| 481 | EXTRACT_16BITS(cp), EXTRACT_16BITS(cp + 2))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 482 | break; |
| 483 | |
| 484 | #ifdef INET6 |
| 485 | case T_AAAA: |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 486 | { |
| 487 | struct in6_addr addr; |
| 488 | char ntop_buf[INET6_ADDRSTRLEN]; |
| 489 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 490 | if (!ND_TTEST2(*cp, sizeof(struct in6_addr))) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 491 | return(NULL); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 492 | memcpy(&addr, cp, sizeof(struct in6_addr)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 493 | ND_PRINT((ndo, " %s", |
| 494 | inet_ntop(AF_INET6, &addr, ntop_buf, sizeof(ntop_buf)))); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 495 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 496 | break; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 497 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 498 | |
| 499 | case T_A6: |
| 500 | { |
| 501 | struct in6_addr a; |
| 502 | int pbit, pbyte; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 503 | char ntop_buf[INET6_ADDRSTRLEN]; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 504 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 505 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 506 | return(NULL); |
| 507 | pbit = *cp; |
| 508 | pbyte = (pbit & ~7) / 8; |
| 509 | if (pbit > 128) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 510 | ND_PRINT((ndo, " %u(bad plen)", pbit)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 511 | break; |
| 512 | } else if (pbit < 128) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 513 | if (!ND_TTEST2(*(cp + 1), sizeof(a) - pbyte)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 514 | return(NULL); |
| 515 | memset(&a, 0, sizeof(a)); |
| 516 | memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 517 | ND_PRINT((ndo, " %u %s", pbit, |
| 518 | inet_ntop(AF_INET6, &a, ntop_buf, sizeof(ntop_buf)))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 519 | } |
| 520 | if (pbit > 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 521 | ND_PRINT((ndo, " ")); |
| 522 | if (ns_nprint(ndo, cp + 1 + sizeof(a) - pbyte, bp) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 523 | return(NULL); |
| 524 | } |
| 525 | break; |
| 526 | } |
| 527 | #endif /*INET6*/ |
| 528 | |
| 529 | case T_OPT: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 530 | ND_PRINT((ndo, " UDPsize=%u", class)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 531 | if (opt_flags & 0x8000) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 532 | ND_PRINT((ndo, " OK")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 533 | break; |
| 534 | |
| 535 | case T_UNSPECA: /* One long string */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 536 | if (!ND_TTEST2(*cp, len)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 537 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 538 | if (fn_printn(ndo, cp, len, ndo->ndo_snapend)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 539 | return(NULL); |
| 540 | break; |
| 541 | |
| 542 | case T_TSIG: |
| 543 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 544 | if (cp + len > ndo->ndo_snapend) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 545 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 546 | if (!ndo->ndo_vflag) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 547 | break; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 548 | ND_PRINT((ndo, " ")); |
| 549 | if ((cp = ns_nprint(ndo, cp, bp)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 550 | return(NULL); |
| 551 | cp += 6; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 552 | if (!ND_TTEST2(*cp, 2)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 553 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 554 | ND_PRINT((ndo, " fudge=%u", EXTRACT_16BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 555 | cp += 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 556 | if (!ND_TTEST2(*cp, 2)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 557 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 558 | ND_PRINT((ndo, " maclen=%u", EXTRACT_16BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 559 | cp += 2 + EXTRACT_16BITS(cp); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 560 | if (!ND_TTEST2(*cp, 2)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 561 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 562 | ND_PRINT((ndo, " origid=%u", EXTRACT_16BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 563 | cp += 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 564 | if (!ND_TTEST2(*cp, 2)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 565 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 566 | ND_PRINT((ndo, " error=%u", EXTRACT_16BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 567 | cp += 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 568 | if (!ND_TTEST2(*cp, 2)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 569 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 570 | ND_PRINT((ndo, " otherlen=%u", EXTRACT_16BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 571 | cp += 2; |
| 572 | } |
| 573 | } |
| 574 | return (rp); /* XXX This isn't always right */ |
| 575 | } |
| 576 | |
| 577 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 578 | ns_print(netdissect_options *ndo, |
| 579 | register const u_char *bp, u_int length, int is_mdns) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 580 | { |
| 581 | register const HEADER *np; |
| 582 | register int qdcount, ancount, nscount, arcount; |
| 583 | register const u_char *cp; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 584 | uint16_t b2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 585 | |
| 586 | np = (const HEADER *)bp; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 587 | ND_TCHECK(*np); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 588 | /* get the byte-order right */ |
| 589 | qdcount = EXTRACT_16BITS(&np->qdcount); |
| 590 | ancount = EXTRACT_16BITS(&np->ancount); |
| 591 | nscount = EXTRACT_16BITS(&np->nscount); |
| 592 | arcount = EXTRACT_16BITS(&np->arcount); |
| 593 | |
| 594 | if (DNS_QR(np)) { |
| 595 | /* this is a response */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 596 | ND_PRINT((ndo, "%d%s%s%s%s%s%s", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 597 | EXTRACT_16BITS(&np->id), |
| 598 | ns_ops[DNS_OPCODE(np)], |
| 599 | ns_resp[DNS_RCODE(np)], |
| 600 | DNS_AA(np)? "*" : "", |
| 601 | DNS_RA(np)? "" : "-", |
| 602 | DNS_TC(np)? "|" : "", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 603 | DNS_AD(np)? "$" : "")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 604 | |
| 605 | if (qdcount != 1) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 606 | ND_PRINT((ndo, " [%dq]", qdcount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 607 | /* Print QUESTION section on -vv */ |
| 608 | cp = (const u_char *)(np + 1); |
| 609 | while (qdcount--) { |
| 610 | if (qdcount < EXTRACT_16BITS(&np->qdcount) - 1) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 611 | ND_PRINT((ndo, ",")); |
| 612 | if (ndo->ndo_vflag > 1) { |
| 613 | ND_PRINT((ndo, " q:")); |
| 614 | if ((cp = ns_qprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 615 | goto trunc; |
| 616 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 617 | if ((cp = ns_nskip(ndo, cp)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 618 | goto trunc; |
| 619 | cp += 4; /* skip QTYPE and QCLASS */ |
| 620 | } |
| 621 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 622 | ND_PRINT((ndo, " %d/%d/%d", ancount, nscount, arcount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 623 | if (ancount--) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 624 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 625 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 626 | while (cp < ndo->ndo_snapend && ancount--) { |
| 627 | ND_PRINT((ndo, ",")); |
| 628 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 629 | goto trunc; |
| 630 | } |
| 631 | } |
| 632 | if (ancount > 0) |
| 633 | goto trunc; |
| 634 | /* Print NS and AR sections on -vv */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 635 | if (ndo->ndo_vflag > 1) { |
| 636 | if (cp < ndo->ndo_snapend && nscount--) { |
| 637 | ND_PRINT((ndo, " ns:")); |
| 638 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 639 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 640 | while (cp < ndo->ndo_snapend && nscount--) { |
| 641 | ND_PRINT((ndo, ",")); |
| 642 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 643 | goto trunc; |
| 644 | } |
| 645 | } |
| 646 | if (nscount > 0) |
| 647 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 648 | if (cp < ndo->ndo_snapend && arcount--) { |
| 649 | ND_PRINT((ndo, " ar:")); |
| 650 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 651 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 652 | while (cp < ndo->ndo_snapend && arcount--) { |
| 653 | ND_PRINT((ndo, ",")); |
| 654 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 655 | goto trunc; |
| 656 | } |
| 657 | } |
| 658 | if (arcount > 0) |
| 659 | goto trunc; |
| 660 | } |
| 661 | } |
| 662 | else { |
| 663 | /* this is a request */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 664 | ND_PRINT((ndo, "%d%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 665 | DNS_RD(np) ? "+" : "", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 666 | DNS_CD(np) ? "%" : "")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 667 | |
| 668 | /* any weirdness? */ |
| 669 | b2 = EXTRACT_16BITS(((u_short *)np)+1); |
| 670 | if (b2 & 0x6cf) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 671 | ND_PRINT((ndo, " [b2&3=0x%x]", b2)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 672 | |
| 673 | if (DNS_OPCODE(np) == IQUERY) { |
| 674 | if (qdcount) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 675 | ND_PRINT((ndo, " [%dq]", qdcount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 676 | if (ancount != 1) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 677 | ND_PRINT((ndo, " [%da]", ancount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 678 | } |
| 679 | else { |
| 680 | if (ancount) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 681 | ND_PRINT((ndo, " [%da]", ancount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 682 | if (qdcount != 1) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 683 | ND_PRINT((ndo, " [%dq]", qdcount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 684 | } |
| 685 | if (nscount) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 686 | ND_PRINT((ndo, " [%dn]", nscount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 687 | if (arcount) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 688 | ND_PRINT((ndo, " [%dau]", arcount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 689 | |
| 690 | cp = (const u_char *)(np + 1); |
| 691 | if (qdcount--) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 692 | cp = ns_qprint(ndo, cp, (const u_char *)np, is_mdns); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 693 | if (!cp) |
| 694 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 695 | while (cp < ndo->ndo_snapend && qdcount--) { |
| 696 | cp = ns_qprint(ndo, (const u_char *)cp, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 697 | (const u_char *)np, |
| 698 | is_mdns); |
| 699 | if (!cp) |
| 700 | goto trunc; |
| 701 | } |
| 702 | } |
| 703 | if (qdcount > 0) |
| 704 | goto trunc; |
| 705 | |
| 706 | /* Print remaining sections on -vv */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 707 | if (ndo->ndo_vflag > 1) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 708 | if (ancount--) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 709 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 710 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 711 | while (cp < ndo->ndo_snapend && ancount--) { |
| 712 | ND_PRINT((ndo, ",")); |
| 713 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 714 | goto trunc; |
| 715 | } |
| 716 | } |
| 717 | if (ancount > 0) |
| 718 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 719 | if (cp < ndo->ndo_snapend && nscount--) { |
| 720 | ND_PRINT((ndo, " ns:")); |
| 721 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 722 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 723 | while (nscount-- && cp < ndo->ndo_snapend) { |
| 724 | ND_PRINT((ndo, ",")); |
| 725 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 726 | goto trunc; |
| 727 | } |
| 728 | } |
| 729 | if (nscount > 0) |
| 730 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 731 | if (cp < ndo->ndo_snapend && arcount--) { |
| 732 | ND_PRINT((ndo, " ar:")); |
| 733 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 734 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 735 | while (cp < ndo->ndo_snapend && arcount--) { |
| 736 | ND_PRINT((ndo, ",")); |
| 737 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 738 | goto trunc; |
| 739 | } |
| 740 | } |
| 741 | if (arcount > 0) |
| 742 | goto trunc; |
| 743 | } |
| 744 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 745 | ND_PRINT((ndo, " (%d)", length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 746 | return; |
| 747 | |
| 748 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 749 | ND_PRINT((ndo, "[|domain]")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 750 | } |