FreeBSD/usr.bin/netstat/inet6.c
/*
 * Dump ICMPv6 per-interface statistics based on RFC 2466.
 */
Dump ICMPv6 per-interface statistics based on RFC 2466.
Dump ICMPv6 per - interface statistics based on RFC 2466 .
void
icmp6_ifstats(char *ifname)
{
	struct in6_ifreq ifr;
	int s;
#define	p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1)	\
	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f,		\
	    plural(ifr.ifr_ifru.ifru_icmp6stat.f))
#define	p2(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1)	\
	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f,		\
	    pluralies(ifr.ifr_ifru.ifru_icmp6stat.f))
	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
		xo_warn("Warning: socket(AF_INET6)");
		return;
	}
	strcpy(ifr.ifr_name, ifname);
	if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
		if (errno != EPFNOSUPPORT)
			xo_warn("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
		goto end;
	}
	xo_emit("{T:/icmp6 on %s}:\n", ifr.ifr_name);
	xo_open_instance("icmp6-interface-statistics");
	xo_emit("{ke:name/%s}", ifr.ifr_name);
	p(ifs6_in_msg, "\t{:received-packets/%ju} "
	    "{N:/total input message%s}\n");
	p(ifs6_in_error, "\t{:received-errors/%ju} "
	    "{N:/total input error message%s}\n");
	p(ifs6_in_dstunreach, "\t{:received-destination-unreachable/%ju} "
	    "{N:/input destination unreachable error%s}\n");
	p(ifs6_in_adminprohib, "\t{:received-admin-prohibited/%ju} "
	    "{N:/input administratively prohibited error%s}\n");
	p(ifs6_in_timeexceed, "\t{:received-time-exceeded/%ju} "
	    "{N:/input time exceeded error%s}\n");
	p(ifs6_in_paramprob, "\t{:received-bad-parameter/%ju} "
	    "{N:/input parameter problem error%s}\n");
	p(ifs6_in_pkttoobig, "\t{:received-packet-too-big/%ju} "
	    "{N:/input packet too big error%s}\n");
	p(ifs6_in_echo, "\t{:received-echo-requests/%ju} "
	    "{N:/input echo request%s}\n");
	p2(ifs6_in_echoreply, "\t{:received-echo-replies/%ju} "
	    "{N:/input echo repl%s}\n");
	p(ifs6_in_routersolicit, "\t{:received-router-solicitation/%ju} "
	    "{N:/input router solicitation%s}\n");
	p(ifs6_in_routeradvert, "\t{:received-router-advertisement/%ju} "
	    "{N:/input router advertisement%s}\n");
	p(ifs6_in_neighborsolicit, "\t{:received-neighbor-solicitation/%ju} "
	    "{N:/input neighbor solicitation%s}\n");
	p(ifs6_in_neighboradvert, "\t{:received-neighbor-advertisement/%ju} "
	    "{N:/input neighbor advertisement%s}\n");
	p(ifs6_in_redirect, "\t{received-redirects/%ju} "
	    "{N:/input redirect%s}\n");
	p2(ifs6_in_mldquery, "\t{:received-mld-queries/%ju} "
	    "{N:/input MLD quer%s}\n");
	p(ifs6_in_mldreport, "\t{:received-mld-reports/%ju} "
	    "{N:/input MLD report%s}\n");
	p(ifs6_in_mlddone, "\t{:received-mld-done/%ju} "
	    "{N:/input MLD done%s}\n");
	p(ifs6_out_msg, "\t{:sent-packets/%ju} "
	    "{N:/total output message%s}\n");
	p(ifs6_out_error, "\t{:sent-errors/%ju} "
	    "{N:/total output error message%s}\n");
	p(ifs6_out_dstunreach, "\t{:sent-destination-unreachable/%ju} "
	    "{N:/output destination unreachable error%s}\n");
	p(ifs6_out_adminprohib, "\t{:sent-admin-prohibited/%ju} "
	    "{N:/output administratively prohibited error%s}\n");
	p(ifs6_out_timeexceed, "\t{:sent-time-exceeded/%ju} "
	    "{N:/output time exceeded error%s}\n");
	p(ifs6_out_paramprob, "\t{:sent-bad-parameter/%ju} "
	    "{N:/output parameter problem error%s}\n");
	p(ifs6_out_pkttoobig, "\t{:sent-packet-too-big/%ju} "
	    "{N:/output packet too big error%s}\n");
	p(ifs6_out_echo, "\t{:sent-echo-requests/%ju} "
	    "{N:/output echo request%s}\n");
	p2(ifs6_out_echoreply, "\t{:sent-echo-replies/%ju} "
	    "{N:/output echo repl%s}\n");
	p(ifs6_out_routersolicit, "\t{:sent-router-solicitation/%ju} "
	    "{N:/output router solicitation%s}\n");
	p(ifs6_out_routeradvert, "\t{:sent-router-advertisement/%ju} "
	    "{N:/output router advertisement%s}\n");
	p(ifs6_out_neighborsolicit, "\t{:sent-neighbor-solicitation/%ju} "
	    "{N:/output neighbor solicitation%s}\n");
	p(ifs6_out_neighboradvert, "\t{:sent-neighbor-advertisement/%ju} "
	    "{N:/output neighbor advertisement%s}\n");
	p(ifs6_out_redirect, "\t{:sent-redirects/%ju} "
	    "{N:/output redirect%s}\n");
	p2(ifs6_out_mldquery, "\t{:sent-mld-queries/%ju} "
	    "{N:/output MLD quer%s}\n");
	p(ifs6_out_mldreport, "\t{:sent-mld-reports/%ju} "
	    "{N:/output MLD report%s}\n");
	p(ifs6_out_mlddone, "\t{:sent-mld-dones/%ju} "
	    "{N:/output MLD done%s}\n");
