FreeBSD/usr.bin/netstat/inet6.c
/*
 * Dump IPv6 per-interface statistics based on RFC 2465.
 */
Dump IPv6 per-interface statistics based on RFC 2465.
Dump IPv6 per - interface statistics based on RFC 2465 .
void
ip6_ifstats(char *ifname)
{
	struct in6_ifreq ifr;
	int s;
#define	p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1)	\
	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_stat.f,		\
	    plural(ifr.ifr_ifru.ifru_stat.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_IN6, (char *)&ifr) < 0) {
		if (errno != EPFNOSUPPORT)
			xo_warn("Warning: ioctl(SIOCGIFSTAT_IN6)");
		goto end;
	}
	xo_emit("{T:/ip6 on %s}:\n", ifr.ifr_name);
	xo_open_instance("ip6-interface-statistics");
	xo_emit("{ke:name/%s}", ifr.ifr_name);
	p(ifs6_in_receive, "\t{:received-packets/%ju} "
	    "{N:/total input datagram%s}\n");
	p(ifs6_in_hdrerr, "\t{:dropped-invalid-header/%ju} "
	    "{N:/datagram%s with invalid header received}\n");
	p(ifs6_in_toobig, "\t{:dropped-mtu-exceeded/%ju} "
	    "{N:/datagram%s exceeded MTU received}\n");
	p(ifs6_in_noroute, "\t{:dropped-no-route/%ju} "
	    "{N:/datagram%s with no route received}\n");
	p(ifs6_in_addrerr, "\t{:dropped-invalid-destination/%ju} "
	    "{N:/datagram%s with invalid dst received}\n");
	p(ifs6_in_protounknown, "\t{:dropped-unknown-protocol/%ju} "
	    "{N:/datagram%s with unknown proto received}\n");
	p(ifs6_in_truncated, "\t{:dropped-truncated/%ju} "
	    "{N:/truncated datagram%s received}\n");
	p(ifs6_in_discard, "\t{:dropped-discarded/%ju} "
	    "{N:/input datagram%s discarded}\n");
 	p(ifs6_in_deliver, "\t{:received-valid-packets/%ju} "
	    "{N:/datagram%s delivered to an upper layer protocol}\n");
	p(ifs6_out_forward, "\t{:sent-forwarded/%ju} "
	    "{N:/datagram%s forwarded to this interface}\n");
 	p(ifs6_out_request, "\t{:sent-packets/%ju} "
	    "{N:/datagram%s sent from an upper layer protocol}\n");
	p(ifs6_out_discard, "\t{:discard-packets/%ju} "
	    "{N:/total discarded output datagram%s}\n");
	p(ifs6_out_fragok, "\t{:discard-fragments/%ju} "
	    "{N:/output datagram%s fragmented}\n");
	p(ifs6_out_fragfail, "\t{:fragments-failed/%ju} "
	    "{N:/output datagram%s failed on fragment}\n");
	p(ifs6_out_fragcreat, "\t{:fragments-created/%ju} "
	    "{N:/output datagram%s succeeded on fragment}\n");
	p(ifs6_reass_reqd, "\t{:reassembly-required/%ju} "
	    "{N:/incoming datagram%s fragmented}\n");
	p(ifs6_reass_ok, "\t{:reassembled-packets/%ju} "
	    "{N:/datagram%s reassembled}\n");
	p(ifs6_reass_fail, "\t{:reassembly-failed/%ju} "
	    "{N:/datagram%s failed on reassembly}\n");
	p(ifs6_in_mcast, "\t{:received-multicast/%ju} "
	    "{N:/multicast datagram%s received}\n");
	p(ifs6_out_mcast, "\t{:sent-multicast/%ju} "
	    "{N:/multicast datagram%s sent}\n");
 end:
	xo_close_instance("ip6-interface-statistics");
 	close(s);
#undef p
}
void ip6_ifstats ( char * ifname ) { struct in6_ifreq ifr ; int s ; #define p ( f , m )  if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1)	\
	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_stat.f,		\
	    plural(ifr.ifr_ifru.ifru_stat.f)) if ( ( s = socket ( AF_INET6 , SOCK_DGRAM , 0 ) ) < 0 ) { xo_warn ( " " ) ; return ; } strcpy ( ifr . ifr_name , ifname ) ; if ( ioctl ( s , SIOCGIFSTAT_IN6 , ( 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_receive , " \t " " \n " ) ; p ( ifs6_in_hdrerr , " \t " " \n " ) ; p ( ifs6_in_toobig , " \t " " \n " ) ; p ( ifs6_in_noroute , " \t " " \n " ) ; p ( ifs6_in_addrerr , " \t " " \n " ) ; p ( ifs6_in_protounknown , " \t " " \n " ) ; p ( ifs6_in_truncated , " \t " " \n " ) ; p ( ifs6_in_discard , " \t " " \n " ) ; p ( ifs6_in_deliver , " \t " " \n " ) ; p ( ifs6_out_forward , " \t " " \n " ) ; p ( ifs6_out_request , " \t " " \n " ) ; p ( ifs6_out_discard , " \t " " \n " ) ; p ( ifs6_out_fragok , " \t " " \n " ) ; p ( ifs6_out_fragfail , " \t " " \n " ) ; p ( ifs6_out_fragcreat , " \t " " \n " ) ; p ( ifs6_reass_reqd , " \t " " \n " ) ; p ( ifs6_reass_ok , " \t " " \n " ) ; p ( ifs6_reass_fail , " \t " " \n " ) ; p ( ifs6_in_mcast , " \t " " \n " ) ; p ( ifs6_out_mcast , " \t " " \n " ) ; end : xo_close_instance ( " " ) ; close ( s ) ; #undef  p }
Dump IPv6 per-interface statistics based on RFC 2465.
Dump IPv6 per - interface statistics based on RFC 2465 .