diff --git a/common/device.c b/common/device.c index 95a1595..9347212 100644 --- a/common/device.c +++ b/common/device.c @@ -152,12 +152,7 @@ deviceOpen(ifname, proto, trans) #ifdef DEV_NEW_CONF deviceEthAddr(p->if_name,&p->eaddr[0]); #elif defined(__linux__) - { - int s; - s = socket(AF_INET,SOCK_DGRAM,0); - pfEthAddr(s,p->if_name,&p->eaddr[0]); - (void) close(s); - } + pfEthAddr(0, p->if_name,&p->eaddr[0]); #else p->eaddr[0]= tmp.eaddr[0]; p->eaddr[1]= tmp.eaddr[1]; diff --git a/common/pf-linux.c b/common/pf-linux.c index dcff109..4b2babe 100644 --- a/common/pf-linux.c +++ b/common/pf-linux.c @@ -204,12 +204,17 @@ int s; char *interface; u_char *addr; { + int err; + strncpy(ifr.ifr_name, interface, sizeof (ifr.ifr_name) - 1); ifr.ifr_name[sizeof(ifr.ifr_name)] = 0; ifr.ifr_addr.sa_family = AF_INET; - if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { + s = socket(AF_INET,SOCK_DGRAM,0); + err = ioctl(s, SIOCGIFHWADDR, &ifr); + (void) close(s); + if (err < 0) { syslog(LOG_ERR, "pfEthAddr: %s: SIOCGIFHWADDR: %m", interface); - return(-1); + exit(-1); } memcpy((char *)addr, ifr.ifr_hwaddr.sa_data, 6); return(0);