svn commit: r360800 - stable/11/lib/libc/net

Kristof Provost kp at FreeBSD.org
Thu May 7 21:14:13 UTC 2020


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 */
 


More information about the svn-src-all mailing list