4 #include <sys/ndd_var.h>
8 get ethernet MAC address on AIX
10 static int aix_get_mac_addr(const char *device_name, uint8_t mac[6])
13 struct kinfo_ndd *ndd;
16 ksize = getkerninfo(KINFO_NDD, 0, 0, 0);
22 ndd = (struct kinfo_ndd *)malloc(ksize);
28 if (getkerninfo(KINFO_NDD, ndd, &ksize, 0) == -1) {
33 count= ksize/sizeof(struct kinfo_ndd);
34 for (i=0;i<count;i++) {
35 if ((ndd[i].ndd_type == NDD_ETHER ||
36 ndd[i].ndd_type == NDD_ISO88023) &&
37 ndd[i].ndd_addrlen == 6 &&
38 (strcmp(ndd[i].ndd_alias, device_name) == 0 ||
39 strcmp(ndd[i].ndd_name, device_name == 0))) {
40 memcpy(mac, ndd[i].ndd_addr, 6);
51 int main(int argc, char *argv[])
57 printf("Usage: aix_getmac <interface>\n");
60 ret = aix_get_mac_addr(argv[1], mac);
65 printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
66 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);