end:
	xo_close_instance("icmp6-interface-statistics");
	close(s);
#undef p
}
void icmp6_ifstats ( char * ifname ) { struct in6_ifreq ifr ; int s ; #define p ( f , m )  if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1)	\
	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f,		\
	    plural(ifr.ifr_ifru.ifru_icmp6stat.f)) #define p2 ( f , m )  if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1)	\
	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f,		\
	    pluralies(ifr.ifr_ifru.ifru_icmp6stat.f)) if ( ( s = socket ( AF_INET6 , SOCK_DGRAM , 0 ) ) < 0 ) { xo_warn ( " " ) ; return ; } strcpy ( ifr . ifr_name , ifname ) ; if ( ioctl ( s , SIOCGIFSTAT_ICMP6 , ( char * ) & ifr ) < 0 ) { if ( errno != EPFNOSUPPORT ) xo_warn ( " " ) ; goto end ; } xo_emit ( " \n " , ifr . ifr_name ) ; xo_open_instance ( " " ) ; xo_emit ( " " , ifr . ifr_name ) ; p ( ifs6_in_msg , " \t " " \n " ) ; p ( ifs6_in_error , " \t " " \n " ) ; p ( ifs6_in_dstunreach , " \t " " \n " ) ; p ( ifs6_in_adminprohib , " \t " " \n " ) ; p ( ifs6_in_timeexceed , " \t " " \n " ) ; p ( ifs6_in_paramprob , " \t " " \n " ) ; p ( ifs6_in_pkttoobig , " \t " " \n " ) ; p ( ifs6_in_echo , " \t " " \n " ) ; p2 ( ifs6_in_echoreply , " \t " " \n " ) ; p ( ifs6_in_routersolicit , " \t " " \n " ) ; p ( ifs6_in_routeradvert , " \t " " \n " ) ; p ( ifs6_in_neighborsolicit , " \t " " \n " ) ; p ( ifs6_in_neighboradvert , " \t " " \n " ) ; p ( ifs6_in_redirect , " \t " " \n " ) ; p2 ( ifs6_in_mldquery , " \t " " \n " ) ; p ( ifs6_in_mldreport , " \t " " \n " ) ; p ( ifs6_in_mlddone , " \t " " \n " ) ; p ( ifs6_out_msg , " \t " " \n " ) ; p ( ifs6_out_error , " \t " " \n " ) ; p ( ifs6_out_dstunreach , " \t " " \n " ) ; p ( ifs6_out_adminprohib , " \t " " \n " ) ; p ( ifs6_out_timeexceed , " \t " " \n " ) ; p ( ifs6_out_paramprob , " \t " " \n " ) ; p ( ifs6_out_pkttoobig , " \t " " \n " ) ; p ( ifs6_out_echo , " \t " " \n " ) ; p2 ( ifs6_out_echoreply , " \t " " \n " ) ; p ( ifs6_out_routersolicit , " \t " " \n " ) ; p ( ifs6_out_routeradvert , " \t " " \n " ) ; p ( ifs6_out_neighborsolicit , " \t " " \n " ) ; p ( ifs6_out_neighboradvert , " \t " " \n " ) ; p ( ifs6_out_redirect , " \t " " \n " ) ; p2 ( ifs6_out_mldquery , " \t " " \n " ) ; p ( ifs6_out_mldreport , " \t " " \n " ) ; p ( ifs6_out_mlddone , " \t " " \n " ) ; end : xo_close_instance ( " " ) ; close ( s ) ; #undef  p }
Dump ICMPv6 per-interface statistics based on RFC 2466.
Dump ICMPv6 per - interface statistics based on RFC 2466 .