bmon
bmon copied to clipboard
3.9: FTBFS on kFreeBSD (‘struct if_data’ has no member)
As reported in https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=826836 bmon 3.9 FTBFS on kFreeBSD:
in_sysctl.c: In function ‘sysctl_read’:
in_sysctl.c:236:59: error: ‘struct if_data’ has no member named ‘ifi_recvquota’
snprintf(info_buf, sizeof(info_buf), "%u", ifm->ifm_data.ifi_recvquota);
^
in_sysctl.c:239:59: error: ‘struct if_data’ has no member named ‘ifi_xmitquota’
snprintf(info_buf, sizeof(info_buf), "%u", ifm->ifm_data.ifi_xmitquota);
^
Proposed patch is the following (though I'm not sure if it is the best way to fix the problem):
--- a/src/in_sysctl.c
+++ b/src/in_sysctl.c
@@ -231,9 +231,9 @@
snprintf(info_buf, sizeof(info_buf), "%ju", (uintmax_t)ifm->ifm_data.ifi_metric);
element_update_info(e, "Metric", info_buf);
-#ifndef __NetBSD__
+#ifdef __APPLE__
snprintf(info_buf, sizeof(info_buf), "%u", ifm->ifm_data.ifi_recvquota);
element_update_info(e, "RX-Quota", info_buf);
snprintf(info_buf, sizeof(info_buf), "%u", ifm->ifm_data.ifi_xmitquota);
FYI detecting kFreeBSD can be done using __FreeBSD_kernel__
:
https://wiki.debian.org/Debian_GNU/kFreeBSD_FAQ#Q._How_do_I_detect_kfreebsd_with_preprocessor_directives_in_a_C_program.3F
It would be ideal to have a BSD guy comment on this. Looking at: https://opensource.apple.com/source/xnu/xnu-792.13.8/bsd/net/if_var.h
struct if_data {
/* generic interface information */
unsigned char ifi_type; /* ethernet, tokenring, etc */
#ifdef __APPLE__
unsigned char ifi_typelen; /* Length of frame type id */
#endif
unsigned char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
unsigned char ifi_addrlen; /* media address length */
unsigned char ifi_hdrlen; /* media header length */
unsigned char ifi_recvquota; /* polling quota for receive intrs */
unsigned char ifi_xmitquota; /* polling quota for xmit intrs */
would indicate that __APPLE__
is too restrictive. I didn't find any better information and this is clearly a step forward so unless somebody comments on this in the next couple of days, then I'm going to merge this the way it is.
Hello!
If even the XNU headers use ifdef __APPLE__
for this member, why not do exactly the same in bmon? I don't understand why that would be too restrictive.
@stevenc99 The ifi_typelen
is protected by __APPLE__
, the quota members are not which lead me to the conclusion that there is likely a better fitting feature define.
FYI, build fails with the same error on FreeBSD 10.0-RELEASE-p12:
in_sysctl.c:236:60: error: no member named 'ifi_recvquota' in 'struct if_data'
snprintf(info_buf, sizeof(info_buf), "%u", ifm->ifm_data.ifi_recvquota);
~~~~~~~~~~~~~ ^
in_sysctl.c:239:60: error: no member named 'ifi_xmitquota' in 'struct if_data'
snprintf(info_buf, sizeof(info_buf), "%u", ifm->ifm_data.ifi_xmitquota);
~~~~~~~~~~~~~ ^