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