]> The Tcpdump Group git mirrors - tcpdump/blob - print-icmp6.c
(token_if_print): remove unused variable
[tcpdump] / print-icmp6.c
1 /*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
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
22 #ifndef lint
23 static const char rcsid[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.18 2000-07-16 05:25:16 itojun Exp $";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #ifdef INET6
32
33 #include <ctype.h>
34
35 #include <sys/param.h>
36 #include <sys/time.h>
37 #include <sys/types.h>
38 #include <sys/socket.h>
39
40 #include <net/if.h>
41
42 #include <netinet/in.h>
43 #include <netinet/if_ether.h>
44 #include <netinet/in_systm.h>
45 #include <netinet/ip.h>
46 #include <netinet/ip_icmp.h>
47 #include <netinet/ip_var.h>
48 #include <netinet/udp.h>
49 #include <netinet/udp_var.h>
50 #include <netinet/tcp.h>
51
52 #include <arpa/inet.h>
53
54 #include <stdio.h>
55
56 #include <netinet/ip6.h>
57 #include <netinet/icmp6.h>
58
59 #include "interface.h"
60 #include "addrtoname.h"
61
62 void icmp6_opt_print(const u_char *, int);
63 void mld6_print(const u_char *);
64 #ifdef HAVE_STRUCT_ICMP6_NODEINFO
65 static void dnsname_print(const u_char *, const u_char *);
66 void icmp6_nodeinfo_print(int, const u_char *, const u_char *);
67 #endif
68
69 #ifndef abs
70 #define abs(a) ((0 < (a)) ? (a) : -(a))
71 #endif
72
73 #ifndef HAVE_STRUCT_ICMP6_NODEINFO
74 struct icmp6_nodeinfo {
75 struct icmp6_hdr icmp6_ni_hdr;
76 u_int8_t icmp6_ni_nonce[8];
77 /* could be followed by reply data */
78 };
79
80 #define ni_type icmp6_ni_hdr.icmp6_type
81 #define ni_code icmp6_ni_hdr.icmp6_code
82 #define ni_cksum icmp6_ni_hdr.icmp6_cksum
83 #define ni_qtype icmp6_ni_hdr.icmp6_data16[0]
84 #define ni_flags icmp6_ni_hdr.icmp6_data16[1]
85 #endif
86
87 #ifndef ICMP6_NI_SUCCESS
88 #define ICMP6_NI_SUCESS 0 /* node information successful reply */
89 #define ICMP6_NI_REFUSED 1 /* node information request is refused */
90 #define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */
91 #endif
92
93 #ifdef NI_QTYPE_NOOP
94 #define NI_QTYPE_NOOP 0 /* NOOP */
95 #define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes */
96 #define NI_QTYPE_FQDN 2 /* FQDN */
97 #define NI_QTYPE_NODEADDR 3 /* Node Addresses. XXX: spec says 2, but it may be a typo... */
98 #endif
99
100 #ifndef ICMP6_NI_SUBJ_IPV6
101 #define ICMP6_NI_SUBJ_IPV6 0 /* Query Subject is an IPv6 address */
102 #define ICMP6_NI_SUBJ_FQDN 1 /* Query Subject is a Domain name */
103 #define ICMP6_NI_SUBJ_IPV4 2 /* Query Subject is an IPv4 address */
104 #endif
105
106 void
107 icmp6_print(register const u_char *bp, register const u_char *bp2)
108 {
109 const struct icmp6_hdr *dp;
110 register const struct ip6_hdr *ip;
111 register const char *str;
112 register const struct ip6_hdr *oip;
113 register const struct udphdr *ouh;
114 register int hlen, dport;
115 register const u_char *ep;
116 char buf[256];
117 int icmp6len;
118
119 #if 0
120 #define TCHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) goto trunc
121 #endif
122
123 dp = (struct icmp6_hdr *)bp;
124 ip = (struct ip6_hdr *)bp2;
125 oip = (struct ip6_hdr *)(dp + 1);
126 str = buf;
127 /* 'ep' points to the end of avaible data. */
128 ep = snapend;
129 if (ip->ip6_plen)
130 icmp6len = (ntohs(ip->ip6_plen) + sizeof(struct ip6_hdr) -
131 (bp - bp2));
132 else /* XXX: jumbo payload case... */
133 icmp6len = snapend - bp;
134
135 #if 0
136 (void)printf("%s > %s: ",
137 ip6addr_string(&ip->ip6_src),
138 ip6addr_string(&ip->ip6_dst));
139 #endif
140
141 TCHECK(dp->icmp6_code);
142 switch (dp->icmp6_type) {
143 case ICMP6_DST_UNREACH:
144 TCHECK(oip->ip6_dst);
145 switch (dp->icmp6_code) {
146 case ICMP6_DST_UNREACH_NOROUTE:
147 printf("icmp6: %s unreachable route",
148 ip6addr_string(&oip->ip6_dst));
149 break;
150 case ICMP6_DST_UNREACH_ADMIN:
151 printf("icmp6: %s unreachable prohibited",
152 ip6addr_string(&oip->ip6_dst));
153 break;
154 #ifdef ICMP6_DST_UNREACH_BEYONDSCOPE
155 case ICMP6_DST_UNREACH_BEYONDSCOPE:
156 #else
157 case ICMP6_DST_UNREACH_NOTNEIGHBOR:
158 #endif
159 printf("icmp6: %s beyond scope of source address %s",
160 ip6addr_string(&oip->ip6_dst),
161 ip6addr_string(&oip->ip6_src));
162 break;
163 case ICMP6_DST_UNREACH_ADDR:
164 printf("icmp6: %s unreachable address",
165 ip6addr_string(&oip->ip6_dst));
166 break;
167 case ICMP6_DST_UNREACH_NOPORT:
168 TCHECK(oip->ip6_nxt);
169 hlen = sizeof(struct ip6_hdr);
170 ouh = (struct udphdr *)(((u_char *)oip) + hlen);
171 dport = ntohs(ouh->uh_dport);
172 switch (oip->ip6_nxt) {
173 case IPPROTO_TCP:
174 printf("icmp6: %s tcp port %s unreachable",
175 ip6addr_string(&oip->ip6_dst),
176 tcpport_string(dport));
177 break;
178 case IPPROTO_UDP:
179 printf("icmp6: %s udp port %s unreachable",
180 ip6addr_string(&oip->ip6_dst),
181 udpport_string(dport));
182 break;
183 default:
184 printf("icmp6: %s protocol %d port %d unreachable",
185 ip6addr_string(&oip->ip6_dst),
186 oip->ip6_nxt, dport);
187 break;
188 }
189 break;
190 default:
191 printf("icmp6: %s unreachable code-#%d",
192 ip6addr_string(&oip->ip6_dst),
193 dp->icmp6_code);
194 break;
195 }
196 break;
197 case ICMP6_PACKET_TOO_BIG:
198 TCHECK(dp->icmp6_mtu);
199 printf("icmp6: too big %u\n", (u_int32_t)ntohl(dp->icmp6_mtu));
200 break;
201 case ICMP6_TIME_EXCEEDED:
202 TCHECK(oip->ip6_dst);
203 switch (dp->icmp6_code) {
204 case ICMP6_TIME_EXCEED_TRANSIT:
205 printf("icmp6: time exceeded in-transit for %s",
206 ip6addr_string(&oip->ip6_dst));
207 break;
208 case ICMP6_TIME_EXCEED_REASSEMBLY:
209 printf("icmp6: ip6 reassembly time exceeded");
210 break;
211 default:
212 printf("icmp6: time exceeded code-#%d",
213 dp->icmp6_code);
214 break;
215 }
216 break;
217 case ICMP6_PARAM_PROB:
218 TCHECK(oip->ip6_dst);
219 switch (dp->icmp6_code) {
220 case ICMP6_PARAMPROB_HEADER:
221 printf("icmp6: parameter problem errorneous - octet %u\n",
222 (u_int32_t)ntohl(dp->icmp6_pptr));
223 break;
224 case ICMP6_PARAMPROB_NEXTHEADER:
225 printf("icmp6: parameter problem next header - octet %u\n",
226 (u_int32_t)ntohl(dp->icmp6_pptr));
227 break;
228 case ICMP6_PARAMPROB_OPTION:
229 printf("icmp6: parameter problem option - octet %u\n",
230 (u_int32_t)ntohl(dp->icmp6_pptr));
231 break;
232 default:
233 printf("icmp6: parameter problem code-#%d",
234 dp->icmp6_code);
235 break;
236 }
237 break;
238 case ICMP6_ECHO_REQUEST:
239 printf("icmp6: echo request");
240 break;
241 case ICMP6_ECHO_REPLY:
242 printf("icmp6: echo reply");
243 break;
244 #if defined(HAVE_STRUCT_MLD6_HDR) || defined(HAVE_STRUCT_ICMP6_MLD)
245 case ICMP6_MEMBERSHIP_QUERY:
246 printf("icmp6: multicast listener query ");
247 mld6_print((const u_char *)dp);
248 break;
249 case ICMP6_MEMBERSHIP_REPORT:
250 printf("icmp6: multicast listener report ");
251 mld6_print((const u_char *)dp);
252 break;
253 case ICMP6_MEMBERSHIP_REDUCTION:
254 printf("icmp6: multicast listener done ");
255 mld6_print((const u_char *)dp);
256 break;
257 #endif
258 case ND_ROUTER_SOLICIT:
259 printf("icmp6: router solicitation ");
260 if (vflag) {
261 #define RTSOLLEN 8
262 icmp6_opt_print((const u_char *)dp + RTSOLLEN,
263 icmp6len - RTSOLLEN);
264 }
265 break;
266 case ND_ROUTER_ADVERT:
267 printf("icmp6: router advertisement");
268 if (vflag) {
269 struct nd_router_advert *p;
270
271 p = (struct nd_router_advert *)dp;
272 TCHECK(p->nd_ra_retransmit);
273 printf("(chlim=%d, ", (int)p->nd_ra_curhoplimit);
274 if (p->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED)
275 printf("M");
276 if (p->nd_ra_flags_reserved & ND_RA_FLAG_OTHER)
277 printf("O");
278 #ifndef ND_RA_FLAG_HA
279 #define ND_RA_FLAG_HA 0x20
280 #endif
281 if (p->nd_ra_flags_reserved & ND_RA_FLAG_HA)
282 printf("H");
283 if (p->nd_ra_flags_reserved != 0)
284 printf(" ");
285 printf("router_ltime=%d, ", ntohs(p->nd_ra_router_lifetime));
286 printf("reachable_time=%u, ",
287 (u_int32_t)ntohl(p->nd_ra_reachable));
288 printf("retrans_time=%u)",
289 (u_int32_t)ntohl(p->nd_ra_retransmit));
290 #define RTADVLEN 16
291 icmp6_opt_print((const u_char *)dp + RTADVLEN,
292 icmp6len - RTADVLEN);
293 }
294 break;
295 case ND_NEIGHBOR_SOLICIT:
296 {
297 struct nd_neighbor_solicit *p;
298 p = (struct nd_neighbor_solicit *)dp;
299 TCHECK(p->nd_ns_target);
300 printf("icmp6: neighbor sol: who has %s",
301 ip6addr_string(&p->nd_ns_target));
302 if (vflag) {
303 #define NDSOLLEN 24
304 icmp6_opt_print((const u_char *)dp + NDSOLLEN,
305 icmp6len - NDSOLLEN);
306 }
307 }
308 break;
309 case ND_NEIGHBOR_ADVERT:
310 {
311 struct nd_neighbor_advert *p;
312
313 p = (struct nd_neighbor_advert *)dp;
314 TCHECK(p->nd_na_target);
315 printf("icmp6: neighbor adv: tgt is %s",
316 ip6addr_string(&p->nd_na_target));
317 if (vflag) {
318 #define ND_NA_FLAG_ALL \
319 (ND_NA_FLAG_ROUTER|ND_NA_FLAG_SOLICITED|ND_NA_FLAG_OVERRIDE)
320 /* we don't need ntohl() here. see advanced-api-04. */
321 if (p->nd_na_flags_reserved & ND_NA_FLAG_ALL) {
322 #undef ND_NA_FLAG_ALL
323 u_int32_t flags;
324
325 flags = p->nd_na_flags_reserved;
326 printf("(");
327 if (flags & ND_NA_FLAG_ROUTER)
328 printf("R");
329 if (flags & ND_NA_FLAG_SOLICITED)
330 printf("S");
331 if (flags & ND_NA_FLAG_OVERRIDE)
332 printf("O");
333 printf(")");
334 }
335 #define NDADVLEN 24
336 icmp6_opt_print((const u_char *)dp + NDADVLEN,
337 icmp6len - NDADVLEN);
338 #undef NDADVLEN
339 }
340 }
341 break;
342 case ND_REDIRECT:
343 #define RDR(i) ((struct nd_redirect *)(i))
344 TCHECK(RDR(dp)->nd_rd_dst);
345 printf("icmp6: redirect %s",
346 getname6((const u_char *)&RDR(dp)->nd_rd_dst));
347 printf(" to %s",
348 getname6((const u_char*)&RDR(dp)->nd_rd_target));
349 #define REDIRECTLEN 40
350 if (vflag) {
351 icmp6_opt_print((const u_char *)dp + REDIRECTLEN,
352 icmp6len - REDIRECTLEN);
353 }
354 break;
355 #undef REDIRECTLEN
356 #undef RDR
357 #ifndef ICMP6_ROUTER_RENUMBERING
358 #define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */
359 #endif
360 case ICMP6_ROUTER_RENUMBERING:
361 switch (dp->icmp6_code) {
362 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
363 #define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */
364 #endif
365 case ICMP6_ROUTER_RENUMBERING_COMMAND:
366 printf("icmp6: router renum command");
367 break;
368 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
369 #define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */
370 #endif
371 case ICMP6_ROUTER_RENUMBERING_RESULT:
372 printf("icmp6: router renum result");
373 break;
374 default:
375 printf("icmp6: router renum code-#%d", dp->icmp6_code);
376 break;
377 }
378 break;
379 #ifdef HAVE_STRUCT_ICMP6_NODEINFO
380 #ifndef ICMP6_NI_QUERY
381 #define ICMP6_NI_QUERY 139
382 #endif
383 case ICMP6_NI_QUERY:
384 icmp6_nodeinfo_print(icmp6len, bp, ep);
385 break;
386 #ifndef ICMP6_NI_REPLY
387 #define ICMP6_NI_REPLY 140
388 #endif
389 case ICMP6_NI_REPLY:
390 icmp6_nodeinfo_print(icmp6len, bp, ep);
391 break;
392 #endif
393 default:
394 printf("icmp6: type-#%d", dp->icmp6_type);
395 break;
396 }
397 return;
398 trunc:
399 fputs("[|icmp6]", stdout);
400 #if 0
401 #undef TCHECK
402 #endif
403 }
404
405 void
406 icmp6_opt_print(register const u_char *bp, int resid)
407 {
408 register const struct nd_opt_hdr *op;
409 register const struct nd_opt_hdr *opl; /* why there's no struct? */
410 register const struct nd_opt_prefix_info *opp;
411 register const struct icmp6_opts_redirect *opr;
412 register const struct nd_opt_mtu *opm;
413 register const u_char *ep;
414 int opts_len;
415 #if 0
416 register const struct ip6_hdr *ip;
417 register const char *str;
418 register const struct ip6_hdr *oip;
419 register const struct udphdr *ouh;
420 register int hlen, dport;
421 char buf[256];
422 #endif
423
424 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
425
426 op = (struct nd_opt_hdr *)bp;
427 #if 0
428 ip = (struct ip6_hdr *)bp2;
429 oip = &dp->icmp6_ip6;
430 str = buf;
431 #endif
432 /* 'ep' points to the end of avaible data. */
433 ep = snapend;
434
435 ECHECK(op->nd_opt_len);
436 if (resid <= 0)
437 return;
438 switch (op->nd_opt_type) {
439 case ND_OPT_SOURCE_LINKADDR:
440 opl = (struct nd_opt_hdr *)op;
441 #if 1
442 if ((u_char *)opl + (opl->nd_opt_len << 3) > ep)
443 goto trunc;
444 #else
445 TCHECK((u_char *)opl + (opl->nd_opt_len << 3) - 1);
446 #endif
447 printf("(src lladdr: %s", /*)*/
448 etheraddr_string((u_char *)(opl + 1)));
449 if (opl->nd_opt_len != 1)
450 printf("!");
451 /*(*/
452 printf(")");
453 icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
454 resid - (op->nd_opt_len << 3));
455 break;
456 case ND_OPT_TARGET_LINKADDR:
457 opl = (struct nd_opt_hdr *)op;
458 #if 1
459 if ((u_char *)opl + (opl->nd_opt_len << 3) > ep)
460 goto trunc;
461 #else
462 TCHECK((u_char *)opl + (opl->nd_opt_len << 3) - 1);
463 #endif
464 printf("(tgt lladdr: %s", /*)*/
465 etheraddr_string((u_char *)(opl + 1)));
466 if (opl->nd_opt_len != 1)
467 printf("!");
468 /*(*/
469 printf(")");
470 icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
471 resid - (op->nd_opt_len << 3));
472 break;
473 case ND_OPT_PREFIX_INFORMATION:
474 opp = (struct nd_opt_prefix_info *)op;
475 TCHECK(opp->nd_opt_pi_prefix);
476 printf("(prefix info: "); /*)*/
477 if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK)
478 printf("L");
479 if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO)
480 printf("A");
481 if (opp->nd_opt_pi_flags_reserved)
482 printf(" ");
483 printf("valid_ltime=");
484 if ((u_int32_t)ntohl(opp->nd_opt_pi_valid_time) == ~0U)
485 printf("infinity");
486 else {
487 printf("%u", (u_int32_t)ntohl(opp->nd_opt_pi_valid_time));
488 }
489 printf(", ");
490 printf("preffered_ltime=");
491 if ((u_int32_t)ntohl(opp->nd_opt_pi_preferred_time) == ~0U)
492 printf("infinity");
493 else {
494 printf("%u", (u_int32_t)ntohl(opp->nd_opt_pi_preferred_time));
495 }
496 printf(", ");
497 printf("prefix=%s/%d", ip6addr_string(&opp->nd_opt_pi_prefix),
498 opp->nd_opt_pi_prefix_len);
499 if (opp->nd_opt_pi_len != 4)
500 printf("!");
501 /*(*/
502 printf(")");
503 icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
504 resid - (op->nd_opt_len << 3));
505 break;
506 case ND_OPT_REDIRECTED_HEADER:
507 opr = (struct icmp6_opts_redirect *)op;
508 printf("(redirect)");
509 /* xxx */
510 icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
511 resid - (op->nd_opt_len << 3));
512 break;
513 case ND_OPT_MTU:
514 opm = (struct nd_opt_mtu *)op;
515 TCHECK(opm->nd_opt_mtu_mtu);
516 printf("(mtu: "); /*)*/
517 printf("mtu=%u", (u_int32_t)ntohl(opm->nd_opt_mtu_mtu));
518 if (opm->nd_opt_mtu_len != 1)
519 printf("!");
520 printf(")");
521 icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
522 resid - (op->nd_opt_len << 3));
523 break;
524 default:
525 opts_len = op->nd_opt_len;
526 printf("(unknwon opt_type=%d, opt_len=%d)",
527 op->nd_opt_type, opts_len);
528 if (opts_len == 0)
529 opts_len = 1; /* XXX */
530 icmp6_opt_print((const u_char *)op + (opts_len << 3),
531 resid - (opts_len << 3));
532 break;
533 }
534 return;
535 trunc:
536 fputs("[ndp opt]", stdout);
537 return;
538 #undef ECHECK
539 }
540
541 #if defined(HAVE_STRUCT_MLD6_HDR)
542 void
543 mld6_print(register const u_char *bp)
544 {
545 register struct mld6_hdr *mp = (struct mld6_hdr *)bp;
546 register const u_char *ep;
547
548 /* 'ep' points to the end of avaible data. */
549 ep = snapend;
550
551 if ((u_char *)mp + sizeof(*mp) > ep)
552 return;
553
554 printf("max resp delay: %d ", ntohs(mp->mld6_maxdelay));
555 printf("addr: %s", ip6addr_string(&mp->mld6_addr));
556 }
557
558 #elif defined(HAVE_STRUCT_ICMP6_MLD)
559
560 void
561 mld6_print(register const u_char *bp)
562 {
563 register struct icmp6_mld *mp = (struct icmp6_mld *)bp;
564 register const u_char *ep;
565
566 /* 'ep' points to the end of avaible data. */
567 ep = snapend;
568
569 if ((u_char *)mp + sizeof(*mp) > ep)
570 return;
571
572 printf("max resp delay: %d ", ntohs(mp->icmp6m_hdr.icmp6_maxdelay));
573 printf("addr: %s", ip6addr_string(&mp->icmp6m_group));
574 }
575
576 #endif
577
578 #ifdef HAVE_STRUCT_ICMP6_NODEINFO
579 static void
580 dnsname_print(const u_char *cp, const u_char *ep)
581 {
582 int i;
583
584 /* DNS name decoding - no decompression */
585 printf(", \"");
586 while (cp < ep) {
587 i = *cp++;
588 if (i) {
589 if (i > ep - cp) {
590 printf("???");
591 break;
592 }
593 while (i-- && cp < ep) {
594 safeputchar(*cp);
595 cp++;
596 }
597 if (cp + 1 < ep && *cp)
598 printf(".");
599 } else {
600 if (cp == ep) {
601 /* FQDN */
602 printf(".");
603 } else if (cp + 1 == ep && *cp == '\0') {
604 /* truncated */
605 } else {
606 /* invalid */
607 printf("???");
608 }
609 break;
610 }
611 }
612 printf("\"");
613 }
614
615 void
616 icmp6_nodeinfo_print(int icmp6len, const u_char *bp, const u_char *ep)
617 {
618 struct icmp6_nodeinfo *ni6;
619 struct icmp6_hdr *dp;
620 const u_char *cp;
621 int siz, i;
622 int needcomma;
623
624 dp = (struct icmp6_hdr *)bp;
625 ni6 = (struct icmp6_nodeinfo *)bp;
626 siz = ep - bp;
627
628 switch (ni6->ni_type) {
629 case ICMP6_NI_QUERY:
630 if (siz == sizeof(*dp) + 4) {
631 /* KAME who-are-you */
632 printf("icmp6: who-are-you request");
633 break;
634 }
635 printf("icmp6: node information query");
636
637 TCHECK2(*dp, sizeof(*ni6));
638 ni6 = (struct icmp6_nodeinfo *)dp;
639 printf(" ("); /*)*/
640 switch (ntohs(ni6->ni_qtype)) {
641 case NI_QTYPE_NOOP:
642 printf("noop");
643 break;
644 case NI_QTYPE_SUPTYPES:
645 printf("supported qtypes");
646 i = ntohs(ni6->ni_flags);
647 if (i)
648 printf(" [%s]", (i & 0x01) ? "C" : "");
649 break;
650 break;
651 case NI_QTYPE_FQDN:
652 printf("DNS name");
653 break;
654 case NI_QTYPE_NODEADDR:
655 printf("node addresses");
656 i = ni6->ni_flags;
657 if (!i)
658 break;
659 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
660 printf(" [%s%s%s%s%s%s]",
661 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
662 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
663 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
664 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
665 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
666 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "");
667 break;
668 default:
669 printf("unknown");
670 break;
671 }
672
673 if (ni6->ni_qtype == NI_QTYPE_NOOP ||
674 ni6->ni_qtype == NI_QTYPE_SUPTYPES) {
675 if (siz != sizeof(*ni6))
676 if (vflag)
677 printf(", invalid len");
678 /*(*/
679 printf(")");
680 break;
681 }
682
683
684 /* XXX backward compat, icmp-name-lookup-03 */
685 if (siz == sizeof(*ni6)) {
686 printf(", 03 draft");
687 /*(*/
688 printf(")");
689 break;
690 }
691
692 switch (ni6->ni_code) {
693 case ICMP6_NI_SUBJ_IPV6:
694 if (!TTEST2(*dp,
695 sizeof(*ni6) + sizeof(struct in6_addr)))
696 break;
697 if (siz != sizeof(*ni6) + sizeof(struct in6_addr)) {
698 if (vflag)
699 printf(", invalid subject len");
700 break;
701 }
702 printf(", subject=%s",
703 getname6((const u_char *)(ni6 + 1)));
704 break;
705 case ICMP6_NI_SUBJ_FQDN:
706 printf(", subject=DNS name");
707 cp = (const u_char *)(ni6 + 1);
708 if (cp[0] == ep - cp - 1) {
709 /* icmp-name-lookup-03, pascal string */
710 if (vflag)
711 printf(", 03 draft");
712 cp++;
713 printf(", \"");
714 while (cp < ep) {
715 safeputchar(*cp);
716 cp++;
717 }
718 printf("\"");
719 } else
720 dnsname_print(cp, ep);
721 break;
722 case ICMP6_NI_SUBJ_IPV4:
723 if (!TTEST2(*dp, sizeof(*ni6) + sizeof(struct in_addr)))
724 break;
725 if (siz != sizeof(*ni6) + sizeof(struct in_addr)) {
726 if (vflag)
727 printf(", invalid subject len");
728 break;
729 }
730 printf(", subject=%s",
731 getname((const u_char *)(ni6 + 1)));
732 break;
733 default:
734 printf(", unknown subject");
735 break;
736 }
737
738 /*(*/
739 printf(")");
740 break;
741
742 case ICMP6_NI_REPLY:
743 if (icmp6len > siz) {
744 printf("[|icmp6: node information reply]");
745 break;
746 }
747
748 needcomma = 0;
749
750 ni6 = (struct icmp6_nodeinfo *)dp;
751 printf("icmp6: node information query");
752 printf(" ("); /*)*/
753 switch (ni6->ni_code) {
754 case ICMP6_NI_SUCESS:
755 if (vflag) {
756 printf("success");
757 needcomma++;
758 }
759 break;
760 case ICMP6_NI_REFUSED:
761 printf("refused");
762 needcomma++;
763 if (siz != sizeof(*ni6))
764 if (vflag)
765 printf(", invalid length");
766 break;
767 case ICMP6_NI_UNKNOWN:
768 printf("unknown");
769 needcomma++;
770 if (siz != sizeof(*ni6))
771 if (vflag)
772 printf(", invalid length");
773 break;
774 }
775
776 if (ni6->ni_code != ICMP6_NI_SUCESS) {
777 /*(*/
778 printf(")");
779 break;
780 }
781
782 switch (ntohs(ni6->ni_qtype)) {
783 case NI_QTYPE_NOOP:
784 if (needcomma)
785 printf(", ");
786 printf("noop");
787 if (siz != sizeof(*ni6))
788 if (vflag)
789 printf(", invalid length");
790 break;
791 case NI_QTYPE_SUPTYPES:
792 if (needcomma)
793 printf(", ");
794 printf("supported qtypes");
795 i = ntohs(ni6->ni_flags);
796 if (i)
797 printf(" [%s]", (i & 0x01) ? "C" : "");
798 break;
799 case NI_QTYPE_FQDN:
800 if (needcomma)
801 printf(", ");
802 printf("DNS name");
803 cp = (const u_char *)(ni6 + 1) + 4;
804 if (cp[0] == ep - cp - 1) {
805 /* icmp-name-lookup-03, pascal string */
806 if (vflag)
807 printf(", 03 draft");
808 cp++;
809 printf(", \"");
810 while (cp < ep) {
811 safeputchar(*cp);
812 cp++;
813 }
814 printf("\"");
815 } else
816 dnsname_print(cp, ep);
817 if ((ntohs(ni6->ni_flags) & 0x01) != 0)
818 printf(" [TTL=%u]", *(u_int32_t *)(ni6 + 1));
819 break;
820 case NI_QTYPE_NODEADDR:
821 if (needcomma)
822 printf(", ");
823 printf("node addresses");
824 for (i = sizeof(*ni6);
825 i < siz;
826 i += sizeof(struct in6_addr)) {
827 printf(" %s", getname6(bp + i));
828 }
829 i = ni6->ni_flags;
830 if (!i)
831 break;
832 printf(" [%s%s%s%s%s%s%s]",
833 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
834 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
835 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
836 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
837 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
838 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "",
839 (i & NI_NODEADDR_FLAG_TRUNCATE) ? "T" : "");
840 break;
841 default:
842 if (needcomma)
843 printf(", ");
844 printf("unknown");
845 break;
846 }
847
848 /*(*/
849 printf(")");
850 break;
851 }
852 return;
853
854 trunc:
855 fputs("[|icmp6]", stdout);
856 }
857 #endif
858
859 #endif /* INET6 */