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.30 2000-10-03 02:19:05 itojun Exp $";
35 #include <sys/param.h>
37 #include <sys/types.h>
38 #include <sys/socket.h>
41 #include <netinet/in.h>
43 #include <netinet6/ah.h>
45 #include <arpa/inet.h>
49 #include <netinet/ip6.h>
50 #include <netinet/icmp6.h>
52 #include "interface.h"
53 #include "addrtoname.h"
57 void icmp6_opt_print(const u_char
*, int);
58 void mld6_print(const u_char
*);
59 static struct udphdr
*get_upperlayer(u_char
*, int *);
60 #ifdef HAVE_STRUCT_ICMP6_NODEINFO
61 static void dnsname_print(const u_char
*, const u_char
*);
62 void icmp6_nodeinfo_print(int, const u_char
*, const u_char
*);
66 #define abs(a) ((0 < (a)) ? (a) : -(a))
69 #ifndef HAVE_STRUCT_ICMP6_NODEINFO
70 struct icmp6_nodeinfo
{
71 struct icmp6_hdr icmp6_ni_hdr
;
72 u_int8_t icmp6_ni_nonce
[8];
73 /* could be followed by reply data */
76 #define ni_type icmp6_ni_hdr.icmp6_type
77 #define ni_code icmp6_ni_hdr.icmp6_code
78 #define ni_cksum icmp6_ni_hdr.icmp6_cksum
79 #define ni_qtype icmp6_ni_hdr.icmp6_data16[0]
80 #define ni_flags icmp6_ni_hdr.icmp6_data16[1]
83 /* cope with past KAME typo - shipped with freebsd4[01] and openbsd27 */
84 #if defined(ICMP6_NI_SUCESS) && !defined(ICMP6_NI_SUCCESS)
85 #define ICMP6_NI_SUCCESS ICMP6_NI_SUCESS
87 #ifndef ICMP6_NI_SUCCESS
88 #define ICMP6_NI_SUCCESS 0 /* node information successful reply */
89 #define ICMP6_NI_REFUSED 1 /* node information request is refused */
90 #define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */
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... */
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 */
107 icmp6_print(register const u_char
*bp
, register const u_char
*bp2
)
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
;
120 #define TCHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) goto trunc
123 dp
= (struct icmp6_hdr
*)bp
;
124 ip
= (struct ip6_hdr
*)bp2
;
125 oip
= (struct ip6_hdr
*)(dp
+ 1);
127 /* 'ep' points to the end of available data. */
130 icmp6len
= (ntohs(ip
->ip6_plen
) + sizeof(struct ip6_hdr
) -
132 else /* XXX: jumbo payload case... */
133 icmp6len
= snapend
- bp
;
136 (void)printf("%s > %s: ",
137 ip6addr_string(&ip
->ip6_src
),
138 ip6addr_string(&ip
->ip6_dst
));
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
));
150 case ICMP6_DST_UNREACH_ADMIN
:
151 printf("icmp6: %s unreachable prohibited",
152 ip6addr_string(&oip
->ip6_dst
));
154 #ifdef ICMP6_DST_UNREACH_BEYONDSCOPE
155 case ICMP6_DST_UNREACH_BEYONDSCOPE
:
157 case ICMP6_DST_UNREACH_NOTNEIGHBOR
:
159 printf("icmp6: %s beyond scope of source address %s",
160 ip6addr_string(&oip
->ip6_dst
),
161 ip6addr_string(&oip
->ip6_src
));
163 case ICMP6_DST_UNREACH_ADDR
:
164 printf("icmp6: %s unreachable address",
165 ip6addr_string(&oip
->ip6_dst
));
167 case ICMP6_DST_UNREACH_NOPORT
:
168 if ((ouh
= get_upperlayer((u_char
*)oip
, &prot
))
172 dport
= ntohs(ouh
->uh_dport
);
175 printf("icmp6: %s tcp port %s unreachable",
176 ip6addr_string(&oip
->ip6_dst
),
177 tcpport_string(dport
));
180 printf("icmp6: %s udp port %s unreachable",
181 ip6addr_string(&oip
->ip6_dst
),
182 udpport_string(dport
));
185 printf("icmp6: %s protocol %d port %d unreachable",
186 ip6addr_string(&oip
->ip6_dst
),
187 oip
->ip6_nxt
, dport
);
192 printf("icmp6: %s unreachable code-#%d",
193 ip6addr_string(&oip
->ip6_dst
),
198 case ICMP6_PACKET_TOO_BIG
:
199 TCHECK(dp
->icmp6_mtu
);
200 printf("icmp6: too big %u\n", (u_int32_t
)ntohl(dp
->icmp6_mtu
));
202 case ICMP6_TIME_EXCEEDED
:
203 TCHECK(oip
->ip6_dst
);
204 switch (dp
->icmp6_code
) {
205 case ICMP6_TIME_EXCEED_TRANSIT
:
206 printf("icmp6: time exceeded in-transit for %s",
207 ip6addr_string(&oip
->ip6_dst
));
209 case ICMP6_TIME_EXCEED_REASSEMBLY
:
210 printf("icmp6: ip6 reassembly time exceeded");
213 printf("icmp6: time exceeded code-#%d",
218 case ICMP6_PARAM_PROB
:
219 TCHECK(oip
->ip6_dst
);
220 switch (dp
->icmp6_code
) {
221 case ICMP6_PARAMPROB_HEADER
:
222 printf("icmp6: parameter problem errorneous - octet %u\n",
223 (u_int32_t
)ntohl(dp
->icmp6_pptr
));
225 case ICMP6_PARAMPROB_NEXTHEADER
:
226 printf("icmp6: parameter problem next header - octet %u\n",
227 (u_int32_t
)ntohl(dp
->icmp6_pptr
));
229 case ICMP6_PARAMPROB_OPTION
:
230 printf("icmp6: parameter problem option - octet %u\n",
231 (u_int32_t
)ntohl(dp
->icmp6_pptr
));
234 printf("icmp6: parameter problem code-#%d",
239 case ICMP6_ECHO_REQUEST
:
240 printf("icmp6: echo request");
242 case ICMP6_ECHO_REPLY
:
243 printf("icmp6: echo reply");
245 #if defined(HAVE_STRUCT_MLD6_HDR) || defined(HAVE_STRUCT_ICMP6_MLD)
246 case ICMP6_MEMBERSHIP_QUERY
:
247 printf("icmp6: multicast listener query ");
248 mld6_print((const u_char
*)dp
);
250 case ICMP6_MEMBERSHIP_REPORT
:
251 printf("icmp6: multicast listener report ");
252 mld6_print((const u_char
*)dp
);
254 case ICMP6_MEMBERSHIP_REDUCTION
:
255 printf("icmp6: multicast listener done ");
256 mld6_print((const u_char
*)dp
);
259 case ND_ROUTER_SOLICIT
:
260 printf("icmp6: router solicitation ");
263 icmp6_opt_print((const u_char
*)dp
+ RTSOLLEN
,
264 icmp6len
- RTSOLLEN
);
267 case ND_ROUTER_ADVERT
:
268 printf("icmp6: router advertisement");
270 struct nd_router_advert
*p
;
272 p
= (struct nd_router_advert
*)dp
;
273 TCHECK(p
->nd_ra_retransmit
);
274 printf("(chlim=%d, ", (int)p
->nd_ra_curhoplimit
);
275 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_MANAGED
)
277 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_OTHER
)
279 #ifndef ND_RA_FLAG_HA
280 #define ND_RA_FLAG_HA 0x20
282 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_HA
)
284 if (p
->nd_ra_flags_reserved
!= 0)
286 printf("router_ltime=%d, ", ntohs(p
->nd_ra_router_lifetime
));
287 printf("reachable_time=%u, ",
288 (u_int32_t
)ntohl(p
->nd_ra_reachable
));
289 printf("retrans_time=%u)",
290 (u_int32_t
)ntohl(p
->nd_ra_retransmit
));
292 icmp6_opt_print((const u_char
*)dp
+ RTADVLEN
,
293 icmp6len
- RTADVLEN
);
296 case ND_NEIGHBOR_SOLICIT
:
298 struct nd_neighbor_solicit
*p
;
299 p
= (struct nd_neighbor_solicit
*)dp
;
300 TCHECK(p
->nd_ns_target
);
301 printf("icmp6: neighbor sol: who has %s",
302 ip6addr_string(&p
->nd_ns_target
));
305 icmp6_opt_print((const u_char
*)dp
+ NDSOLLEN
,
306 icmp6len
- NDSOLLEN
);
310 case ND_NEIGHBOR_ADVERT
:
312 struct nd_neighbor_advert
*p
;
314 p
= (struct nd_neighbor_advert
*)dp
;
315 TCHECK(p
->nd_na_target
);
316 printf("icmp6: neighbor adv: tgt is %s",
317 ip6addr_string(&p
->nd_na_target
));
319 #define ND_NA_FLAG_ALL \
320 (ND_NA_FLAG_ROUTER|ND_NA_FLAG_SOLICITED|ND_NA_FLAG_OVERRIDE)
321 /* we don't need ntohl() here. see advanced-api-04. */
322 if (p
->nd_na_flags_reserved
& ND_NA_FLAG_ALL
) {
323 #undef ND_NA_FLAG_ALL
326 flags
= p
->nd_na_flags_reserved
;
328 if (flags
& ND_NA_FLAG_ROUTER
)
330 if (flags
& ND_NA_FLAG_SOLICITED
)
332 if (flags
& ND_NA_FLAG_OVERRIDE
)
337 icmp6_opt_print((const u_char
*)dp
+ NDADVLEN
,
338 icmp6len
- NDADVLEN
);
344 #define RDR(i) ((struct nd_redirect *)(i))
345 TCHECK(RDR(dp
)->nd_rd_dst
);
346 printf("icmp6: redirect %s",
347 getname6((const u_char
*)&RDR(dp
)->nd_rd_dst
));
349 getname6((const u_char
*)&RDR(dp
)->nd_rd_target
));
350 #define REDIRECTLEN 40
352 icmp6_opt_print((const u_char
*)dp
+ REDIRECTLEN
,
353 icmp6len
- REDIRECTLEN
);
358 #ifndef ICMP6_ROUTER_RENUMBERING
359 #define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */
361 case ICMP6_ROUTER_RENUMBERING
:
362 switch (dp
->icmp6_code
) {
363 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
364 #define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */
366 case ICMP6_ROUTER_RENUMBERING_COMMAND
:
367 printf("icmp6: router renum command");
369 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
370 #define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */
372 case ICMP6_ROUTER_RENUMBERING_RESULT
:
373 printf("icmp6: router renum result");
376 printf("icmp6: router renum code-#%d", dp
->icmp6_code
);
380 #ifdef HAVE_STRUCT_ICMP6_NODEINFO
381 #ifndef ICMP6_NI_QUERY
382 #define ICMP6_NI_QUERY 139
385 icmp6_nodeinfo_print(icmp6len
, bp
, ep
);
387 #ifndef ICMP6_NI_REPLY
388 #define ICMP6_NI_REPLY 140
391 icmp6_nodeinfo_print(icmp6len
, bp
, ep
);
395 printf("icmp6: type-#%d", dp
->icmp6_type
);
400 fputs("[|icmp6]", stdout
);
406 static struct udphdr
*
407 get_upperlayer(register u_char
*bp
, int *prot
)
409 register const u_char
*ep
;
410 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
413 struct ip6_frag
*fragh
;
417 /* 'ep' points to the end of avaible data. */
420 if (TTEST(ip6
->ip6_nxt
) == 0)
424 hlen
= sizeof(struct ip6_hdr
);
426 while (bp
< snapend
) {
432 uh
= (struct udphdr
*)bp
;
433 if (TTEST(uh
->uh_dport
)) {
441 case IPPROTO_HOPOPTS
:
442 case IPPROTO_DSTOPTS
:
443 case IPPROTO_ROUTING
:
444 hbh
= (struct ip6_hbh
*)bp
;
445 if (TTEST(hbh
->ip6h_len
) == 0)
448 hlen
= (hbh
->ip6h_len
+ 1) << 3;
451 case IPPROTO_FRAGMENT
: /* this should be odd, but try anyway */
452 fragh
= (struct ip6_frag
*)bp
;
453 if (TTEST(fragh
->ip6f_offlg
) == 0)
455 /* fragments with non-zero offset are meaningless */
456 if ((fragh
->ip6f_offlg
& IP6F_OFF_MASK
) != 0)
458 nh
= fragh
->ip6f_nxt
;
459 hlen
= sizeof(struct ip6_frag
);
463 ah
= (struct ah
*)bp
;
464 if (TTEST(ah
->ah_len
) == 0)
467 hlen
= (ah
->ah_len
+ 2) << 2;
470 default: /* unknown or undecodable header */
471 *prot
= nh
; /* meaningless, but set here anyway */
476 return(NULL
); /* should be notreached, though */
480 icmp6_opt_print(register const u_char
*bp
, int resid
)
482 register const struct nd_opt_hdr
*op
;
483 register const struct nd_opt_hdr
*opl
; /* why there's no struct? */
484 register const struct nd_opt_prefix_info
*opp
;
485 register const struct icmp6_opts_redirect
*opr
;
486 register const struct nd_opt_mtu
*opm
;
487 register const u_char
*ep
;
490 register const struct ip6_hdr
*ip
;
491 register const char *str
;
492 register const struct ip6_hdr
*oip
;
493 register const struct udphdr
*ouh
;
494 register int hlen
, dport
;
498 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
500 op
= (struct nd_opt_hdr
*)bp
;
502 ip
= (struct ip6_hdr
*)bp2
;
503 oip
= &dp
->icmp6_ip6
;
506 /* 'ep' points to the end of available data. */
509 ECHECK(op
->nd_opt_len
);
512 switch (op
->nd_opt_type
) {
513 case ND_OPT_SOURCE_LINKADDR
:
514 opl
= (struct nd_opt_hdr
*)op
;
516 if ((u_char
*)opl
+ (opl
->nd_opt_len
<< 3) > ep
)
519 TCHECK((u_char
*)opl
+ (opl
->nd_opt_len
<< 3) - 1);
521 printf("(src lladdr: %s", /*)*/
522 etheraddr_string((u_char
*)(opl
+ 1)));
523 if (opl
->nd_opt_len
!= 1)
527 icmp6_opt_print((const u_char
*)op
+ (op
->nd_opt_len
<< 3),
528 resid
- (op
->nd_opt_len
<< 3));
530 case ND_OPT_TARGET_LINKADDR
:
531 opl
= (struct nd_opt_hdr
*)op
;
533 if ((u_char
*)opl
+ (opl
->nd_opt_len
<< 3) > ep
)
536 TCHECK((u_char
*)opl
+ (opl
->nd_opt_len
<< 3) - 1);
538 printf("(tgt lladdr: %s", /*)*/
539 etheraddr_string((u_char
*)(opl
+ 1)));
540 if (opl
->nd_opt_len
!= 1)
544 icmp6_opt_print((const u_char
*)op
+ (op
->nd_opt_len
<< 3),
545 resid
- (op
->nd_opt_len
<< 3));
547 case ND_OPT_PREFIX_INFORMATION
:
548 opp
= (struct nd_opt_prefix_info
*)op
;
549 TCHECK(opp
->nd_opt_pi_prefix
);
550 printf("(prefix info: "); /*)*/
551 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_ONLINK
)
553 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_AUTO
)
555 if (opp
->nd_opt_pi_flags_reserved
)
557 printf("valid_ltime=");
558 if ((u_int32_t
)ntohl(opp
->nd_opt_pi_valid_time
) == ~0U)
561 printf("%u", (u_int32_t
)ntohl(opp
->nd_opt_pi_valid_time
));
564 printf("preffered_ltime=");
565 if ((u_int32_t
)ntohl(opp
->nd_opt_pi_preferred_time
) == ~0U)
568 printf("%u", (u_int32_t
)ntohl(opp
->nd_opt_pi_preferred_time
));
571 printf("prefix=%s/%d", ip6addr_string(&opp
->nd_opt_pi_prefix
),
572 opp
->nd_opt_pi_prefix_len
);
573 if (opp
->nd_opt_pi_len
!= 4)
577 icmp6_opt_print((const u_char
*)op
+ (op
->nd_opt_len
<< 3),
578 resid
- (op
->nd_opt_len
<< 3));
580 case ND_OPT_REDIRECTED_HEADER
:
581 opr
= (struct icmp6_opts_redirect
*)op
;
582 printf("(redirect)");
584 icmp6_opt_print((const u_char
*)op
+ (op
->nd_opt_len
<< 3),
585 resid
- (op
->nd_opt_len
<< 3));
588 opm
= (struct nd_opt_mtu
*)op
;
589 TCHECK(opm
->nd_opt_mtu_mtu
);
590 printf("(mtu: "); /*)*/
591 printf("mtu=%u", (u_int32_t
)ntohl(opm
->nd_opt_mtu_mtu
));
592 if (opm
->nd_opt_mtu_len
!= 1)
595 icmp6_opt_print((const u_char
*)op
+ (op
->nd_opt_len
<< 3),
596 resid
- (op
->nd_opt_len
<< 3));
599 opts_len
= op
->nd_opt_len
;
600 printf("(unknwon opt_type=%d, opt_len=%d)",
601 op
->nd_opt_type
, opts_len
);
603 opts_len
= 1; /* XXX */
604 icmp6_opt_print((const u_char
*)op
+ (opts_len
<< 3),
605 resid
- (opts_len
<< 3));
610 fputs("[ndp opt]", stdout
);
615 #if defined(HAVE_STRUCT_MLD6_HDR)
617 mld6_print(register const u_char
*bp
)
619 register struct mld6_hdr
*mp
= (struct mld6_hdr
*)bp
;
620 register const u_char
*ep
;
622 /* 'ep' points to the end of available data. */
625 if ((u_char
*)mp
+ sizeof(*mp
) > ep
)
628 printf("max resp delay: %d ", ntohs(mp
->mld6_maxdelay
));
629 printf("addr: %s", ip6addr_string(&mp
->mld6_addr
));
632 #elif defined(HAVE_STRUCT_ICMP6_MLD)
635 mld6_print(register const u_char
*bp
)
637 register struct icmp6_mld
*mp
= (struct icmp6_mld
*)bp
;
638 register const u_char
*ep
;
640 /* 'ep' points to the end of available data. */
643 if ((u_char
*)mp
+ sizeof(*mp
) > ep
)
646 printf("max resp delay: %d ", ntohs(mp
->icmp6m_hdr
.icmp6_maxdelay
));
647 printf("addr: %s", ip6addr_string(&mp
->icmp6m_group
));
652 #ifdef HAVE_STRUCT_ICMP6_NODEINFO
654 dnsname_print(const u_char
*cp
, const u_char
*ep
)
658 /* DNS name decoding - no decompression */
667 while (i
-- && cp
< ep
) {
671 if (cp
+ 1 < ep
&& *cp
)
677 } else if (cp
+ 1 == ep
&& *cp
== '\0') {
690 icmp6_nodeinfo_print(int icmp6len
, const u_char
*bp
, const u_char
*ep
)
692 struct icmp6_nodeinfo
*ni6
;
693 struct icmp6_hdr
*dp
;
698 dp
= (struct icmp6_hdr
*)bp
;
699 ni6
= (struct icmp6_nodeinfo
*)bp
;
702 switch (ni6
->ni_type
) {
704 if (siz
== sizeof(*dp
) + 4) {
705 /* KAME who-are-you */
706 printf("icmp6: who-are-you request");
709 printf("icmp6: node information query");
711 TCHECK2(*dp
, sizeof(*ni6
));
712 ni6
= (struct icmp6_nodeinfo
*)dp
;
714 switch (ntohs(ni6
->ni_qtype
)) {
718 case NI_QTYPE_SUPTYPES
:
719 printf("supported qtypes");
720 i
= ntohs(ni6
->ni_flags
);
722 printf(" [%s]", (i
& 0x01) ? "C" : "");
728 case NI_QTYPE_NODEADDR
:
729 printf("node addresses");
733 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
734 printf(" [%s%s%s%s%s%s]",
735 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
736 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
737 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
738 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
739 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
740 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "");
747 if (ni6
->ni_qtype
== NI_QTYPE_NOOP
||
748 ni6
->ni_qtype
== NI_QTYPE_SUPTYPES
) {
749 if (siz
!= sizeof(*ni6
))
751 printf(", invalid len");
758 /* XXX backward compat, icmp-name-lookup-03 */
759 if (siz
== sizeof(*ni6
)) {
760 printf(", 03 draft");
766 switch (ni6
->ni_code
) {
767 case ICMP6_NI_SUBJ_IPV6
:
769 sizeof(*ni6
) + sizeof(struct in6_addr
)))
771 if (siz
!= sizeof(*ni6
) + sizeof(struct in6_addr
)) {
773 printf(", invalid subject len");
776 printf(", subject=%s",
777 getname6((const u_char
*)(ni6
+ 1)));
779 case ICMP6_NI_SUBJ_FQDN
:
780 printf(", subject=DNS name");
781 cp
= (const u_char
*)(ni6
+ 1);
782 if (cp
[0] == ep
- cp
- 1) {
783 /* icmp-name-lookup-03, pascal string */
785 printf(", 03 draft");
794 dnsname_print(cp
, ep
);
796 case ICMP6_NI_SUBJ_IPV4
:
797 if (!TTEST2(*dp
, sizeof(*ni6
) + sizeof(struct in_addr
)))
799 if (siz
!= sizeof(*ni6
) + sizeof(struct in_addr
)) {
801 printf(", invalid subject len");
804 printf(", subject=%s",
805 getname((const u_char
*)(ni6
+ 1)));
808 printf(", unknown subject");
817 if (icmp6len
> siz
) {
818 printf("[|icmp6: node information reply]");
824 ni6
= (struct icmp6_nodeinfo
*)dp
;
825 printf("icmp6: node information reply");
827 switch (ni6
->ni_code
) {
828 case ICMP6_NI_SUCCESS
:
834 case ICMP6_NI_REFUSED
:
837 if (siz
!= sizeof(*ni6
))
839 printf(", invalid length");
841 case ICMP6_NI_UNKNOWN
:
844 if (siz
!= sizeof(*ni6
))
846 printf(", invalid length");
850 if (ni6
->ni_code
!= ICMP6_NI_SUCCESS
) {
856 switch (ntohs(ni6
->ni_qtype
)) {
861 if (siz
!= sizeof(*ni6
))
863 printf(", invalid length");
865 case NI_QTYPE_SUPTYPES
:
868 printf("supported qtypes");
869 i
= ntohs(ni6
->ni_flags
);
871 printf(" [%s]", (i
& 0x01) ? "C" : "");
877 cp
= (const u_char
*)(ni6
+ 1) + 4;
878 if (cp
[0] == ep
- cp
- 1) {
879 /* icmp-name-lookup-03, pascal string */
881 printf(", 03 draft");
890 dnsname_print(cp
, ep
);
891 if ((ntohs(ni6
->ni_flags
) & 0x01) != 0)
892 printf(" [TTL=%u]", *(u_int32_t
*)(ni6
+ 1));
894 case NI_QTYPE_NODEADDR
:
897 printf("node addresses");
900 if (i
+ sizeof(struct in6_addr
) + sizeof(int32_t) > siz
)
902 printf(" %s", getname6(bp
+ i
));
903 i
+= sizeof(struct in6_addr
);
904 printf("(%d)", ntohl(*(int32_t *)(bp
+ i
)));
905 i
+= sizeof(int32_t);
910 printf(" [%s%s%s%s%s%s%s]",
911 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
912 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
913 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
914 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
915 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
916 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "",
917 (i
& NI_NODEADDR_FLAG_TRUNCATE
) ? "T" : "");
933 fputs("[|icmp6]", stdout
);