CVS commit: [netbsd-8] src/lib/libc/net

2018-09-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Sep  5 08:45:52 UTC 2018

Modified Files:
src/lib/libc/net [netbsd-8]: if_nametoindex.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1007):

lib/libc/net/if_nametoindex.c: revision 1.6

- SIOCGIFINDEX was added in 2013, but if_freenameindex(3) have not used it
   for years. Use it to improve performance. Same as FreeBSD.

- KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.5.8.1 src/lib/libc/net/if_nametoindex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/if_nametoindex.c
diff -u src/lib/libc/net/if_nametoindex.c:1.5 src/lib/libc/net/if_nametoindex.c:1.5.8.1
--- src/lib/libc/net/if_nametoindex.c:1.5	Tue Sep  1 09:54:34 2015
+++ src/lib/libc/net/if_nametoindex.c	Wed Sep  5 08:45:52 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_nametoindex.c,v 1.5 2015/09/01 09:54:34 ozaki-r Exp $	*/
+/*	$NetBSD: if_nametoindex.c,v 1.5.8.1 2018/09/05 08:45:52 martin Exp $	*/
 /*	$KAME: if_nametoindex.c,v 1.6 2000/11/24 08:18:54 itojun Exp $	*/
 
 /*-
@@ -28,19 +28,21 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: if_nametoindex.c,v 1.5 2015/09/01 09:54:34 ozaki-r Exp $");
+__RCSID("$NetBSD: if_nametoindex.c,v 1.5.8.1 2018/09/05 08:45:52 martin Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
 #include "namespace.h"
 #endif
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #ifndef RUMP_ACTION
@@ -71,11 +73,24 @@ __weak_alias(if_nametoindex,_if_nametoin
 unsigned int
 if_nametoindex(const char *ifname)
 {
+	int s;
+	struct ifreq ifr;
 	struct ifaddrs *ifaddrs, *ifa;
 	unsigned int ni;
 
+	s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (s != -1) {
+		memset(, 0, sizeof(ifr));
+		strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+		if (ioctl(s, SIOCGIFINDEX, ) != -1) {
+			close(s);
+			return (ifr.ifr_index);
+		}
+		close(s);
+	}
+
 	if (getifaddrs() < 0)
-		return(0);
+		return 0;
 
 	ni = 0;
 
@@ -92,5 +107,5 @@ if_nametoindex(const char *ifname)
 	freeifaddrs(ifaddrs);
 	if (!ni)
 		errno = ENXIO;
-	return(ni);
+	return ni;
 }



CVS commit: [netbsd-8] src/lib/libc/net

2017-07-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jul  4 12:54:30 UTC 2017

Modified Files:
src/lib/libc/net [netbsd-8]: Makefile.inc

Log Message:
Pull up following revision(s) (requested by manu in ticket #78):
lib/libc/net/Makefile.inc: revision 1.87
Include IPv6 global variable in USE_INET6=no libc
This ensures a binary built with USE_INET6=yes libc can still link at
runtime with a USE_INET6=no libc. Of course IPv6 functionnality is not
available, but dynamic linking is not killed by missing symbols such
as in6addr_any.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.86.8.1 src/lib/libc/net/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/Makefile.inc
diff -u src/lib/libc/net/Makefile.inc:1.86 src/lib/libc/net/Makefile.inc:1.86.8.1
--- src/lib/libc/net/Makefile.inc:1.86	Wed Apr 15 19:13:46 2015
+++ src/lib/libc/net/Makefile.inc	Tue Jul  4 12:54:30 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.86 2015/04/15 19:13:46 mrg Exp $
+#	$NetBSD: Makefile.inc,v 1.86.8.1 2017/07/04 12:54:30 martin Exp $
 #	@(#)Makefile.inc	8.2 (Berkeley) 9/5/93
 
 # net sources
@@ -21,8 +21,9 @@ SRCS+=	hesiod.c
 
 SRCS+=	getaddrinfo.c getnameinfo.c
 .if (${USE_INET6} != "no")
-SRCS+=	ip6opt.c rthdr.c vars6.c inet6_scopeid.c
+SRCS+=	ip6opt.c rthdr.c inet6_scopeid.c
 .endif
+SRCS+=	vars6.c
 SRCS+=	if_indextoname.c if_nameindex.c if_nametoindex.c
 
 LPREFIX=_nsyy