diff -u -r iftop-0.17pre1/addrs_ioctl.c iftop-0.17pre1-bsdmac/addrs_ioctl.c --- iftop-0.17pre1/addrs_ioctl.c Tue Jul 27 10:44:13 2004 +++ iftop-0.17pre1-bsdmac/addrs_ioctl.c Tue May 3 11:46:49 2005 @@ -18,6 +18,12 @@ #include #include +#if defined __FreeBSD__ || defined __OpenBSD__ +#include +#include +#include +#endif + #include "iftop.h" /* @@ -65,7 +71,41 @@ got_hw_addr = 1; } #else +#if defined __FreeBSD__ || defined __OpenBSD__ + { + int sysctlparam[6] = {CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0}; + int needed = 0; + char *buf = NULL; + struct if_msghdr *msghdr = NULL; + sysctlparam[5] = if_nametoindex(interface); + if (sysctlparam[5] == 0) { + fprintf(stderr, "Error getting hardware address for interface: %s\n", interface); + goto ENDHWADDR; + } + if (sysctl(sysctlparam, 6, NULL, &needed, NULL, 0) < 0) { + fprintf(stderr, "Error getting hardware address for interface: %s\n", interface); + goto ENDHWADDR; + } + if ((buf = malloc(needed)) == NULL) { + fprintf(stderr, "Error getting hardware address for interface: %s\n", interface); + goto ENDHWADDR; + } + if (sysctl(sysctlparam, 6, buf, &needed, NULL, 0) < 0) { + fprintf(stderr, "Error getting hardware address for interface: %s\n", interface); + free(buf); + goto ENDHWADDR; + } + msghdr = (struct if_msghdr *) buf; + memcpy(if_hw_addr, LLADDR((struct sockaddr_dl *)(buf + sizeof(struct if_msghdr) - sizeof(struct if_data) + sizeof(struct if_data))), 6); + free(buf); + got_hw_addr = 1; + + ENDHWADDR: + 1; /* compiler whines if there is a label at the end of a block...*/ + } +#else fprintf(stderr, "Cannot obtain hardware address on this platform\n"); +#endif #endif /* Get the IP address of the interface */