Author: kp Date: Thu May 7 21:14:11 2020 New Revision: 360799 URL: https://svnweb.freebsd.org/changeset/base/360799
Log: MFC r360231: 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 Sponsored by: RG Nets Modified: stable/12/lib/libc/net/if_indextoname.c Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/libc/net/if_indextoname.c ============================================================================== --- stable/12/lib/libc/net/if_indextoname.c Thu May 7 20:29:38 2020 (r360798) +++ stable/12/lib/libc/net/if_indextoname.c Thu May 7 21:14:11 2020 (r360799) @@ -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 */ _______________________________________________ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"