dnet: Fix hw address getting on AIX

This commit is contained in:
dmiller 2014-09-09 21:19:08 +00:00
parent 9847a701e4
commit 73275cc872

View file

@ -20,6 +20,10 @@
# include <sys/sockio.h>
#endif
/* XXX - AIX */
#ifdef HAVE_GETKERNINFO
#include <sys/ndd_var.h>
#include <sys/kinfo.h>
#endif
#ifndef IP_MULTICAST
# define IP_MULTICAST
#endif
@ -477,6 +481,11 @@ static int
_intf_get_noalias(intf_t *intf, struct intf_entry *entry)
{
struct ifreq ifr;
#ifdef HAVE_GETKERNINFO
int size;
struct kinfo_ndd *nddp;
void *end;
#endif
/* Get interface index. */
entry->intf_index = if_nametoindex(entry->intf_name);
@ -517,7 +526,39 @@ _intf_get_noalias(intf_t *intf, struct intf_entry *entry)
return (-1);
}
} else if (entry->intf_type == INTF_TYPE_ETH) {
#if defined(SIOCGIFHWADDR)
#if defined(HAVE_GETKERNINFO)
/* AIX also defines SIOCGIFHWADDR, but it fails silently?
* This is the method IBM recommends here:
* http://www-01.ibm.com/support/knowledgecenter/ssw_aix_53/com.ibm.aix.progcomm/doc/progcomc/skt_sndother_ex.htm%23ssqinc2joyc?lang=en
*/
/* How many bytes will be returned? */
size = getkerninfo(KINFO_NDD, 0, 0, 0);
if (size <= 0) {
return -1;
}
nddp = (struct kinfo_ndd *)malloc(size);
if (!nddp) {
return -1;
}
/* Get all Network Device Driver (NDD) info */
if (getkerninfo(KINFO_NDD, nddp, &size, 0) < 0) {
free(nddp);
return -1;
}
/* Loop over the returned values until we find a match */
end = (void *)nddp + size;
while ((void *)nddp < end) {
if (!strcmp(nddp->ndd_alias, entry->intf_name) ||
!strcmp(nddp->ndd_name, entry->intf_name)) {
addr_pack(&entry->intf_link_addr, ADDR_TYPE_ETH, ETH_ADDR_BITS,
nddp->ndd_addr, ETH_ADDR_LEN);
break;
} else
nddp++;
}
free(nddp);
#elif defined(SIOCGIFHWADDR)
if (ioctl(intf->fd, SIOCGIFHWADDR, &ifr) < 0)
return (-1);
if (addr_ston(&ifr.ifr_addr, &entry->intf_link_addr) < 0)