mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-26 07:55:01 +00: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
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=360231
@ -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 New Issue
Block a user