Skip to content

Commit

Permalink
aix: add netmask, mac address into net interfaces
Browse files Browse the repository at this point in the history
uv_interface_addresses API extracts the network interface entries.
In AIX, this was not fully implemented. retrieve the network mask and
the mac addresses.

Fixes: nodejs/node#14119
  • Loading branch information
gireeshpunathil committed Jul 8, 2017
1 parent 8658ef0 commit c523e1a
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/unix/aix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,10 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int uv_interface_addresses(uv_interface_address_t** addresses,
int* count) {
uv_interface_address_t* address;
int sockfd, size = 1;
int sockfd, inet6, size = 1;
struct ifconf ifc;
struct ifreq *ifr, *p, flg;
struct sockaddr_dl* sa_addr;

*count = 0;

Expand Down Expand Up @@ -1077,13 +1078,17 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
ifr = ifc.ifc_req;
while ((char*)ifr < (char*)ifc.ifc_req + ifc.ifc_len) {
p = ifr;
inet6 = 0;
ifr = (struct ifreq*)
((char*)ifr + sizeof(ifr->ifr_name) + ADDR_SIZE(ifr->ifr_addr));

if (!(p->ifr_addr.sa_family == AF_INET6 ||
p->ifr_addr.sa_family == AF_INET))
continue;

if (p->ifr_addr.sa_family == AF_INET6)
inet6 = 1;

memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) {
uv__close(sockfd);
Expand All @@ -1097,13 +1102,26 @@ int uv_interface_addresses(uv_interface_address_t** addresses,

address->name = uv__strdup(p->ifr_name);

if (p->ifr_addr.sa_family == AF_INET6) {
if (inet6) {
address->address.address6 = *((struct sockaddr_in6*) &p->ifr_addr);
} else {
address->address.address4 = *((struct sockaddr_in*) &p->ifr_addr);
}

/* TODO: Retrieve netmask using SIOCGIFNETMASK ioctl */
memset(address->phys_addr, 0, sizeof(address->phys_addr));
sa_addr = (struct sockaddr_dl*) &p->ifr_addr;
memcpy(address->phys_addr, LLADDR(sa_addr), sizeof(address->phys_addr));

if (ioctl(sockfd, SIOCGIFNETMASK, p) == -1) {
uv__close(sockfd);
return -ENOSYS;
}

if (inet6) {
address->netmask.netmask6 = *((struct sockaddr_in6*) &p->ifr_addr);
} else {
address->netmask.netmask4 = *((struct sockaddr_in*) &p->ifr_addr);
}

address->is_internal = flg.ifr_flags & IFF_LOOPBACK ? 1 : 0;

Expand Down

0 comments on commit c523e1a

Please sign in to comment.