troglobit / netcalc

Simplified clone of sipcalc with ipcalc looks
BSD 3-Clause "New" or "Revised" License
67 stars 12 forks source link

netcalc.h: add missing include for macOS #25

Closed barracuda156 closed 3 months ago

barracuda156 commented 3 months ago

Fix for macOS: some versions require sys/socket.h be included before net/if.h, otherwise build breaks down.

barracuda156 commented 3 months ago

Without this fix on 10.6:

Making all in src
make[2]: Entering directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_netcalc/netcalc/work/netcalc-2.1.6/src'
  CC       netcalc-netcalc.o
  CC       netcalc-cprintf.o
  CC       netcalc-output.o
  CC       netcalc-misc.o
In file included from netcalc.h:35,
                 from output.c:35:
/usr/include/net/if.h:264: error: field ‘ifru_addr’ has incomplete type
/usr/include/net/if.h:265: error: field ‘ifru_dstaddr’ has incomplete type
/usr/include/net/if.h:266: error: field ‘ifru_broadaddr’ has incomplete type
/usr/include/net/if.h:305: error: field ‘ifra_addr’ has incomplete type
/usr/include/net/if.h:306: error: field ‘ifra_broadaddr’ has incomplete type
/usr/include/net/if.h:307: error: field ‘ifra_mask’ has incomplete type
/usr/include/net/if.h:379: error: field ‘addr’ has incomplete type
/usr/include/net/if.h:380: error: field ‘dstaddr’ has incomplete type
In file included from netcalc.h:35,
                 from netcalc.c:41:
/usr/include/net/if.h:264: error: field ‘ifru_addr’ has incomplete type
/usr/include/net/if.h:265: error: field ‘ifru_dstaddr’ has incomplete type
/usr/include/net/if.h:266: error: field ‘ifru_broadaddr’ has incomplete type
/usr/include/net/if.h:305: error: field ‘ifra_addr’ has incomplete type
/usr/include/net/if.h:306: error: field ‘ifra_broadaddr’ has incomplete type
/usr/include/net/if.h:307: error: field ‘ifra_mask’ has incomplete type
/usr/include/net/if.h:379: error: field ‘addr’ has incomplete type
/usr/include/net/if.h:380: error: field ‘dstaddr’ has incomplete type
make[2]: *** [netcalc-output.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [netcalc-netcalc.o] Error 1
In file included from netcalc.h:35,
                 from misc.c:36:
/usr/include/net/if.h:264: error: field ‘ifru_addr’ has incomplete type
/usr/include/net/if.h:265: error: field ‘ifru_dstaddr’ has incomplete type
/usr/include/net/if.h:266: error: field ‘ifru_broadaddr’ has incomplete type
/usr/include/net/if.h:305: error: field ‘ifra_addr’ has incomplete type
/usr/include/net/if.h:306: error: field ‘ifra_broadaddr’ has incomplete type
/usr/include/net/if.h:307: error: field ‘ifra_mask’ has incomplete type
/usr/include/net/if.h:379: error: field ‘addr’ has incomplete type
/usr/include/net/if.h:380: error: field ‘dstaddr’ has incomplete type
make[2]: *** [netcalc-misc.o] Error 1
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_netcalc/netcalc/work/netcalc-2.1.6/src'
make[1]: *** [all-recursive] Error 1

Once header added, it builds fine:

Making all in src
make[2]: Entering directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_netcalc/netcalc/work/netcalc-2.1.6/src'
  CC       netcalc-output.o
  CC       netcalc-netcalc.o
  CC       netcalc-misc.o
output.c: In function ‘show_network_ranges_v4’:
output.c:39: warning: ‘min’ may be used uninitialized in this function
output.c: In function ‘print_cf_info_v4’:
output.c:115: warning: ‘min’ may be used uninitialized in this function
output.c:115: warning: ‘max’ may be used uninitialized in this function
  CCLD     netcalc
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_netcalc/netcalc/work/netcalc-2.1.6/src'
Making all in tests
make[2]: Entering directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_netcalc/netcalc/work/netcalc-2.1.6/tests'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_netcalc/netcalc/work/netcalc-2.1.6/tests'
make[2]: Entering directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_netcalc/netcalc/work/netcalc-2.1.6'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_netcalc/netcalc/work/netcalc-2.1.6'
make[1]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_netcalc/netcalc/work/netcalc-2.1.6'
make: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_net_netcalc/netcalc/work/netcalc-2.1.6'
troglobit commented 3 months ago

Nice work 👍

barracuda156 commented 3 months ago

Thanks for merging!

troglobit commented 3 months ago

Just released v2.1.7, with a slightly changed #ifdef for your PR to increase portability and usefulness on other (*BSD) systems.

barracuda156 commented 3 months ago

Updated in https://github.com/macports/macports-ports/commit/565f5cf0c487820513bed7f4950a3fa208aba07a