Example #1
0
END_TEST

START_TEST(readsysclassnet_not_found)
{
	linuxonly;

	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	fake_sys_class_net("ethwrong", 10, 20, 30, 40, 50);

	ck_assert_int_eq(readsysclassnet("ethunusual"), 0);
}
Example #2
0
END_TEST

START_TEST(readsysclassnet_success)
{
	linuxonly;

	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	fake_sys_class_net("ethwrong", 10, 20, 30, 40, 50);
	fake_sys_class_net("ethunusual", 1, 2, 3, 4, 5);

	ck_assert_int_eq(readsysclassnet("ethunusual"), 1);
	ck_assert_str_eq(ifinfo.name, "ethunusual");
	ck_assert_int_eq(ifinfo.filled, 1);
	ck_assert_int_eq(ifinfo.rx, 1);
	ck_assert_int_eq(ifinfo.tx, 2);
	ck_assert_int_eq(ifinfo.rxp, 3);
	ck_assert_int_eq(ifinfo.txp, 4);
}
Example #3
0
int getifinfo(const char *iface)
{
	char inface[32];

	ifinfo.filled = 0;

	if (strcmp(iface, "default")==0) {
		strncpy(inface, cfg.iface, 32);
	} else {
		strncpy(inface, iface, 32);
	}

#if defined(__linux__)
	/* try getting interface info from /proc */
	if (readproc(inface)!=1) {
		if (debug)
			printf("Failed to use %s as source.\n", PROCNETDEV);

		/* try getting interface info from /sys */
		if (readsysclassnet(inface)!=1) {
			snprintf(errorstring, 512, "Unable to get interface \"%s\" statistics.", inface);
			printe(PT_Error);
			return 0;
		}
	}
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)  || defined(__FreeBSD_kernel__)
	if (readifaddrs(inface)!=1) {
		snprintf(errorstring, 512, "Unable to get interface \"%s\" statistics.", inface);
		printe(PT_Error);
		return 0;
	}
#else
	return 0;
#endif

	return 1;
}