print-lwres.c revision 1.2 1 1.1 christos /*
2 1.1 christos * Copyright (C) 2001 WIDE Project.
3 1.1 christos * All rights reserved.
4 1.1 christos *
5 1.1 christos * Redistribution and use in source and binary forms, with or without
6 1.1 christos * modification, are permitted provided that the following conditions
7 1.1 christos * are met:
8 1.1 christos * 1. Redistributions of source code must retain the above copyright
9 1.1 christos * notice, this list of conditions and the following disclaimer.
10 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 christos * notice, this list of conditions and the following disclaimer in the
12 1.1 christos * documentation and/or other materials provided with the distribution.
13 1.1 christos * 3. Neither the name of the project nor the names of its contributors
14 1.1 christos * may be used to endorse or promote products derived from this software
15 1.1 christos * without specific prior written permission.
16 1.1 christos *
17 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.1 christos * SUCH DAMAGE.
28 1.1 christos */
29 1.1 christos
30 1.2 christos #include <sys/cdefs.h>
31 1.1 christos #ifndef lint
32 1.2 christos #if 0
33 1.1 christos static const char rcsid[] _U_ =
34 1.1 christos "@(#) Header: /tcpdump/master/tcpdump/print-lwres.c,v 1.13 2004-03-24 01:54:29 guy Exp (LBL)";
35 1.2 christos #else
36 1.2 christos __RCSID("$NetBSD: print-lwres.c,v 1.2 2010/12/05 05:11:30 christos Exp $");
37 1.2 christos #endif
38 1.1 christos #endif
39 1.1 christos
40 1.1 christos #ifdef HAVE_CONFIG_H
41 1.1 christos #include "config.h"
42 1.1 christos #endif
43 1.1 christos
44 1.1 christos #include <tcpdump-stdinc.h>
45 1.1 christos
46 1.1 christos #include "nameser.h"
47 1.1 christos
48 1.1 christos #include <stdio.h>
49 1.1 christos #include <string.h>
50 1.1 christos
51 1.1 christos #include "interface.h"
52 1.1 christos #include "addrtoname.h"
53 1.1 christos #include "extract.h" /* must come after interface.h */
54 1.1 christos
55 1.1 christos /* BIND9 lib/lwres/include/lwres */
56 1.1 christos typedef u_int32_t lwres_uint32_t;
57 1.1 christos typedef u_int16_t lwres_uint16_t;
58 1.1 christos typedef u_int8_t lwres_uint8_t;
59 1.1 christos
60 1.1 christos struct lwres_lwpacket {
61 1.1 christos lwres_uint32_t length;
62 1.1 christos lwres_uint16_t version;
63 1.1 christos lwres_uint16_t pktflags;
64 1.1 christos lwres_uint32_t serial;
65 1.1 christos lwres_uint32_t opcode;
66 1.1 christos lwres_uint32_t result;
67 1.1 christos lwres_uint32_t recvlength;
68 1.1 christos lwres_uint16_t authtype;
69 1.1 christos lwres_uint16_t authlength;
70 1.1 christos };
71 1.1 christos
72 1.1 christos #define LWRES_LWPACKETFLAG_RESPONSE 0x0001U /* if set, pkt is a response */
73 1.1 christos
74 1.1 christos #define LWRES_LWPACKETVERSION_0 0
75 1.1 christos
76 1.1 christos #define LWRES_FLAG_TRUSTNOTREQUIRED 0x00000001U
77 1.1 christos #define LWRES_FLAG_SECUREDATA 0x00000002U
78 1.1 christos
79 1.1 christos /*
80 1.1 christos * no-op
81 1.1 christos */
82 1.1 christos #define LWRES_OPCODE_NOOP 0x00000000U
83 1.1 christos
84 1.1 christos typedef struct {
85 1.1 christos /* public */
86 1.1 christos lwres_uint16_t datalength;
87 1.1 christos /* data follows */
88 1.1 christos } lwres_nooprequest_t;
89 1.1 christos
90 1.1 christos typedef struct {
91 1.1 christos /* public */
92 1.1 christos lwres_uint16_t datalength;
93 1.1 christos /* data follows */
94 1.1 christos } lwres_noopresponse_t;
95 1.1 christos
96 1.1 christos /*
97 1.1 christos * get addresses by name
98 1.1 christos */
99 1.1 christos #define LWRES_OPCODE_GETADDRSBYNAME 0x00010001U
100 1.1 christos
101 1.1 christos typedef struct lwres_addr lwres_addr_t;
102 1.1 christos
103 1.1 christos struct lwres_addr {
104 1.1 christos lwres_uint32_t family;
105 1.1 christos lwres_uint16_t length;
106 1.1 christos /* address folows */
107 1.1 christos };
108 1.1 christos
109 1.1 christos typedef struct {
110 1.1 christos /* public */
111 1.1 christos lwres_uint32_t flags;
112 1.1 christos lwres_uint32_t addrtypes;
113 1.1 christos lwres_uint16_t namelen;
114 1.1 christos /* name follows */
115 1.1 christos } lwres_gabnrequest_t;
116 1.1 christos
117 1.1 christos typedef struct {
118 1.1 christos /* public */
119 1.1 christos lwres_uint32_t flags;
120 1.1 christos lwres_uint16_t naliases;
121 1.1 christos lwres_uint16_t naddrs;
122 1.1 christos lwres_uint16_t realnamelen;
123 1.1 christos /* aliases follows */
124 1.1 christos /* addrs follows */
125 1.1 christos /* realname follows */
126 1.1 christos } lwres_gabnresponse_t;
127 1.1 christos
128 1.1 christos /*
129 1.1 christos * get name by address
130 1.1 christos */
131 1.1 christos #define LWRES_OPCODE_GETNAMEBYADDR 0x00010002U
132 1.1 christos typedef struct {
133 1.1 christos /* public */
134 1.1 christos lwres_uint32_t flags;
135 1.1 christos lwres_addr_t addr;
136 1.1 christos /* addr body follows */
137 1.1 christos } lwres_gnbarequest_t;
138 1.1 christos
139 1.1 christos typedef struct {
140 1.1 christos /* public */
141 1.1 christos lwres_uint32_t flags;
142 1.1 christos lwres_uint16_t naliases;
143 1.1 christos lwres_uint16_t realnamelen;
144 1.1 christos /* aliases follows */
145 1.1 christos /* realname follows */
146 1.1 christos } lwres_gnbaresponse_t;
147 1.1 christos
148 1.1 christos /*
149 1.1 christos * get rdata by name
150 1.1 christos */
151 1.1 christos #define LWRES_OPCODE_GETRDATABYNAME 0x00010003U
152 1.1 christos
153 1.1 christos typedef struct {
154 1.1 christos /* public */
155 1.1 christos lwres_uint32_t flags;
156 1.1 christos lwres_uint16_t rdclass;
157 1.1 christos lwres_uint16_t rdtype;
158 1.1 christos lwres_uint16_t namelen;
159 1.1 christos /* name follows */
160 1.1 christos } lwres_grbnrequest_t;
161 1.1 christos
162 1.1 christos typedef struct {
163 1.1 christos /* public */
164 1.1 christos lwres_uint32_t flags;
165 1.1 christos lwres_uint16_t rdclass;
166 1.1 christos lwres_uint16_t rdtype;
167 1.1 christos lwres_uint32_t ttl;
168 1.1 christos lwres_uint16_t nrdatas;
169 1.1 christos lwres_uint16_t nsigs;
170 1.1 christos /* realname here (len + name) */
171 1.1 christos /* rdata here (len + name) */
172 1.1 christos /* signatures here (len + name) */
173 1.1 christos } lwres_grbnresponse_t;
174 1.1 christos
175 1.1 christos #define LWRDATA_VALIDATED 0x00000001
176 1.1 christos
177 1.1 christos #define LWRES_ADDRTYPE_V4 0x00000001U /* ipv4 */
178 1.1 christos #define LWRES_ADDRTYPE_V6 0x00000002U /* ipv6 */
179 1.1 christos
180 1.1 christos #define LWRES_MAX_ALIASES 16 /* max # of aliases */
181 1.1 christos #define LWRES_MAX_ADDRS 64 /* max # of addrs */
182 1.1 christos
183 1.1 christos struct tok opcode[] = {
184 1.1 christos { LWRES_OPCODE_NOOP, "noop", },
185 1.1 christos { LWRES_OPCODE_GETADDRSBYNAME, "getaddrsbyname", },
186 1.1 christos { LWRES_OPCODE_GETNAMEBYADDR, "getnamebyaddr", },
187 1.1 christos { LWRES_OPCODE_GETRDATABYNAME, "getrdatabyname", },
188 1.1 christos { 0, NULL, },
189 1.1 christos };
190 1.1 christos
191 1.1 christos /* print-domain.c */
192 1.1 christos extern struct tok ns_type2str[];
193 1.1 christos extern struct tok ns_class2str[];
194 1.1 christos
195 1.1 christos static int lwres_printname(size_t, const char *);
196 1.1 christos static int lwres_printnamelen(const char *);
197 1.1 christos static int lwres_printbinlen(const char *);
198 1.1 christos static int lwres_printaddr(lwres_addr_t *);
199 1.1 christos
200 1.1 christos static int
201 1.1 christos lwres_printname(size_t l, const char *p0)
202 1.1 christos {
203 1.1 christos const char *p;
204 1.1 christos size_t i;
205 1.1 christos
206 1.1 christos p = p0;
207 1.1 christos /* + 1 for terminating \0 */
208 1.1 christos if (p + l + 1 > (const char *)snapend)
209 1.1 christos goto trunc;
210 1.1 christos
211 1.1 christos printf(" ");
212 1.1 christos for (i = 0; i < l; i++)
213 1.1 christos safeputchar(*p++);
214 1.1 christos p++; /* skip terminating \0 */
215 1.1 christos
216 1.1 christos return p - p0;
217 1.1 christos
218 1.1 christos trunc:
219 1.1 christos return -1;
220 1.1 christos }
221 1.1 christos
222 1.1 christos static int
223 1.1 christos lwres_printnamelen(const char *p)
224 1.1 christos {
225 1.1 christos u_int16_t l;
226 1.1 christos int advance;
227 1.1 christos
228 1.1 christos if (p + 2 > (const char *)snapend)
229 1.1 christos goto trunc;
230 1.1 christos l = EXTRACT_16BITS(p);
231 1.1 christos advance = lwres_printname(l, p + 2);
232 1.1 christos if (advance < 0)
233 1.1 christos goto trunc;
234 1.1 christos return 2 + advance;
235 1.1 christos
236 1.1 christos trunc:
237 1.1 christos return -1;
238 1.1 christos }
239 1.1 christos
240 1.1 christos static int
241 1.1 christos lwres_printbinlen(const char *p0)
242 1.1 christos {
243 1.1 christos const char *p;
244 1.1 christos u_int16_t l;
245 1.1 christos int i;
246 1.1 christos
247 1.1 christos p = p0;
248 1.1 christos if (p + 2 > (const char *)snapend)
249 1.1 christos goto trunc;
250 1.1 christos l = EXTRACT_16BITS(p);
251 1.1 christos if (p + 2 + l > (const char *)snapend)
252 1.1 christos goto trunc;
253 1.1 christos p += 2;
254 1.1 christos for (i = 0; i < l; i++)
255 1.1 christos printf("%02x", *p++);
256 1.1 christos return p - p0;
257 1.1 christos
258 1.1 christos trunc:
259 1.1 christos return -1;
260 1.1 christos }
261 1.1 christos
262 1.1 christos static int
263 1.1 christos lwres_printaddr(lwres_addr_t *ap)
264 1.1 christos {
265 1.1 christos u_int16_t l;
266 1.1 christos const char *p;
267 1.1 christos int i;
268 1.1 christos
269 1.1 christos TCHECK(ap->length);
270 1.1 christos l = EXTRACT_16BITS(&ap->length);
271 1.1 christos /* XXX ap points to packed struct */
272 1.1 christos p = (const char *)&ap->length + sizeof(ap->length);
273 1.1 christos TCHECK2(*p, l);
274 1.1 christos
275 1.1 christos switch (EXTRACT_32BITS(&ap->family)) {
276 1.1 christos case 1: /* IPv4 */
277 1.1 christos if (l < 4)
278 1.1 christos return -1;
279 1.1 christos printf(" %s", ipaddr_string(p));
280 1.1 christos p += sizeof(struct in_addr);
281 1.1 christos break;
282 1.1 christos #ifdef INET6
283 1.1 christos case 2: /* IPv6 */
284 1.1 christos if (l < 16)
285 1.1 christos return -1;
286 1.1 christos printf(" %s", ip6addr_string(p));
287 1.1 christos p += sizeof(struct in6_addr);
288 1.1 christos break;
289 1.1 christos #endif
290 1.1 christos default:
291 1.1 christos printf(" %u/", EXTRACT_32BITS(&ap->family));
292 1.1 christos for (i = 0; i < l; i++)
293 1.1 christos printf("%02x", *p++);
294 1.1 christos }
295 1.1 christos
296 1.1 christos return p - (const char *)ap;
297 1.1 christos
298 1.1 christos trunc:
299 1.1 christos return -1;
300 1.1 christos }
301 1.1 christos
302 1.1 christos void
303 1.1 christos lwres_print(register const u_char *bp, u_int length)
304 1.1 christos {
305 1.1 christos const struct lwres_lwpacket *np;
306 1.1 christos u_int32_t v;
307 1.1 christos const char *s;
308 1.1 christos int response;
309 1.1 christos int advance;
310 1.1 christos int unsupported = 0;
311 1.1 christos
312 1.1 christos np = (const struct lwres_lwpacket *)bp;
313 1.1 christos TCHECK(np->authlength);
314 1.1 christos
315 1.1 christos printf(" lwres");
316 1.1 christos v = EXTRACT_16BITS(&np->version);
317 1.1 christos if (vflag || v != LWRES_LWPACKETVERSION_0)
318 1.1 christos printf(" v%u", v);
319 1.1 christos if (v != LWRES_LWPACKETVERSION_0) {
320 1.1 christos s = (const char *)np + EXTRACT_32BITS(&np->length);
321 1.1 christos goto tail;
322 1.1 christos }
323 1.1 christos
324 1.1 christos response = EXTRACT_16BITS(&np->pktflags) & LWRES_LWPACKETFLAG_RESPONSE;
325 1.1 christos
326 1.1 christos /* opcode and pktflags */
327 1.1 christos v = EXTRACT_32BITS(&np->opcode);
328 1.1 christos s = tok2str(opcode, "#0x%x", v);
329 1.1 christos printf(" %s%s", s, response ? "" : "?");
330 1.1 christos
331 1.1 christos /* pktflags */
332 1.1 christos v = EXTRACT_16BITS(&np->pktflags);
333 1.1 christos if (v & ~LWRES_LWPACKETFLAG_RESPONSE)
334 1.1 christos printf("[0x%x]", v);
335 1.1 christos
336 1.1 christos if (vflag > 1) {
337 1.1 christos printf(" ("); /*)*/
338 1.1 christos printf("serial:0x%x", EXTRACT_32BITS(&np->serial));
339 1.1 christos printf(" result:0x%x", EXTRACT_32BITS(&np->result));
340 1.1 christos printf(" recvlen:%u", EXTRACT_32BITS(&np->recvlength));
341 1.1 christos /* BIND910: not used */
342 1.1 christos if (vflag > 2) {
343 1.1 christos printf(" authtype:0x%x", EXTRACT_16BITS(&np->authtype));
344 1.1 christos printf(" authlen:%u", EXTRACT_16BITS(&np->authlength));
345 1.1 christos }
346 1.1 christos /*(*/
347 1.1 christos printf(")");
348 1.1 christos }
349 1.1 christos
350 1.1 christos /* per-opcode content */
351 1.1 christos if (!response) {
352 1.1 christos /*
353 1.1 christos * queries
354 1.1 christos */
355 1.1 christos lwres_gabnrequest_t *gabn;
356 1.1 christos lwres_gnbarequest_t *gnba;
357 1.1 christos lwres_grbnrequest_t *grbn;
358 1.1 christos u_int32_t l;
359 1.1 christos
360 1.1 christos gabn = NULL;
361 1.1 christos gnba = NULL;
362 1.1 christos grbn = NULL;
363 1.1 christos
364 1.1 christos switch (EXTRACT_32BITS(&np->opcode)) {
365 1.1 christos case LWRES_OPCODE_NOOP:
366 1.1 christos break;
367 1.1 christos case LWRES_OPCODE_GETADDRSBYNAME:
368 1.1 christos gabn = (lwres_gabnrequest_t *)(np + 1);
369 1.1 christos TCHECK(gabn->namelen);
370 1.1 christos /* XXX gabn points to packed struct */
371 1.1 christos s = (const char *)&gabn->namelen +
372 1.1 christos sizeof(gabn->namelen);
373 1.1 christos l = EXTRACT_16BITS(&gabn->namelen);
374 1.1 christos
375 1.1 christos /* BIND910: not used */
376 1.1 christos if (vflag > 2) {
377 1.1 christos printf(" flags:0x%x",
378 1.1 christos EXTRACT_32BITS(&gabn->flags));
379 1.1 christos }
380 1.1 christos
381 1.1 christos v = EXTRACT_32BITS(&gabn->addrtypes);
382 1.1 christos switch (v & (LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6)) {
383 1.1 christos case LWRES_ADDRTYPE_V4:
384 1.1 christos printf(" IPv4");
385 1.1 christos break;
386 1.1 christos case LWRES_ADDRTYPE_V6:
387 1.1 christos printf(" IPv6");
388 1.1 christos break;
389 1.1 christos case LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6:
390 1.1 christos printf(" IPv4/6");
391 1.1 christos break;
392 1.1 christos }
393 1.1 christos if (v & ~(LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6))
394 1.1 christos printf("[0x%x]", v);
395 1.1 christos
396 1.1 christos advance = lwres_printname(l, s);
397 1.1 christos if (advance < 0)
398 1.1 christos goto trunc;
399 1.1 christos s += advance;
400 1.1 christos break;
401 1.1 christos case LWRES_OPCODE_GETNAMEBYADDR:
402 1.1 christos gnba = (lwres_gnbarequest_t *)(np + 1);
403 1.1 christos TCHECK(gnba->addr);
404 1.1 christos
405 1.1 christos /* BIND910: not used */
406 1.1 christos if (vflag > 2) {
407 1.1 christos printf(" flags:0x%x",
408 1.1 christos EXTRACT_32BITS(&gnba->flags));
409 1.1 christos }
410 1.1 christos
411 1.1 christos s = (const char *)&gnba->addr;
412 1.1 christos
413 1.1 christos advance = lwres_printaddr(&gnba->addr);
414 1.1 christos if (advance < 0)
415 1.1 christos goto trunc;
416 1.1 christos s += advance;
417 1.1 christos break;
418 1.1 christos case LWRES_OPCODE_GETRDATABYNAME:
419 1.1 christos /* XXX no trace, not tested */
420 1.1 christos grbn = (lwres_grbnrequest_t *)(np + 1);
421 1.1 christos TCHECK(grbn->namelen);
422 1.1 christos
423 1.1 christos /* BIND910: not used */
424 1.1 christos if (vflag > 2) {
425 1.1 christos printf(" flags:0x%x",
426 1.1 christos EXTRACT_32BITS(&grbn->flags));
427 1.1 christos }
428 1.1 christos
429 1.1 christos printf(" %s", tok2str(ns_type2str, "Type%d",
430 1.1 christos EXTRACT_16BITS(&grbn->rdtype)));
431 1.1 christos if (EXTRACT_16BITS(&grbn->rdclass) != C_IN) {
432 1.1 christos printf(" %s", tok2str(ns_class2str, "Class%d",
433 1.1 christos EXTRACT_16BITS(&grbn->rdclass)));
434 1.1 christos }
435 1.1 christos
436 1.1 christos /* XXX grbn points to packed struct */
437 1.1 christos s = (const char *)&grbn->namelen +
438 1.1 christos sizeof(grbn->namelen);
439 1.1 christos l = EXTRACT_16BITS(&grbn->namelen);
440 1.1 christos
441 1.1 christos advance = lwres_printname(l, s);
442 1.1 christos if (advance < 0)
443 1.1 christos goto trunc;
444 1.1 christos s += advance;
445 1.1 christos break;
446 1.1 christos default:
447 1.1 christos unsupported++;
448 1.1 christos break;
449 1.1 christos }
450 1.1 christos } else {
451 1.1 christos /*
452 1.1 christos * responses
453 1.1 christos */
454 1.1 christos lwres_gabnresponse_t *gabn;
455 1.1 christos lwres_gnbaresponse_t *gnba;
456 1.1 christos lwres_grbnresponse_t *grbn;
457 1.1 christos u_int32_t l, na;
458 1.1 christos u_int32_t i;
459 1.1 christos
460 1.1 christos gabn = NULL;
461 1.1 christos gnba = NULL;
462 1.1 christos grbn = NULL;
463 1.1 christos
464 1.1 christos switch (EXTRACT_32BITS(&np->opcode)) {
465 1.1 christos case LWRES_OPCODE_NOOP:
466 1.1 christos break;
467 1.1 christos case LWRES_OPCODE_GETADDRSBYNAME:
468 1.1 christos gabn = (lwres_gabnresponse_t *)(np + 1);
469 1.1 christos TCHECK(gabn->realnamelen);
470 1.1 christos /* XXX gabn points to packed struct */
471 1.1 christos s = (const char *)&gabn->realnamelen +
472 1.1 christos sizeof(gabn->realnamelen);
473 1.1 christos l = EXTRACT_16BITS(&gabn->realnamelen);
474 1.1 christos
475 1.1 christos /* BIND910: not used */
476 1.1 christos if (vflag > 2) {
477 1.1 christos printf(" flags:0x%x",
478 1.1 christos EXTRACT_32BITS(&gabn->flags));
479 1.1 christos }
480 1.1 christos
481 1.1 christos printf(" %u/%u", EXTRACT_16BITS(&gabn->naliases),
482 1.1 christos EXTRACT_16BITS(&gabn->naddrs));
483 1.1 christos
484 1.1 christos advance = lwres_printname(l, s);
485 1.1 christos if (advance < 0)
486 1.1 christos goto trunc;
487 1.1 christos s += advance;
488 1.1 christos
489 1.1 christos /* aliases */
490 1.1 christos na = EXTRACT_16BITS(&gabn->naliases);
491 1.1 christos for (i = 0; i < na; i++) {
492 1.1 christos advance = lwres_printnamelen(s);
493 1.1 christos if (advance < 0)
494 1.1 christos goto trunc;
495 1.1 christos s += advance;
496 1.1 christos }
497 1.1 christos
498 1.1 christos /* addrs */
499 1.1 christos na = EXTRACT_16BITS(&gabn->naddrs);
500 1.1 christos for (i = 0; i < na; i++) {
501 1.1 christos advance = lwres_printaddr((lwres_addr_t *)s);
502 1.1 christos if (advance < 0)
503 1.1 christos goto trunc;
504 1.1 christos s += advance;
505 1.1 christos }
506 1.1 christos break;
507 1.1 christos case LWRES_OPCODE_GETNAMEBYADDR:
508 1.1 christos gnba = (lwres_gnbaresponse_t *)(np + 1);
509 1.1 christos TCHECK(gnba->realnamelen);
510 1.1 christos /* XXX gnba points to packed struct */
511 1.1 christos s = (const char *)&gnba->realnamelen +
512 1.1 christos sizeof(gnba->realnamelen);
513 1.1 christos l = EXTRACT_16BITS(&gnba->realnamelen);
514 1.1 christos
515 1.1 christos /* BIND910: not used */
516 1.1 christos if (vflag > 2) {
517 1.1 christos printf(" flags:0x%x",
518 1.1 christos EXTRACT_32BITS(&gnba->flags));
519 1.1 christos }
520 1.1 christos
521 1.1 christos printf(" %u", EXTRACT_16BITS(&gnba->naliases));
522 1.1 christos
523 1.1 christos advance = lwres_printname(l, s);
524 1.1 christos if (advance < 0)
525 1.1 christos goto trunc;
526 1.1 christos s += advance;
527 1.1 christos
528 1.1 christos /* aliases */
529 1.1 christos na = EXTRACT_16BITS(&gnba->naliases);
530 1.1 christos for (i = 0; i < na; i++) {
531 1.1 christos advance = lwres_printnamelen(s);
532 1.1 christos if (advance < 0)
533 1.1 christos goto trunc;
534 1.1 christos s += advance;
535 1.1 christos }
536 1.1 christos break;
537 1.1 christos case LWRES_OPCODE_GETRDATABYNAME:
538 1.1 christos /* XXX no trace, not tested */
539 1.1 christos grbn = (lwres_grbnresponse_t *)(np + 1);
540 1.1 christos TCHECK(grbn->nsigs);
541 1.1 christos
542 1.1 christos /* BIND910: not used */
543 1.1 christos if (vflag > 2) {
544 1.1 christos printf(" flags:0x%x",
545 1.1 christos EXTRACT_32BITS(&grbn->flags));
546 1.1 christos }
547 1.1 christos
548 1.1 christos printf(" %s", tok2str(ns_type2str, "Type%d",
549 1.1 christos EXTRACT_16BITS(&grbn->rdtype)));
550 1.1 christos if (EXTRACT_16BITS(&grbn->rdclass) != C_IN) {
551 1.1 christos printf(" %s", tok2str(ns_class2str, "Class%d",
552 1.1 christos EXTRACT_16BITS(&grbn->rdclass)));
553 1.1 christos }
554 1.1 christos printf(" TTL ");
555 1.1 christos relts_print(EXTRACT_32BITS(&grbn->ttl));
556 1.1 christos printf(" %u/%u", EXTRACT_16BITS(&grbn->nrdatas),
557 1.1 christos EXTRACT_16BITS(&grbn->nsigs));
558 1.1 christos
559 1.1 christos /* XXX grbn points to packed struct */
560 1.1 christos s = (const char *)&grbn->nsigs+ sizeof(grbn->nsigs);
561 1.1 christos
562 1.1 christos advance = lwres_printnamelen(s);
563 1.1 christos if (advance < 0)
564 1.1 christos goto trunc;
565 1.1 christos s += advance;
566 1.1 christos
567 1.1 christos /* rdatas */
568 1.1 christos na = EXTRACT_16BITS(&grbn->nrdatas);
569 1.1 christos for (i = 0; i < na; i++) {
570 1.1 christos /* XXX should decode resource data */
571 1.1 christos advance = lwres_printbinlen(s);
572 1.1 christos if (advance < 0)
573 1.1 christos goto trunc;
574 1.1 christos s += advance;
575 1.1 christos }
576 1.1 christos
577 1.1 christos /* sigs */
578 1.1 christos na = EXTRACT_16BITS(&grbn->nsigs);
579 1.1 christos for (i = 0; i < na; i++) {
580 1.1 christos /* XXX how should we print it? */
581 1.1 christos advance = lwres_printbinlen(s);
582 1.1 christos if (advance < 0)
583 1.1 christos goto trunc;
584 1.1 christos s += advance;
585 1.1 christos }
586 1.1 christos break;
587 1.1 christos default:
588 1.1 christos unsupported++;
589 1.1 christos break;
590 1.1 christos }
591 1.1 christos }
592 1.1 christos
593 1.1 christos tail:
594 1.1 christos /* length mismatch */
595 1.1 christos if (EXTRACT_32BITS(&np->length) != length) {
596 1.1 christos printf(" [len: %u != %u]", EXTRACT_32BITS(&np->length),
597 1.1 christos length);
598 1.1 christos }
599 1.1 christos if (!unsupported && s < (const char *)np + EXTRACT_32BITS(&np->length))
600 1.1 christos printf("[extra]");
601 1.1 christos return;
602 1.1 christos
603 1.1 christos trunc:
604 1.1 christos printf("[|lwres]");
605 1.1 christos return;
606 1.1 christos }
607