Date: Thu, 23 Apr 2020 21:16:52 +0000 (UTC) From: Kristof Provost <kp@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360231 - head/lib/libc/net Message-ID: <202004232116.03NLGq7N076570@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kp Date: Thu Apr 23 21:16:51 2020 New Revision: 360231 URL: https://svnweb.freebsd.org/changeset/base/360231 Log: 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 Modified: head/lib/libc/net/if_indextoname.c Modified: head/lib/libc/net/if_indextoname.c ============================================================================== --- head/lib/libc/net/if_indextoname.c Thu Apr 23 20:14:59 2020 (r360230) +++ head/lib/libc/net/if_indextoname.c Thu Apr 23 21:16:51 2020 (r360231) @@ -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?202004232116.03NLGq7N076570>