Date: Thu, 7 May 2020 21:14:11 +0000 (UTC) From: Kristof Provost <kp@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r360799 - stable/12/lib/libc/net Message-ID: <202005072114.047LEBOw094808@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005072114.047LEBOw094808>