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