if (ioctl (mi->fd, SIOCGIFADDR, (char *) & mi->buf[i])) {
err->errcode = errno;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "ioctl(SIOCGIFADDR) error (%d): %s", strerror(errno));
return GETMAC_ERROR;
}
/* get Hardware Address */
#ifdef SOLARIS
do {
mi->arp.arp_pa.sa_family = AF_INET;
mi->arp.arp_ha.sa_family = AF_INET;
((struct sockaddr_in *) & mi->arp.arp_pa)->sin_addr.s_addr = ((struct sockaddr_in*)(& buf[i].ifr_addr))->sin_addr.s_addr;
if ((ioctl (mi->fd, SIOCGARP, (char *) & mi->arp))) {
err->errcode = errno;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "ioctl(SIOCGARP) error (%d): %s", strerror(errno));
return GETMAC_ERROR;
}
} while (0);
#else
#if 0
do {
/* get HW ADDRESS of the net card */
if (ioctl (mi->fd, SIOCGENADDR, (char *) & buf[i])) {
err->errcode = errno;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "ioctl(SIOCGENADDR) error (%d): %s", strerror(errno));
return GETMAC_ERROR;
}
} while (0);
#else
do {
if (ioctl (mi->fd, SIOCGIFHWADDR, (char *) & mi->buf[i])) {
err->errcode = errno;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "ioctl(SIOCGIFHWADDR) error (%d): %s", strerror(errno));
return GETMAC_ERROR;
}
} while (0);
#endif
#endif
}
err->errcode = GETMAC_NOERROR;
/* get net attribute */
switch (attr) {
case GETMAC_ATTR_IFF_UP: /* Interface is up */
if (mi->buf[i].ifr_flags & IFF_UP) {
* ((GETMAC_BOOL *) value) = GETMAC_TRUE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Interface is up");
} else {
* ((GETMAC_BOOL *) value) = GETMAC_FALSE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Interface is not up");
}
break;
case GETMAC_ATTR_IFF_BROADCAST: /* Broadcast address valid */
if (mi->buf[i].ifr_flags & IFF_BROADCAST) {
* ((GETMAC_BOOL *) value) = GETMAC_TRUE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Broadcast address valid");
} else {
* ((GETMAC_BOOL *) value) = GETMAC_FALSE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Broadcast address invalid");
}
break;
case GETMAC_ATTR_IFF_DEBUG: /* Turn on debugging */
if (mi->buf[i].ifr_flags & IFF_DEBUG) {
* ((GETMAC_BOOL *) value) = GETMAC_TRUE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Turn on debugging");
} else {
* ((GETMAC_BOOL *) value) = GETMAC_FALSE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Turn off debugging");
}
break;
case GETMAC_ATTR_IFF_LOOPBACK: /* Is a loopback net */
if (mi->buf[i].ifr_flags & IFF_LOOPBACK) {
* ((GETMAC_BOOL *) value) = GETMAC_TRUE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Is a loopback net");
} else {
* ((GETMAC_BOOL *) value) = GETMAC_FALSE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Not a loopback net");
}
break;
case GETMAC_ATTR_IFF_POINTOPOINT: /* Interface is point-to-point link */
if (mi->buf[i].ifr_flags & IFF_POINTOPOINT) {
* ((GETMAC_BOOL *) value) = GETMAC_TRUE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Interface is point-to-point link");
} else {
* ((GETMAC_BOOL *) value) = GETMAC_FALSE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Interface is not point-to-point link");
}
break;
case GETMAC_ATTR_IFF_NOTRAILERS: /* Avoid use of trailers */
if (mi->buf[i].ifr_flags & IFF_NOTRAILERS) {
* ((GETMAC_BOOL *) value) = GETMAC_TRUE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Avoid use of trailers");
} else {
* ((GETMAC_BOOL *) value) = GETMAC_FALSE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Not Avoid use of trailers");
}
break;
case GETMAC_ATTR_IFF_RUNNING: /* Resources allocated */
if (mi->buf[i].ifr_flags & IFF_RUNNING) {
* ((GETMAC_BOOL *) value) = GETMAC_TRUE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Resources allocated");
} else {
* ((GETMAC_BOOL *) value) = GETMAC_FALSE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Resources not allocated");
}
break;
case GETMAC_ATTR_IFF_NOARP: /* No address resolution protocol */
if (mi->buf[i].ifr_flags & IFF_NOARP) {
* ((GETMAC_BOOL *) value) = GETMAC_TRUE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "No address resolution protocol");
} else {
* ((GETMAC_BOOL *) value) = GETMAC_FALSE;
snprintf (err->errmsg, GETMAC_MAX_MSGLEN, "Has address resolution protocol");
}
break;