From cf0d539f8ba172e983e81349d5399c304afc41e3 Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Sat, 19 May 2012 02:39:43 +0000 Subject: [PATCH] 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. --- lib/libc/net/if_indextoname.c | 2 +- lib/libc/net/if_nameindex.c | 2 +- lib/libc/net/if_nametoindex.c | 2 +- lib/libc/net/sourcefilter.c | 2 +- sys/net/if_dl.h | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/libc/net/if_indextoname.c b/lib/libc/net/if_indextoname.c index 4dadce351ad9..4b16433a4ee6 100644 --- a/lib/libc/net/if_indextoname.c +++ b/lib/libc/net/if_indextoname.c @@ -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; } diff --git a/lib/libc/net/if_nameindex.c b/lib/libc/net/if_nameindex.c index 7a12d34b58e7..138289c6814e 100644 --- a/lib/libc/net/if_nameindex.c +++ b/lib/libc/net/if_nameindex.c @@ -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++; diff --git a/lib/libc/net/if_nametoindex.c b/lib/libc/net/if_nametoindex.c index 9d47089971e4..89076c0e021c 100644 --- a/lib/libc/net/if_nametoindex.c +++ b/lib/libc/net/if_nametoindex.c @@ -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; } } diff --git a/lib/libc/net/sourcefilter.c b/lib/libc/net/sourcefilter.c index cc0f1b971e91..4d29d9f36e0b 100644 --- a/lib/libc/net/sourcefilter.c +++ b/lib/libc/net/sourcefilter.c @@ -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; } } diff --git a/sys/net/if_dl.h b/sys/net/if_dl.h index 8d88623db856..64f4b56d76e6 100644 --- a/sys/net/if_dl.h +++ b/sys/net/if_dl.h @@ -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