Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: tweak _net_interfaces



On Linux we use the /proc filing system to find network interfaces.
However, that doesn't find everything, in particular tunnels, which
both ifconfig and ip can manipulate.

The following tries to be safe by using the output of ifconfig unless it
didn't return any results.

Index: Completion/Unix/Type/_net_interfaces
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_net_interfaces,v
retrieving revision 1.3
diff -u -r1.3 _net_interfaces
--- Completion/Unix/Type/_net_interfaces	11 May 2005 09:27:10 -0000	1.3
+++ Completion/Unix/Type/_net_interfaces	26 Feb 2007 15:13:10 -0000
@@ -14,8 +14,19 @@
   ;;
   darwin*|freebsd*|dragonfly*) intf=( $(ifconfig -l) ) ;;
   irix*) intf=( ${${${(f)"$(/usr/etc/netstat -i)"}%% *}[2,-1]} ) ;;
-  linux*) intf=( /proc/sys/net/ipv4/conf/*~*(all|default)(N:t) ) ;;
-  *) intf=( $(ifconfig -a|sed -n 's/^\([^ 	:]*\).*/\1/p') ) ;;
+
+  *)
+  # Make sure ifconfig is in the path.
+  local PATH=$PATH
+  PATH=/sbin:$PATH
+  intf=( $(ifconfig -a 2>/dev/null | sed -n 's/^\([^ 	:]*\).*/\1/p') )
+  if [[${#intf} -eq 0 &&  -d /proc/sys/net/ipv4/conf ]]; then
+    # On linux we used to use the following as the default.
+    # However, we now use ifconfig since it finds additional devices such
+    # as tunnels.  So only do this if that didn't work.
+    intf=( /proc/sys/net/ipv4/conf/*~*(all|default)(N:t) )
+  fi
+  ;;
 esac
 
 _wanted interfaces expl 'network interface' \

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview



Messages sorted by: Reverse Date, Date, Thread, Author