mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
libc: Shortcut if_indextoname() if index == 0
If the index we're trying to convert is 0 we can avoid a potentially expensive call to getifaddrs(). No interface has an ifindex of zero, so we can handle this as an error: set the errno to ENXIO and return NULL. Submitted by: Nick Rogers Reviewed by: lutz at donnerhacke.de MFC after: 2 weeks Sponsored by: RG Nets Differential Revision: https://reviews.freebsd.org/D24524
This commit is contained in:
parent
9d433cb875
commit
36dcd97de3
1 changed files with 5 additions and 0 deletions
|
|
@ -66,6 +66,11 @@ if_indextoname(unsigned int ifindex, char *ifname)
|
|||
struct ifaddrs *ifaddrs, *ifa;
|
||||
int error = 0;
|
||||
|
||||
if (ifindex == 0) {
|
||||
errno = ENXIO;
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if (getifaddrs(&ifaddrs) < 0)
|
||||
return(NULL); /* getifaddrs properly set errno */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue