Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 May 2020 21:14:12 +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-11@freebsd.org
Subject:   svn commit: r360800 - stable/11/lib/libc/net
Message-ID:  <202005072114.047LECSA094852@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kp
Date: Thu May  7 21:14:12 2020
New Revision: 360800
URL: https://svnweb.freebsd.org/changeset/base/360800

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/11/lib/libc/net/if_indextoname.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libc/net/if_indextoname.c
==============================================================================
--- stable/11/lib/libc/net/if_indextoname.c	Thu May  7 21:14:11 2020	(r360799)
+++ stable/11/lib/libc/net/if_indextoname.c	Thu May  7 21:14:12 2020	(r360800)
@@ -64,6 +64,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.047LECSA094852>