2 * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
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
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.
23 static const char rcsid
[] _U_
=
24 "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.72.2.3 2003-11-19 01:28:19 guy Exp $";
33 #include <tcpdump-stdinc.h>
42 #include "interface.h"
43 #include "addrtoname.h"
49 static const char *get_rtpref(u_int
);
50 static const char *get_lifetime(u_int32_t
);
51 static void print_lladdr(const u_char
*, size_t);
52 static void icmp6_opt_print(const u_char
*, int);
53 static void mld6_print(const u_char
*);
54 static struct udphdr
*get_upperlayer(u_char
*, u_int
*);
55 static void dnsname_print(const u_char
*, const u_char
*);
56 static void icmp6_nodeinfo_print(u_int
, const u_char
*, const u_char
*);
57 static void icmp6_rrenum_print(const u_char
*, const u_char
*);
60 #define abs(a) ((0 < (a)) ? (a) : -(a))
66 static const char *rtpref_str
[] = {
73 return rtpref_str
[((v
& ND_RA_FLAG_RTPREF_MASK
) >> 3) & 0xff];
77 get_lifetime(u_int32_t v
)
81 if (v
== (u_int32_t
)~0UL)
84 snprintf(buf
, sizeof(buf
), "%u", v
);
90 print_lladdr(const u_int8_t
*p
, size_t l
)
92 const u_int8_t
*ep
, *q
;
96 while (l
> 0 && q
< ep
) {
104 static int icmp6_cksum(const struct ip6_hdr
*ip6
, const struct icmp6_hdr
*icp
,
108 register const u_int16_t
*sp
;
112 struct in6_addr ph_src
;
113 struct in6_addr ph_dst
;
122 memset(&phu
, 0, sizeof(phu
));
123 phu
.ph
.ph_src
= ip6
->ip6_src
;
124 phu
.ph
.ph_dst
= ip6
->ip6_dst
;
125 phu
.ph
.ph_len
= htonl(len
);
126 phu
.ph
.ph_nxt
= IPPROTO_ICMPV6
;
129 for (i
= 0; i
< sizeof(phu
.pa
) / sizeof(phu
.pa
[0]); i
++)
132 sp
= (const u_int16_t
*)icp
;
134 for (i
= 0; i
< (len
& ~1); i
+= 2)
138 sum
+= htons((*(const u_int8_t
*)sp
) << 8);
141 sum
= (sum
& 0xffff) + (sum
>> 16);
148 icmp6_print(const u_char
*bp
, u_int length
, const u_char
*bp2
, int fragmented
)
150 const struct icmp6_hdr
*dp
;
151 const struct ip6_hdr
*ip
;
153 const struct ip6_hdr
*oip
;
154 const struct udphdr
*ouh
;
160 dp
= (struct icmp6_hdr
*)bp
;
161 ip
= (struct ip6_hdr
*)bp2
;
162 oip
= (struct ip6_hdr
*)(dp
+ 1);
164 /* 'ep' points to the end of available data. */
167 TCHECK(dp
->icmp6_cksum
);
169 if (vflag
&& !fragmented
) {
170 int sum
= dp
->icmp6_cksum
;
172 if (TTEST2(bp
[0], length
)) {
173 sum
= icmp6_cksum(ip
, dp
, length
);
175 (void)printf("[bad icmp6 cksum %x!] ", sum
);
177 (void)printf("[icmp6 sum ok] ");
181 switch (dp
->icmp6_type
) {
182 case ICMP6_DST_UNREACH
:
183 TCHECK(oip
->ip6_dst
);
184 switch (dp
->icmp6_code
) {
185 case ICMP6_DST_UNREACH_NOROUTE
:
186 printf("icmp6: %s unreachable route",
187 ip6addr_string(&oip
->ip6_dst
));
189 case ICMP6_DST_UNREACH_ADMIN
:
190 printf("icmp6: %s unreachable prohibited",
191 ip6addr_string(&oip
->ip6_dst
));
193 case ICMP6_DST_UNREACH_BEYONDSCOPE
:
194 printf("icmp6: %s beyond scope of source address %s",
195 ip6addr_string(&oip
->ip6_dst
),
196 ip6addr_string(&oip
->ip6_src
));
198 case ICMP6_DST_UNREACH_ADDR
:
199 printf("icmp6: %s unreachable address",
200 ip6addr_string(&oip
->ip6_dst
));
202 case ICMP6_DST_UNREACH_NOPORT
:
203 if ((ouh
= get_upperlayer((u_char
*)oip
, &prot
))
207 dport
= EXTRACT_16BITS(&ouh
->uh_dport
);
210 printf("icmp6: %s tcp port %s unreachable",
211 ip6addr_string(&oip
->ip6_dst
),
212 tcpport_string(dport
));
215 printf("icmp6: %s udp port %s unreachable",
216 ip6addr_string(&oip
->ip6_dst
),
217 udpport_string(dport
));
220 printf("icmp6: %s protocol %d port %d unreachable",
221 ip6addr_string(&oip
->ip6_dst
),
222 oip
->ip6_nxt
, dport
);
227 printf("icmp6: %s unreachable code-#%d",
228 ip6addr_string(&oip
->ip6_dst
),
233 case ICMP6_PACKET_TOO_BIG
:
234 TCHECK(dp
->icmp6_mtu
);
235 printf("icmp6: too big %u", EXTRACT_32BITS(&dp
->icmp6_mtu
));
237 case ICMP6_TIME_EXCEEDED
:
238 TCHECK(oip
->ip6_dst
);
239 switch (dp
->icmp6_code
) {
240 case ICMP6_TIME_EXCEED_TRANSIT
:
241 printf("icmp6: time exceeded in-transit for %s",
242 ip6addr_string(&oip
->ip6_dst
));
244 case ICMP6_TIME_EXCEED_REASSEMBLY
:
245 printf("icmp6: ip6 reassembly time exceeded");
248 printf("icmp6: time exceeded code-#%d",
253 case ICMP6_PARAM_PROB
:
254 TCHECK(oip
->ip6_dst
);
255 switch (dp
->icmp6_code
) {
256 case ICMP6_PARAMPROB_HEADER
:
257 printf("icmp6: parameter problem errorneous - octet %u",
258 EXTRACT_32BITS(&dp
->icmp6_pptr
));
260 case ICMP6_PARAMPROB_NEXTHEADER
:
261 printf("icmp6: parameter problem next header - octet %u",
262 EXTRACT_32BITS(&dp
->icmp6_pptr
));
264 case ICMP6_PARAMPROB_OPTION
:
265 printf("icmp6: parameter problem option - octet %u",
266 EXTRACT_32BITS(&dp
->icmp6_pptr
));
269 printf("icmp6: parameter problem code-#%d",
274 case ICMP6_ECHO_REQUEST
:
275 case ICMP6_ECHO_REPLY
:
276 TCHECK(dp
->icmp6_seq
);
277 printf("icmp6: echo %s seq %u",
278 dp
->icmp6_type
== ICMP6_ECHO_REQUEST
?
280 EXTRACT_16BITS(&dp
->icmp6_seq
));
282 case ICMP6_MEMBERSHIP_QUERY
:
283 printf("icmp6: multicast listener query ");
284 mld6_print((const u_char
*)dp
);
286 case ICMP6_MEMBERSHIP_REPORT
:
287 printf("icmp6: multicast listener report ");
288 mld6_print((const u_char
*)dp
);
290 case ICMP6_MEMBERSHIP_REDUCTION
:
291 printf("icmp6: multicast listener done ");
292 mld6_print((const u_char
*)dp
);
294 case ND_ROUTER_SOLICIT
:
295 printf("icmp6: router solicitation ");
298 icmp6_opt_print((const u_char
*)dp
+ RTSOLLEN
,
302 case ND_ROUTER_ADVERT
:
303 printf("icmp6: router advertisement");
305 struct nd_router_advert
*p
;
307 p
= (struct nd_router_advert
*)dp
;
308 TCHECK(p
->nd_ra_retransmit
);
309 printf("(chlim=%d, ", (int)p
->nd_ra_curhoplimit
);
310 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_MANAGED
)
312 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_OTHER
)
314 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_HOME_AGENT
)
317 if ((p
->nd_ra_flags_reserved
& ~ND_RA_FLAG_RTPREF_MASK
)
322 get_rtpref(p
->nd_ra_flags_reserved
));
324 printf("router_ltime=%d, ", EXTRACT_16BITS(&p
->nd_ra_router_lifetime
));
325 printf("reachable_time=%u, ",
326 EXTRACT_32BITS(&p
->nd_ra_reachable
));
327 printf("retrans_time=%u)",
328 EXTRACT_32BITS(&p
->nd_ra_retransmit
));
330 icmp6_opt_print((const u_char
*)dp
+ RTADVLEN
,
334 case ND_NEIGHBOR_SOLICIT
:
336 struct nd_neighbor_solicit
*p
;
337 p
= (struct nd_neighbor_solicit
*)dp
;
338 TCHECK(p
->nd_ns_target
);
339 printf("icmp6: neighbor sol: who has %s",
340 ip6addr_string(&p
->nd_ns_target
));
343 icmp6_opt_print((const u_char
*)dp
+ NDSOLLEN
,
348 case ND_NEIGHBOR_ADVERT
:
350 struct nd_neighbor_advert
*p
;
352 p
= (struct nd_neighbor_advert
*)dp
;
353 TCHECK(p
->nd_na_target
);
354 printf("icmp6: neighbor adv: tgt is %s",
355 ip6addr_string(&p
->nd_na_target
));
357 #define ND_NA_FLAG_ALL \
358 (ND_NA_FLAG_ROUTER|ND_NA_FLAG_SOLICITED|ND_NA_FLAG_OVERRIDE)
359 /* we don't need ntohl() here. see advanced-api-04. */
360 if (p
->nd_na_flags_reserved
& ND_NA_FLAG_ALL
) {
361 #undef ND_NA_FLAG_ALL
364 flags
= p
->nd_na_flags_reserved
;
366 if (flags
& ND_NA_FLAG_ROUTER
)
368 if (flags
& ND_NA_FLAG_SOLICITED
)
370 if (flags
& ND_NA_FLAG_OVERRIDE
)
375 icmp6_opt_print((const u_char
*)dp
+ NDADVLEN
,
382 #define RDR(i) ((struct nd_redirect *)(i))
383 TCHECK(RDR(dp
)->nd_rd_dst
);
384 printf("icmp6: redirect %s",
385 getname6((const u_char
*)&RDR(dp
)->nd_rd_dst
));
387 getname6((const u_char
*)&RDR(dp
)->nd_rd_target
));
388 #define REDIRECTLEN 40
390 icmp6_opt_print((const u_char
*)dp
+ REDIRECTLEN
,
391 length
- REDIRECTLEN
);
396 case ICMP6_ROUTER_RENUMBERING
:
397 icmp6_rrenum_print(bp
, ep
);
401 icmp6_nodeinfo_print(length
, bp
, ep
);
403 case ICMP6_HADISCOV_REQUEST
:
404 printf("icmp6: ha discovery request");
406 TCHECK(dp
->icmp6_data16
[0]);
407 printf("(id=%d)", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
410 case ICMP6_HADISCOV_REPLY
:
411 printf("icmp6: ha discovery reply");
413 struct in6_addr
*in6
;
416 TCHECK(dp
->icmp6_data16
[0]);
417 printf("(id=%d", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
418 cp
= (u_char
*)dp
+ length
;
419 in6
= (struct in6_addr
*)(dp
+ 1);
420 for (; (u_char
*)in6
< cp
; in6
++) {
422 printf(", %s", ip6addr_string(in6
));
427 case ICMP6_MOBILEPREFIX_SOLICIT
:
428 printf("icmp6: mobile router solicitation");
430 TCHECK(dp
->icmp6_data16
[0]);
431 printf("(id=%d)", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
434 case ICMP6_MOBILEPREFIX_ADVERT
:
435 printf("icmp6: mobile router advertisement");
437 TCHECK(dp
->icmp6_data16
[0]);
438 printf("(id=%d", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
439 if (dp
->icmp6_data16
[1] & 0xc0)
441 if (dp
->icmp6_data16
[1] & 0x80)
443 if (dp
->icmp6_data16
[1] & 0x40)
447 icmp6_opt_print((const u_char
*)dp
+ MPADVLEN
,
452 printf("icmp6: type-#%d", dp
->icmp6_type
);
457 fputs("[|icmp6]", stdout
);
460 static struct udphdr
*
461 get_upperlayer(u_char
*bp
, u_int
*prot
)
464 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
467 struct ip6_frag
*fragh
;
472 /* 'ep' points to the end of available data. */
475 if (!TTEST(ip6
->ip6_nxt
))
479 hlen
= sizeof(struct ip6_hdr
);
481 while (bp
< snapend
) {
487 uh
= (struct udphdr
*)bp
;
488 if (TTEST(uh
->uh_dport
)) {
496 case IPPROTO_HOPOPTS
:
497 case IPPROTO_DSTOPTS
:
498 case IPPROTO_ROUTING
:
499 hbh
= (struct ip6_hbh
*)bp
;
500 if (!TTEST(hbh
->ip6h_len
))
503 hlen
= (hbh
->ip6h_len
+ 1) << 3;
506 case IPPROTO_FRAGMENT
: /* this should be odd, but try anyway */
507 fragh
= (struct ip6_frag
*)bp
;
508 if (!TTEST(fragh
->ip6f_offlg
))
510 /* fragments with non-zero offset are meaningless */
511 if ((EXTRACT_16BITS(&fragh
->ip6f_offlg
) & IP6F_OFF_MASK
) != 0)
513 nh
= fragh
->ip6f_nxt
;
514 hlen
= sizeof(struct ip6_frag
);
518 ah
= (struct ah
*)bp
;
519 if (!TTEST(ah
->ah_len
))
522 hlen
= (ah
->ah_len
+ 2) << 2;
525 default: /* unknown or undecodable header */
526 *prot
= nh
; /* meaningless, but set here anyway */
531 return(NULL
); /* should be notreached, though */
535 icmp6_opt_print(const u_char
*bp
, int resid
)
537 const struct nd_opt_hdr
*op
;
538 const struct nd_opt_hdr
*opl
; /* why there's no struct? */
539 const struct nd_opt_prefix_info
*opp
;
540 const struct icmp6_opts_redirect
*opr
;
541 const struct nd_opt_mtu
*opm
;
542 const struct nd_opt_advinterval
*opa
;
543 const struct nd_opt_homeagent_info
*oph
;
544 const struct nd_opt_route_info
*opri
;
545 const u_char
*cp
, *ep
;
546 struct in6_addr in6
, *in6p
;
549 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
552 /* 'ep' points to the end of available data. */
556 op
= (struct nd_opt_hdr
*)cp
;
558 ECHECK(op
->nd_opt_len
);
561 if (op
->nd_opt_len
== 0)
563 if (cp
+ (op
->nd_opt_len
<< 3) > ep
)
566 switch (op
->nd_opt_type
) {
567 case ND_OPT_SOURCE_LINKADDR
:
568 opl
= (struct nd_opt_hdr
*)op
;
569 printf("(src lladdr: ");
570 l
= (op
->nd_opt_len
<< 3) - 2;
571 print_lladdr(cp
+ 2, l
);
575 case ND_OPT_TARGET_LINKADDR
:
576 opl
= (struct nd_opt_hdr
*)op
;
577 printf("(tgt lladdr: ");
578 l
= (op
->nd_opt_len
<< 3) - 2;
579 print_lladdr(cp
+ 2, l
);
583 case ND_OPT_PREFIX_INFORMATION
:
584 opp
= (struct nd_opt_prefix_info
*)op
;
585 TCHECK(opp
->nd_opt_pi_prefix
);
586 printf("(prefix info: "); /*)*/
587 if (op
->nd_opt_len
!= 4) {
593 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_ONLINK
)
595 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_AUTO
)
597 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_ROUTER
)
599 if (opp
->nd_opt_pi_flags_reserved
)
601 printf("valid_ltime=%s,",
602 get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_valid_time
)));
603 printf("preferred_ltime=%s,",
604 get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_preferred_time
)));
605 printf("prefix=%s/%d",
606 ip6addr_string(&opp
->nd_opt_pi_prefix
),
607 opp
->nd_opt_pi_prefix_len
);
608 if (opp
->nd_opt_pi_len
!= 4)
613 case ND_OPT_REDIRECTED_HEADER
:
614 opr
= (struct icmp6_opts_redirect
*)op
;
615 printf("(redirect)");
619 opm
= (struct nd_opt_mtu
*)op
;
620 TCHECK(opm
->nd_opt_mtu_mtu
);
621 printf("(mtu:"); /*)*/
622 if (op
->nd_opt_len
!= 1) {
628 printf(" mtu=%u", EXTRACT_32BITS(&opm
->nd_opt_mtu_mtu
));
629 if (opm
->nd_opt_mtu_len
!= 1)
633 case ND_OPT_ADVINTERVAL
:
634 opa
= (struct nd_opt_advinterval
*)op
;
635 TCHECK(opa
->nd_opt_adv_interval
);
636 printf("(advint:"); /*)*/
638 EXTRACT_32BITS(&opa
->nd_opt_adv_interval
));
642 case ND_OPT_HOMEAGENT_INFO
:
643 oph
= (struct nd_opt_homeagent_info
*)op
;
644 TCHECK(oph
->nd_opt_hai_lifetime
);
645 printf("(ha info:"); /*)*/
646 printf(" pref=%d", EXTRACT_16BITS(&oph
->nd_opt_hai_preference
));
647 printf(", lifetime=%u", EXTRACT_16BITS(&oph
->nd_opt_hai_lifetime
));
650 case ND_OPT_ROUTE_INFO
:
651 opri
= (struct nd_opt_route_info
*)op
;
652 TCHECK(opri
->nd_opt_rti_lifetime
);
653 memset(&in6
, 0, sizeof(in6
));
654 in6p
= (struct in6_addr
*)(opri
+ 1);
655 switch (op
->nd_opt_len
) {
660 memcpy(&in6
, opri
+ 1, 8);
664 memcpy(&in6
, opri
+ 1, sizeof(in6
));
669 printf("(rtinfo:"); /*)*/
670 printf(" %s/%u", ip6addr_string(&in6
),
671 opri
->nd_opt_rti_prefixlen
);
672 printf(", pref=%s", get_rtpref(opri
->nd_opt_rti_flags
));
673 printf(", lifetime=%s",
674 get_lifetime(EXTRACT_32BITS(&opri
->nd_opt_rti_lifetime
)));
679 printf("(unknown opt_type=%d, opt_len=%d)",
680 op
->nd_opt_type
, op
->nd_opt_len
);
684 cp
+= op
->nd_opt_len
<< 3;
685 resid
-= op
->nd_opt_len
<< 3;
690 fputs("[ndp opt]", stdout
);
696 mld6_print(const u_char
*bp
)
698 struct mld6_hdr
*mp
= (struct mld6_hdr
*)bp
;
701 /* 'ep' points to the end of available data. */
704 if ((u_char
*)mp
+ sizeof(*mp
) > ep
)
707 printf("max resp delay: %d ", EXTRACT_16BITS(&mp
->mld6_maxdelay
));
708 printf("addr: %s", ip6addr_string(&mp
->mld6_addr
));
712 dnsname_print(const u_char
*cp
, const u_char
*ep
)
716 /* DNS name decoding - no decompression */
725 while (i
-- && cp
< ep
) {
729 if (cp
+ 1 < ep
&& *cp
)
735 } else if (cp
+ 1 == ep
&& *cp
== '\0') {
748 icmp6_nodeinfo_print(u_int icmp6len
, const u_char
*bp
, const u_char
*ep
)
750 struct icmp6_nodeinfo
*ni6
;
751 struct icmp6_hdr
*dp
;
758 dp
= (struct icmp6_hdr
*)bp
;
759 ni6
= (struct icmp6_nodeinfo
*)bp
;
762 switch (ni6
->ni_type
) {
764 if (siz
== sizeof(*dp
) + 4) {
765 /* KAME who-are-you */
766 printf("icmp6: who-are-you request");
769 printf("icmp6: node information query");
771 TCHECK2(*dp
, sizeof(*ni6
));
772 ni6
= (struct icmp6_nodeinfo
*)dp
;
774 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
778 case NI_QTYPE_SUPTYPES
:
779 printf("supported qtypes");
780 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
782 printf(" [%s]", (i
& 0x01) ? "C" : "");
788 case NI_QTYPE_NODEADDR
:
789 printf("node addresses");
793 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
794 printf(" [%s%s%s%s%s%s]",
795 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
796 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
797 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
798 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
799 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
800 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "");
807 if (ni6
->ni_qtype
== NI_QTYPE_NOOP
||
808 ni6
->ni_qtype
== NI_QTYPE_SUPTYPES
) {
809 if (siz
!= sizeof(*ni6
))
811 printf(", invalid len");
818 /* XXX backward compat, icmp-name-lookup-03 */
819 if (siz
== sizeof(*ni6
)) {
820 printf(", 03 draft");
826 switch (ni6
->ni_code
) {
827 case ICMP6_NI_SUBJ_IPV6
:
829 sizeof(*ni6
) + sizeof(struct in6_addr
)))
831 if (siz
!= sizeof(*ni6
) + sizeof(struct in6_addr
)) {
833 printf(", invalid subject len");
836 printf(", subject=%s",
837 getname6((const u_char
*)(ni6
+ 1)));
839 case ICMP6_NI_SUBJ_FQDN
:
840 printf(", subject=DNS name");
841 cp
= (const u_char
*)(ni6
+ 1);
842 if (cp
[0] == ep
- cp
- 1) {
843 /* icmp-name-lookup-03, pascal string */
845 printf(", 03 draft");
854 dnsname_print(cp
, ep
);
856 case ICMP6_NI_SUBJ_IPV4
:
857 if (!TTEST2(*dp
, sizeof(*ni6
) + sizeof(struct in_addr
)))
859 if (siz
!= sizeof(*ni6
) + sizeof(struct in_addr
)) {
861 printf(", invalid subject len");
864 printf(", subject=%s",
865 getname((const u_char
*)(ni6
+ 1)));
868 printf(", unknown subject");
877 if (icmp6len
> siz
) {
878 printf("[|icmp6: node information reply]");
884 ni6
= (struct icmp6_nodeinfo
*)dp
;
885 printf("icmp6: node information reply");
887 switch (ni6
->ni_code
) {
888 case ICMP6_NI_SUCCESS
:
894 case ICMP6_NI_REFUSED
:
897 if (siz
!= sizeof(*ni6
))
899 printf(", invalid length");
901 case ICMP6_NI_UNKNOWN
:
904 if (siz
!= sizeof(*ni6
))
906 printf(", invalid length");
910 if (ni6
->ni_code
!= ICMP6_NI_SUCCESS
) {
916 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
921 if (siz
!= sizeof(*ni6
))
923 printf(", invalid length");
925 case NI_QTYPE_SUPTYPES
:
928 printf("supported qtypes");
929 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
931 printf(" [%s]", (i
& 0x01) ? "C" : "");
937 cp
= (const u_char
*)(ni6
+ 1) + 4;
938 if (cp
[0] == ep
- cp
- 1) {
939 /* icmp-name-lookup-03, pascal string */
941 printf(", 03 draft");
950 dnsname_print(cp
, ep
);
951 if ((EXTRACT_16BITS(&ni6
->ni_flags
) & 0x01) != 0)
952 printf(" [TTL=%u]", *(u_int32_t
*)(ni6
+ 1));
954 case NI_QTYPE_NODEADDR
:
957 printf("node addresses");
960 if (i
+ sizeof(struct in6_addr
) + sizeof(int32_t) > siz
)
962 printf(" %s", getname6(bp
+ i
));
963 i
+= sizeof(struct in6_addr
);
964 printf("(%d)", (int32_t)EXTRACT_32BITS(bp
+ i
));
965 i
+= sizeof(int32_t);
970 printf(" [%s%s%s%s%s%s%s]",
971 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
972 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
973 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
974 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
975 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
976 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "",
977 (i
& NI_NODEADDR_FLAG_TRUNCATE
) ? "T" : "");
993 fputs("[|icmp6]", stdout
);
997 icmp6_rrenum_print(const u_char
*bp
, const u_char
*ep
)
999 struct icmp6_router_renum
*rr6
;
1000 struct icmp6_hdr
*dp
;
1003 struct rr_pco_match
*match
;
1004 struct rr_pco_use
*use
;
1005 char hbuf
[NI_MAXHOST
];
1010 dp
= (struct icmp6_hdr
*)bp
;
1011 rr6
= (struct icmp6_router_renum
*)bp
;
1013 cp
= (const char *)(rr6
+ 1);
1015 TCHECK(rr6
->rr_reserved
);
1016 switch (rr6
->rr_code
) {
1017 case ICMP6_ROUTER_RENUMBERING_COMMAND
:
1018 printf("router renum: command");
1020 case ICMP6_ROUTER_RENUMBERING_RESULT
:
1021 printf("router renum: result");
1023 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
:
1024 printf("router renum: sequence number reset");
1027 printf("router renum: code-#%d", rr6
->rr_code
);
1031 printf(", seq=%u", EXTRACT_32BITS(&rr6
->rr_seqnum
));
1034 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1036 if (rr6
->rr_flags
) {
1037 printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST
, "T"),
1038 F(ICMP6_RR_FLAGS_REQRESULT
, "R"),
1039 F(ICMP6_RR_FLAGS_FORCEAPPLY
, "A"),
1040 F(ICMP6_RR_FLAGS_SPECSITE
, "S"),
1041 F(ICMP6_RR_FLAGS_PREVDONE
, "P"));
1043 printf("seg=%u,", rr6
->rr_segnum
);
1044 printf("maxdelay=%u", rr6
->rr_maxdelay
);
1045 if (rr6
->rr_reserved
)
1046 printf("rsvd=0x%x", EXTRACT_16BITS(&rr6
->rr_reserved
));
1052 if (rr6
->rr_code
== ICMP6_ROUTER_RENUMBERING_COMMAND
) {
1053 match
= (struct rr_pco_match
*)cp
;
1054 cp
= (const char *)(match
+ 1);
1056 TCHECK(match
->rpm_prefix
);
1062 printf("match("); /*)*/
1063 switch (match
->rpm_code
) {
1064 case RPM_PCO_ADD
: printf("add"); break;
1065 case RPM_PCO_CHANGE
: printf("change"); break;
1066 case RPM_PCO_SETGLOBAL
: printf("setglobal"); break;
1067 default: printf("#%u", match
->rpm_code
); break;
1071 printf(",ord=%u", match
->rpm_ordinal
);
1072 printf(",min=%u", match
->rpm_minlen
);
1073 printf(",max=%u", match
->rpm_maxlen
);
1075 if (inet_ntop(AF_INET6
, &match
->rpm_prefix
, hbuf
, sizeof(hbuf
)))
1076 printf(",%s/%u", hbuf
, match
->rpm_matchlen
);
1078 printf(",?/%u", match
->rpm_matchlen
);
1082 n
= match
->rpm_len
- 3;
1087 use
= (struct rr_pco_use
*)cp
;
1088 cp
= (const char *)(use
+ 1);
1090 TCHECK(use
->rpu_prefix
);
1096 printf("use("); /*)*/
1097 if (use
->rpu_flags
) {
1098 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1100 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
, "V"),
1101 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
, "P"));
1105 printf("mask=0x%x,", use
->rpu_ramask
);
1106 printf("raflags=0x%x,", use
->rpu_raflags
);
1107 if (~use
->rpu_vltime
== 0)
1108 printf("vltime=infty,");
1110 printf("vltime=%u,",
1111 EXTRACT_32BITS(&use
->rpu_vltime
));
1112 if (~use
->rpu_pltime
== 0)
1113 printf("pltime=infty,");
1115 printf("pltime=%u,",
1116 EXTRACT_32BITS(&use
->rpu_pltime
));
1118 if (inet_ntop(AF_INET6
, &use
->rpu_prefix
, hbuf
,
1120 printf("%s/%u/%u", hbuf
, use
->rpu_uselen
,
1123 printf("?/%u/%u", use
->rpu_uselen
,
1133 fputs("[|icmp6]", stdout
);