DragonFlyBSD Kernel Audit
DF-2905 / mbread.c
← back to finding ↓ download raw
/*
 * mbread — print the current number of live mbufs (mbstat.m_mbufs, the
 * first member of struct mbstat returned by kern.ipc.mbstat).
 * m_mbufs is incremented by updatestats() on every m_get/m_gethdr and
 * decremented by m_free() when the mbuf returns to the plain-mbuf cache,
 * so it is an exact live-plain-mbuf counter.
 */
#include <sys/types.h>
#include <sys/sysctl.h>
#include <stdio.h>
#include <string.h>

int
main(void)
{
	char buf[512];
	size_t len = sizeof(buf);
	unsigned long mbufs;

	if (sysctlbyname("kern.ipc.mbstat", buf, &len, NULL, 0) < 0) {
		perror("sysctl kern.ipc.mbstat");
		return 1;
	}
	memcpy(&mbufs, buf, sizeof(mbufs));	/* m_mbufs is first member */
	printf("%lu\n", mbufs);
	return 0;
}