Use the LLINDEX macro to access the link-level I/F index. This makes

it possible to work with a different type for the sdl_index field --
it only requires a recompile.

Obtained from:	Juniper Networks, Inc.
This commit is contained in:
Marcel Moolenaar 2012-05-19 02:39:43 +00:00
parent 29d8e665ba
commit cf0d539f8b
5 changed files with 5 additions and 4 deletions

View File

@ -70,7 +70,7 @@ if_indextoname(unsigned int ifindex, char *ifname)
for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_LINK &&
ifindex == ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index)
ifindex == LLINDEX((struct sockaddr_dl*)ifa->ifa_addr))
break;
}

View File

@ -123,7 +123,7 @@ if_nameindex(void)
if (ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_LINK) {
ifni2->if_index =
((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index;
LLINDEX((struct sockaddr_dl*)ifa->ifa_addr);
ifni2->if_name = cp;
strcpy(cp, ifa->ifa_name);
ifni2++;

View File

@ -90,7 +90,7 @@ if_nametoindex(const char *ifname)
if (ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_LINK &&
strcmp(ifa->ifa_name, ifname) == 0) {
ni = ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index;
ni = LLINDEX((struct sockaddr_dl*)ifa->ifa_addr);
break;
}
}

View File

@ -120,7 +120,7 @@ __inaddr_to_index(in_addr_t ifaddr)
psu = (sockunion_t *)ifa->ifa_addr;
if (psu && psu->ss.ss_family == AF_LINK &&
strcmp(ifa->ifa_name, ifname) == 0) {
ifindex = psu->sdl.sdl_index;
ifindex = LLINDEX(&psu->sdl);
break;
}
}

View File

@ -67,6 +67,7 @@ struct sockaddr_dl {
};
#define LLADDR(s) ((caddr_t)((s)->sdl_data + (s)->sdl_nlen))
#define LLINDEX(s) ((s)->sdl_index)
#ifndef _KERNEL