diff --git a/iftop.c b/iftop.c index 522d308..fe5921e 100644 --- a/iftop.c +++ b/iftop.c @@ -415,15 +415,21 @@ void packet_init() { perror("socket"); exit(1); } + fprintf(stderr,"if: %s\n", options.interface); +#ifdef SIOCGIFHWADDR strncpy(ifr.ifr_name, options.interface, IFNAMSIZ); - ifr.ifr_hwaddr.sa_family = AF_UNSPEC; - if (ioctl(s, SIOCGIFADDR, &ifr) == -1) { + if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { fprintf(stderr, "Error getting hardware address for interface: %s\n", options.interface); perror("ioctl(SIOCGIFHWADDR)"); exit(1); } - close(s); memcpy(if_hw_addr, ifr.ifr_hwaddr.sa_data, 6); +#else + fprintf(stderr, "Cannot obtain hardware address on this platform\n"); + memset(if_hw_addr, 0, 6); +#endif + + close(s); fprintf(stderr, "MAC address is:"); for (s = 0; s < 6; ++s) fprintf(stderr, "%c%02x", s ? ':' : ' ', (unsigned int)if_hw_addr[s]); diff --git a/iftop.h b/iftop.h index c139d85..b924642 100644 --- a/iftop.h +++ b/iftop.h @@ -36,13 +36,4 @@ void ui_init(void); void options_read(int argc, char **argv); -/* Make use of SIOCGIFHWADDR work on FreeBSD and Solaris. */ -#ifndef SIOCGIFHWADDR -# ifdef HAVE_SYS_SOCKIO_H -# include /* Solaris and others?? */ -# endif -# define SIOCGIFHWADDR SIOCGIFADDR -# define ifr_hwaddr ifr_addr -#endif - #endif /* __IFTOP_H_ */