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
[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.70 2003-05-02 08:13:55 itojun Exp $";
33 #include <tcpdump-stdinc.h>
41 #include "interface.h"
42 #include "addrtoname.h"
48 static const char *get_rtpref(u_int
);
49 static const char *get_lifetime(u_int32_t
);
50 static void print_lladdr(const u_char
*, size_t);
51 static void icmp6_opt_print(const u_char
*, int);
52 static void mld6_print(const u_char
*);
53 static struct udphdr
*get_upperlayer(u_char
*, u_int
*);
54 static void dnsname_print(const u_char
*, const u_char
*);
55 static void icmp6_nodeinfo_print(u_int
, const u_char
*, const u_char
*);
56 static void icmp6_rrenum_print(u_int
, const u_char
*, const u_char
*);
59 #define abs(a) ((0 < (a)) ? (a) : -(a))
65 static const char *rtpref_str
[] = {
72 return rtpref_str
[((v
& ND_RA_FLAG_RTPREF_MASK
) >> 3) & 0xff];
76 get_lifetime(u_int32_t v
)
80 if (v
== (u_int32_t
)~0UL)
83 snprintf(buf
, sizeof(buf
), "%u", v
);
89 print_lladdr(const u_int8_t
*p
, size_t l
)
91 const u_int8_t
*ep
, *q
;
95 while (l
> 0 && q
< ep
) {
103 static int icmp6_cksum(const struct ip6_hdr
*ip6
, const struct icmp6_hdr
*icp
,
107 register const u_int16_t
*sp
;
111 struct in6_addr ph_src
;
112 struct in6_addr ph_dst
;
121 memset(&phu
, 0, sizeof(phu
));
122 phu
.ph
.ph_src
= ip6
->ip6_src
;
123 phu
.ph
.ph_dst
= ip6
->ip6_dst
;
124 phu
.ph
.ph_len
= htonl(len
);
125 phu
.ph
.ph_nxt
= IPPROTO_ICMPV6
;
128 for (i
= 0; i
< sizeof(phu
.pa
) / sizeof(phu
.pa
[0]); i
++)
131 sp
= (const u_int16_t
*)icp
;
133 for (i
= 0; i
< (len
& ~1); i
+= 2)
137 sum
+= htons((*(const u_int8_t
*)sp
) << 8);
140 sum
= (sum
& 0xffff) + (sum
>> 16);
147 icmp6_print(const u_char
*bp
, const u_char
*bp2
, int fragmented
)
149 const struct icmp6_hdr
*dp
;
150 const struct ip6_hdr
*ip
;
152 const struct ip6_hdr
*oip
;
153 const struct udphdr
*ouh
;
157 u_int icmp6len
, prot
;
159 dp
= (struct icmp6_hdr
*)bp
;
160 ip
= (struct ip6_hdr
*)bp2
;
161 oip
= (struct ip6_hdr
*)(dp
+ 1);
163 /* 'ep' points to the end of available data. */
166 icmp6len
= (EXTRACT_16BITS(&ip
->ip6_plen
) + sizeof(struct ip6_hdr
) -
168 else /* XXX: jumbo payload case... */
169 icmp6len
= snapend
- bp
;
171 TCHECK(dp
->icmp6_cksum
);
173 if (vflag
&& !fragmented
) {
174 int sum
= dp
->icmp6_cksum
;
176 if (TTEST2(bp
[0], icmp6len
)) {
177 sum
= icmp6_cksum(ip
, dp
, icmp6len
);
179 (void)printf("[bad icmp6 cksum %x!] ", sum
);
181 (void)printf("[icmp6 sum ok] ");
185 switch (dp
->icmp6_type
) {
186 case ICMP6_DST_UNREACH
:
187 TCHECK(oip
->ip6_dst
);
188 switch (dp
->icmp6_code
) {
189 case ICMP6_DST_UNREACH_NOROUTE
:
190 printf("icmp6: %s unreachable route",
191 ip6addr_string(&oip
->ip6_dst
));
193 case ICMP6_DST_UNREACH_ADMIN
:
194 printf("icmp6: %s unreachable prohibited",
195 ip6addr_string(&oip
->ip6_dst
));
197 case ICMP6_DST_UNREACH_BEYONDSCOPE
:
198 printf("icmp6: %s beyond scope of source address %s",
199 ip6addr_string(&oip
->ip6_dst
),
200 ip6addr_string(&oip
->ip6_src
));
202 case ICMP6_DST_UNREACH_ADDR
:
203 printf("icmp6: %s unreachable address",
204 ip6addr_string(&oip
->ip6_dst
));
206 case ICMP6_DST_UNREACH_NOPORT
:
207 if ((ouh
= get_upperlayer((u_char
*)oip
, &prot
))
211 dport
= EXTRACT_16BITS(&ouh
->uh_dport
);
214 printf("icmp6: %s tcp port %s unreachable",
215 ip6addr_string(&oip
->ip6_dst
),
216 tcpport_string(dport
));
219 printf("icmp6: %s udp port %s unreachable",
220 ip6addr_string(&oip
->ip6_dst
),
221 udpport_string(dport
));
224 printf("icmp6: %s protocol %d port %d unreachable",
225 ip6addr_string(&oip
->ip6_dst
),
226 oip
->ip6_nxt
, dport
);
231 printf("icmp6: %s unreachable code-#%d",
232 ip6addr_string(&oip
->ip6_dst
),
237 case ICMP6_PACKET_TOO_BIG
:
238 TCHECK(dp
->icmp6_mtu
);
239 printf("icmp6: too big %u", EXTRACT_32BITS(&dp
->icmp6_mtu
));
241 case ICMP6_TIME_EXCEEDED
:
242 TCHECK(oip
->ip6_dst
);
243 switch (dp
->icmp6_code
) {
244 case ICMP6_TIME_EXCEED_TRANSIT
:
245 printf("icmp6: time exceeded in-transit for %s",
246 ip6addr_string(&oip
->ip6_dst
));
248 case ICMP6_TIME_EXCEED_REASSEMBLY
:
249 printf("icmp6: ip6 reassembly time exceeded");
252 printf("icmp6: time exceeded code-#%d",
257 case ICMP6_PARAM_PROB
:
258 TCHECK(oip
->ip6_dst
);
259 switch (dp
->icmp6_code
) {
260 case ICMP6_PARAMPROB_HEADER
:
261 printf("icmp6: parameter problem errorneous - octet %u",
262 EXTRACT_32BITS(&dp
->icmp6_pptr
));
264 case ICMP6_PARAMPROB_NEXTHEADER
:
265 printf("icmp6: parameter problem next header - octet %u",
266 EXTRACT_32BITS(&dp
->icmp6_pptr
));
268 case ICMP6_PARAMPROB_OPTION
:
269 printf("icmp6: parameter problem option - octet %u",
270 EXTRACT_32BITS(&dp
->icmp6_pptr
));
273 printf("icmp6: parameter problem code-#%d",
278 case ICMP6_ECHO_REQUEST
:
279 case ICMP6_ECHO_REPLY
:
280 TCHECK(dp
->icmp6_seq
);
281 printf("icmp6: echo %s seq %u",
282 dp
->icmp6_type
== ICMP6_ECHO_REQUEST
?
284 EXTRACT_16BITS(&dp
->icmp6_seq
));
286 case ICMP6_MEMBERSHIP_QUERY
:
287 printf("icmp6: multicast listener query ");
288 mld6_print((const u_char
*)dp
);
290 case ICMP6_MEMBERSHIP_REPORT
:
291 printf("icmp6: multicast listener report ");
292 mld6_print((const u_char
*)dp
);
294 case ICMP6_MEMBERSHIP_REDUCTION
:
295 printf("icmp6: multicast listener done ");
296 mld6_print((const u_char
*)dp
);
298 case ND_ROUTER_SOLICIT
:
299 printf("icmp6: router solicitation ");
302 icmp6_opt_print((const u_char
*)dp
+ RTSOLLEN
,
303 icmp6len
- RTSOLLEN
);
306 case ND_ROUTER_ADVERT
:
307 printf("icmp6: router advertisement");
309 struct nd_router_advert
*p
;
311 p
= (struct nd_router_advert
*)dp
;
312 TCHECK(p
->nd_ra_retransmit
);
313 printf("(chlim=%d, ", (int)p
->nd_ra_curhoplimit
);
314 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_MANAGED
)
316 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_OTHER
)
318 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_HOME_AGENT
)
321 if ((p
->nd_ra_flags_reserved
& ~ND_RA_FLAG_RTPREF_MASK
)
326 get_rtpref(p
->nd_ra_flags_reserved
));
328 printf("router_ltime=%d, ", EXTRACT_16BITS(&p
->nd_ra_router_lifetime
));
329 printf("reachable_time=%u, ",
330 EXTRACT_32BITS(&p
->nd_ra_reachable
));
331 printf("retrans_time=%u)",
332 EXTRACT_32BITS(&p
->nd_ra_retransmit
));
334 icmp6_opt_print((const u_char
*)dp
+ RTADVLEN
,
335 icmp6len
- RTADVLEN
);
338 case ND_NEIGHBOR_SOLICIT
:
340 struct nd_neighbor_solicit
*p
;
341 p
= (struct nd_neighbor_solicit
*)dp
;
342 TCHECK(p
->nd_ns_target
);
343 printf("icmp6: neighbor sol: who has %s",
344 ip6addr_string(&p
->nd_ns_target
));
347 icmp6_opt_print((const u_char
*)dp
+ NDSOLLEN
,
348 icmp6len
- NDSOLLEN
);
352 case ND_NEIGHBOR_ADVERT
:
354 struct nd_neighbor_advert
*p
;
356 p
= (struct nd_neighbor_advert
*)dp
;
357 TCHECK(p
->nd_na_target
);
358 printf("icmp6: neighbor adv: tgt is %s",
359 ip6addr_string(&p
->nd_na_target
));
361 #define ND_NA_FLAG_ALL \
362 (ND_NA_FLAG_ROUTER|ND_NA_FLAG_SOLICITED|ND_NA_FLAG_OVERRIDE)
363 /* we don't need ntohl() here. see advanced-api-04. */
364 if (p
->nd_na_flags_reserved
& ND_NA_FLAG_ALL
) {
365 #undef ND_NA_FLAG_ALL
368 flags
= p
->nd_na_flags_reserved
;
370 if (flags
& ND_NA_FLAG_ROUTER
)
372 if (flags
& ND_NA_FLAG_SOLICITED
)
374 if (flags
& ND_NA_FLAG_OVERRIDE
)
379 icmp6_opt_print((const u_char
*)dp
+ NDADVLEN
,
380 icmp6len
- NDADVLEN
);
386 #define RDR(i) ((struct nd_redirect *)(i))
387 TCHECK(RDR(dp
)->nd_rd_dst
);
388 printf("icmp6: redirect %s",
389 getname6((const u_char
*)&RDR(dp
)->nd_rd_dst
));
391 getname6((const u_char
*)&RDR(dp
)->nd_rd_target
));
392 #define REDIRECTLEN 40
394 icmp6_opt_print((const u_char
*)dp
+ REDIRECTLEN
,
395 icmp6len
- REDIRECTLEN
);
400 case ICMP6_ROUTER_RENUMBERING
:
401 icmp6_rrenum_print(icmp6len
, bp
, ep
);
405 icmp6_nodeinfo_print(icmp6len
, bp
, ep
);
407 case ICMP6_HADISCOV_REQUEST
:
408 printf("icmp6: ha discovery request");
410 TCHECK(dp
->icmp6_data16
[0]);
411 printf("(id=%d)", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
414 case ICMP6_HADISCOV_REPLY
:
415 printf("icmp6: ha discovery reply");
417 struct in6_addr
*in6
;
420 TCHECK(dp
->icmp6_data16
[0]);
421 printf("(id=%d", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
422 cp
= (u_char
*)dp
+ icmp6len
;
423 in6
= (struct in6_addr
*)(dp
+ 1);
424 for (; (u_char
*)in6
< cp
; in6
++) {
426 printf(", %s", ip6addr_string(in6
));
431 case ICMP6_MOBILEPREFIX_SOLICIT
:
432 printf("icmp6: mobile router solicitation");
434 TCHECK(dp
->icmp6_data16
[0]);
435 printf("(id=%d)", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
438 case ICMP6_MOBILEPREFIX_ADVERT
:
439 printf("icmp6: mobile router advertisement");
441 TCHECK(dp
->icmp6_data16
[0]);
442 printf("(id=%d", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
443 if (dp
->icmp6_data16
[1] & 0xc0)
445 if (dp
->icmp6_data16
[1] & 0x80)
447 if (dp
->icmp6_data16
[1] & 0x40)
451 icmp6_opt_print((const u_char
*)dp
+ MPADVLEN
,
452 icmp6len
- MPADVLEN
);
456 printf("icmp6: type-#%d", dp
->icmp6_type
);
461 fputs("[|icmp6]", stdout
);
464 static struct udphdr
*
465 get_upperlayer(u_char
*bp
, u_int
*prot
)
468 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
471 struct ip6_frag
*fragh
;
476 /* 'ep' points to the end of available data. */
479 if (!TTEST(ip6
->ip6_nxt
))
483 hlen
= sizeof(struct ip6_hdr
);
485 while (bp
< snapend
) {
491 uh
= (struct udphdr
*)bp
;
492 if (TTEST(uh
->uh_dport
)) {
500 case IPPROTO_HOPOPTS
:
501 case IPPROTO_DSTOPTS
:
502 case IPPROTO_ROUTING
:
503 hbh
= (struct ip6_hbh
*)bp
;
504 if (!TTEST(hbh
->ip6h_len
))
507 hlen
= (hbh
->ip6h_len
+ 1) << 3;
510 case IPPROTO_FRAGMENT
: /* this should be odd, but try anyway */
511 fragh
= (struct ip6_frag
*)bp
;
512 if (!TTEST(fragh
->ip6f_offlg
))
514 /* fragments with non-zero offset are meaningless */
515 if ((EXTRACT_16BITS(&fragh
->ip6f_offlg
) & IP6F_OFF_MASK
) != 0)
517 nh
= fragh
->ip6f_nxt
;
518 hlen
= sizeof(struct ip6_frag
);
522 ah
= (struct ah
*)bp
;
523 if (!TTEST(ah
->ah_len
))
526 hlen
= (ah
->ah_len
+ 2) << 2;
529 default: /* unknown or undecodable header */
530 *prot
= nh
; /* meaningless, but set here anyway */
535 return(NULL
); /* should be notreached, though */
539 icmp6_opt_print(const u_char
*bp
, int resid
)
541 const struct nd_opt_hdr
*op
;
542 const struct nd_opt_hdr
*opl
; /* why there's no struct? */
543 const struct nd_opt_prefix_info
*opp
;
544 const struct icmp6_opts_redirect
*opr
;
545 const struct nd_opt_mtu
*opm
;
546 const struct nd_opt_advinterval
*opa
;
547 const struct nd_opt_homeagent_info
*oph
;
548 const struct nd_opt_route_info
*opri
;
549 const u_char
*cp
, *ep
;
550 struct in6_addr in6
, *in6p
;
553 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
556 /* 'ep' points to the end of available data. */
560 op
= (struct nd_opt_hdr
*)cp
;
562 ECHECK(op
->nd_opt_len
);
565 if (op
->nd_opt_len
== 0)
567 if (cp
+ (op
->nd_opt_len
<< 3) > ep
)
570 switch (op
->nd_opt_type
) {
571 case ND_OPT_SOURCE_LINKADDR
:
572 opl
= (struct nd_opt_hdr
*)op
;
573 printf("(src lladdr: ");
574 l
= (op
->nd_opt_len
<< 3) - 2;
575 print_lladdr(cp
+ 2, l
);
579 case ND_OPT_TARGET_LINKADDR
:
580 opl
= (struct nd_opt_hdr
*)op
;
581 printf("(tgt lladdr: ");
582 l
= (op
->nd_opt_len
<< 3) - 2;
583 print_lladdr(cp
+ 2, l
);
587 case ND_OPT_PREFIX_INFORMATION
:
588 opp
= (struct nd_opt_prefix_info
*)op
;
589 TCHECK(opp
->nd_opt_pi_prefix
);
590 printf("(prefix info: "); /*)*/
591 if (op
->nd_opt_len
!= 4) {
597 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_ONLINK
)
599 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_AUTO
)
601 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_ROUTER
)
603 if (opp
->nd_opt_pi_flags_reserved
)
605 printf("valid_ltime=%s,",
606 get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_valid_time
)));
607 printf("preferred_ltime=%s,",
608 get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_preferred_time
)));
609 printf("prefix=%s/%d",
610 ip6addr_string(&opp
->nd_opt_pi_prefix
),
611 opp
->nd_opt_pi_prefix_len
);
612 if (opp
->nd_opt_pi_len
!= 4)
617 case ND_OPT_REDIRECTED_HEADER
:
618 opr
= (struct icmp6_opts_redirect
*)op
;
619 printf("(redirect)");
623 opm
= (struct nd_opt_mtu
*)op
;
624 TCHECK(opm
->nd_opt_mtu_mtu
);
625 printf("(mtu:"); /*)*/
626 if (op
->nd_opt_len
!= 1) {
632 printf(" mtu=%u", EXTRACT_32BITS(&opm
->nd_opt_mtu_mtu
));
633 if (opm
->nd_opt_mtu_len
!= 1)
637 case ND_OPT_ADVINTERVAL
:
638 opa
= (struct nd_opt_advinterval
*)op
;
639 TCHECK(opa
->nd_opt_adv_interval
);
640 printf("(advint:"); /*)*/
642 EXTRACT_32BITS(&opa
->nd_opt_adv_interval
));
646 case ND_OPT_HOMEAGENT_INFO
:
647 oph
= (struct nd_opt_homeagent_info
*)op
;
648 TCHECK(oph
->nd_opt_hai_lifetime
);
649 printf("(ha info:"); /*)*/
650 printf(" pref=%d", EXTRACT_16BITS(&oph
->nd_opt_hai_preference
));
651 printf(", lifetime=%u", EXTRACT_16BITS(&oph
->nd_opt_hai_lifetime
));
654 case ND_OPT_ROUTE_INFO
:
655 opri
= (struct nd_opt_route_info
*)op
;
656 TCHECK(opri
->nd_opt_rti_lifetime
);
657 memset(&in6
, 0, sizeof(in6
));
658 in6p
= (struct in6_addr
*)(opri
+ 1);
659 switch (op
->nd_opt_len
) {
664 memcpy(&in6
, opri
+ 1, 8);
668 memcpy(&in6
, opri
+ 1, sizeof(in6
));
673 printf("(rtinfo:"); /*)*/
674 printf(" %s/%u", ip6addr_string(&in6
),
675 opri
->nd_opt_rti_prefixlen
);
676 printf(", pref=%s", get_rtpref(opri
->nd_opt_rti_flags
));
677 printf(", lifetime=%s",
678 get_lifetime(EXTRACT_32BITS(&opri
->nd_opt_rti_lifetime
)));
683 printf("(unknown opt_type=%d, opt_len=%d)",
684 op
->nd_opt_type
, op
->nd_opt_len
);
688 cp
+= op
->nd_opt_len
<< 3;
689 resid
-= op
->nd_opt_len
<< 3;
694 fputs("[ndp opt]", stdout
);
700 mld6_print(const u_char
*bp
)
702 struct mld6_hdr
*mp
= (struct mld6_hdr
*)bp
;
705 /* 'ep' points to the end of available data. */
708 if ((u_char
*)mp
+ sizeof(*mp
) > ep
)
711 printf("max resp delay: %d ", EXTRACT_16BITS(&mp
->mld6_maxdelay
));
712 printf("addr: %s", ip6addr_string(&mp
->mld6_addr
));
716 dnsname_print(const u_char
*cp
, const u_char
*ep
)
720 /* DNS name decoding - no decompression */
729 while (i
-- && cp
< ep
) {
733 if (cp
+ 1 < ep
&& *cp
)
739 } else if (cp
+ 1 == ep
&& *cp
== '\0') {
752 icmp6_nodeinfo_print(u_int icmp6len
, const u_char
*bp
, const u_char
*ep
)
754 struct icmp6_nodeinfo
*ni6
;
755 struct icmp6_hdr
*dp
;
762 dp
= (struct icmp6_hdr
*)bp
;
763 ni6
= (struct icmp6_nodeinfo
*)bp
;
766 switch (ni6
->ni_type
) {
768 if (siz
== sizeof(*dp
) + 4) {
769 /* KAME who-are-you */
770 printf("icmp6: who-are-you request");
773 printf("icmp6: node information query");
775 TCHECK2(*dp
, sizeof(*ni6
));
776 ni6
= (struct icmp6_nodeinfo
*)dp
;
778 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
782 case NI_QTYPE_SUPTYPES
:
783 printf("supported qtypes");
784 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
786 printf(" [%s]", (i
& 0x01) ? "C" : "");
792 case NI_QTYPE_NODEADDR
:
793 printf("node addresses");
797 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
798 printf(" [%s%s%s%s%s%s]",
799 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
800 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
801 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
802 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
803 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
804 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "");
811 if (ni6
->ni_qtype
== NI_QTYPE_NOOP
||
812 ni6
->ni_qtype
== NI_QTYPE_SUPTYPES
) {
813 if (siz
!= sizeof(*ni6
))
815 printf(", invalid len");
822 /* XXX backward compat, icmp-name-lookup-03 */
823 if (siz
== sizeof(*ni6
)) {
824 printf(", 03 draft");
830 switch (ni6
->ni_code
) {
831 case ICMP6_NI_SUBJ_IPV6
:
833 sizeof(*ni6
) + sizeof(struct in6_addr
)))
835 if (siz
!= sizeof(*ni6
) + sizeof(struct in6_addr
)) {
837 printf(", invalid subject len");
840 printf(", subject=%s",
841 getname6((const u_char
*)(ni6
+ 1)));
843 case ICMP6_NI_SUBJ_FQDN
:
844 printf(", subject=DNS name");
845 cp
= (const u_char
*)(ni6
+ 1);
846 if (cp
[0] == ep
- cp
- 1) {
847 /* icmp-name-lookup-03, pascal string */
849 printf(", 03 draft");
858 dnsname_print(cp
, ep
);
860 case ICMP6_NI_SUBJ_IPV4
:
861 if (!TTEST2(*dp
, sizeof(*ni6
) + sizeof(struct in_addr
)))
863 if (siz
!= sizeof(*ni6
) + sizeof(struct in_addr
)) {
865 printf(", invalid subject len");
868 printf(", subject=%s",
869 getname((const u_char
*)(ni6
+ 1)));
872 printf(", unknown subject");
881 if (icmp6len
> siz
) {
882 printf("[|icmp6: node information reply]");
888 ni6
= (struct icmp6_nodeinfo
*)dp
;
889 printf("icmp6: node information reply");
891 switch (ni6
->ni_code
) {
892 case ICMP6_NI_SUCCESS
:
898 case ICMP6_NI_REFUSED
:
901 if (siz
!= sizeof(*ni6
))
903 printf(", invalid length");
905 case ICMP6_NI_UNKNOWN
:
908 if (siz
!= sizeof(*ni6
))
910 printf(", invalid length");
914 if (ni6
->ni_code
!= ICMP6_NI_SUCCESS
) {
920 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
925 if (siz
!= sizeof(*ni6
))
927 printf(", invalid length");
929 case NI_QTYPE_SUPTYPES
:
932 printf("supported qtypes");
933 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
935 printf(" [%s]", (i
& 0x01) ? "C" : "");
941 cp
= (const u_char
*)(ni6
+ 1) + 4;
942 if (cp
[0] == ep
- cp
- 1) {
943 /* icmp-name-lookup-03, pascal string */
945 printf(", 03 draft");
954 dnsname_print(cp
, ep
);
955 if ((EXTRACT_16BITS(&ni6
->ni_flags
) & 0x01) != 0)
956 printf(" [TTL=%u]", *(u_int32_t
*)(ni6
+ 1));
958 case NI_QTYPE_NODEADDR
:
961 printf("node addresses");
964 if (i
+ sizeof(struct in6_addr
) + sizeof(int32_t) > siz
)
966 printf(" %s", getname6(bp
+ i
));
967 i
+= sizeof(struct in6_addr
);
968 printf("(%d)", (int32_t)EXTRACT_32BITS(bp
+ i
));
969 i
+= sizeof(int32_t);
974 printf(" [%s%s%s%s%s%s%s]",
975 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
976 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
977 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
978 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
979 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
980 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "",
981 (i
& NI_NODEADDR_FLAG_TRUNCATE
) ? "T" : "");
997 fputs("[|icmp6]", stdout
);
1001 icmp6_rrenum_print(u_int icmp6len
, const u_char
*bp
, const u_char
*ep
)
1003 struct icmp6_router_renum
*rr6
;
1004 struct icmp6_hdr
*dp
;
1007 struct rr_pco_match
*match
;
1008 struct rr_pco_use
*use
;
1009 char hbuf
[NI_MAXHOST
];
1014 dp
= (struct icmp6_hdr
*)bp
;
1015 rr6
= (struct icmp6_router_renum
*)bp
;
1017 cp
= (const char *)(rr6
+ 1);
1019 TCHECK(rr6
->rr_reserved
);
1020 switch (rr6
->rr_code
) {
1021 case ICMP6_ROUTER_RENUMBERING_COMMAND
:
1022 printf("router renum: command");
1024 case ICMP6_ROUTER_RENUMBERING_RESULT
:
1025 printf("router renum: result");
1027 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
:
1028 printf("router renum: sequence number reset");
1031 printf("router renum: code-#%d", rr6
->rr_code
);
1035 printf(", seq=%u", EXTRACT_32BITS(&rr6
->rr_seqnum
));
1038 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1040 if (rr6
->rr_flags
) {
1041 printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST
, "T"),
1042 F(ICMP6_RR_FLAGS_REQRESULT
, "R"),
1043 F(ICMP6_RR_FLAGS_FORCEAPPLY
, "A"),
1044 F(ICMP6_RR_FLAGS_SPECSITE
, "S"),
1045 F(ICMP6_RR_FLAGS_PREVDONE
, "P"));
1047 printf("seg=%u,", rr6
->rr_segnum
);
1048 printf("maxdelay=%u", rr6
->rr_maxdelay
);
1049 if (rr6
->rr_reserved
)
1050 printf("rsvd=0x%x", EXTRACT_16BITS(&rr6
->rr_reserved
));
1056 if (rr6
->rr_code
== ICMP6_ROUTER_RENUMBERING_COMMAND
) {
1057 match
= (struct rr_pco_match
*)cp
;
1058 cp
= (const char *)(match
+ 1);
1060 TCHECK(match
->rpm_prefix
);
1066 printf("match("); /*)*/
1067 switch (match
->rpm_code
) {
1068 case RPM_PCO_ADD
: printf("add"); break;
1069 case RPM_PCO_CHANGE
: printf("change"); break;
1070 case RPM_PCO_SETGLOBAL
: printf("setglobal"); break;
1071 default: printf("#%u", match
->rpm_code
); break;
1075 printf(",ord=%u", match
->rpm_ordinal
);
1076 printf(",min=%u", match
->rpm_minlen
);
1077 printf(",max=%u", match
->rpm_maxlen
);
1079 if (inet_ntop(AF_INET6
, &match
->rpm_prefix
, hbuf
, sizeof(hbuf
)))
1080 printf(",%s/%u", hbuf
, match
->rpm_matchlen
);
1082 printf(",?/%u", match
->rpm_matchlen
);
1086 n
= match
->rpm_len
- 3;
1091 use
= (struct rr_pco_use
*)cp
;
1092 cp
= (const char *)(use
+ 1);
1094 TCHECK(use
->rpu_prefix
);
1100 printf("use("); /*)*/
1101 if (use
->rpu_flags
) {
1102 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1104 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
, "V"),
1105 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
, "P"));
1109 printf("mask=0x%x,", use
->rpu_ramask
);
1110 printf("raflags=0x%x,", use
->rpu_raflags
);
1111 if (~use
->rpu_vltime
== 0)
1112 printf("vltime=infty,");
1114 printf("vltime=%u,",
1115 EXTRACT_32BITS(&use
->rpu_vltime
));
1116 if (~use
->rpu_pltime
== 0)
1117 printf("pltime=infty,");
1119 printf("pltime=%u,",
1120 EXTRACT_32BITS(&use
->rpu_pltime
));
1122 if (inet_ntop(AF_INET6
, &use
->rpu_prefix
, hbuf
,
1124 printf("%s/%u/%u", hbuf
, use
->rpu_uselen
,
1127 printf("?/%u/%u", use
->rpu_uselen
,
1137 fputs("[|icmp6]", stdout
);