zsh-workers
 help / color / mirror / code / Atom feed
From: Eric Cook <llua@gmx.com>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] _find_net_interfaces: use /sys/class/net/* for interface names in linux
Date: Tue, 11 Aug 2015 20:25:48 -0400	[thread overview]
Message-ID: <55CA928C.5030203@gmx.com> (raw)
In-Reply-To: <27319.1439286441@thecus.kiddle.eu>

[-- Attachment #1: Type: text/plain, Size: 834 bytes --]

On 08/11/2015 05:47 AM, Oliver Kiddle wrote:
> Eric Cook wrote:
>> I also wasn't able to find the type of tunnels mentioned in
>> http://www.zsh.org/mla/workers/2007/msg00111.html that doesn't show up
>> in /proc/sys/net/ipv4/conf/. Maybe at some point since then, that was
>> fixed. But to avoid some kind of regression /sys/class/net/ seems usable
>> for the time being.
> 
> One example, is aliases. So if you do something like
>   ifconfig eth0:1 192.168.42.37
> then ifconfig will show eth0:1 while /sys/class won't.

When i switched to parsing ip(8), those alias interface names were no longer being shown.

So the following patch removes the linux block in the case statement, yet again.
Use ifconfig, but with _call_program. If ifconfig doesn't find anything, fall back to
/proc/sys/net/ipv4/conf/* and now /sys/class/net/*.


[-- Attachment #2: 0001-_find_net_interfaces-use-sys-class-net-for-interface-v3.patch --]
[-- Type: text/x-patch, Size: 1508 bytes --]

diff --git a/Completion/Unix/Type/_find_net_interfaces b/Completion/Unix/Type/_find_net_interfaces
index 0c70335..32ab79b 100644
--- a/Completion/Unix/Type/_find_net_interfaces
+++ b/Completion/Unix/Type/_find_net_interfaces
@@ -21,22 +21,15 @@ case $OSTYPE in
   ;;
   darwin*|freebsd*|dragonfly*) net_intf_list=( $(ifconfig -l) ) ;;
   irix*) net_intf_list=( ${${${(f)"$(/usr/etc/netstat -i)"}%% *}[2,-1]} ) ;;
-  *linux*)
-    if (( $+commands[ip] )); then
-      net_intf_list=( ${${(m)${(f)"$(ip -o link)"}#*: }%%: *} )
-    fi
-  ;&
-
   *)
-  if [[ ${#net_intf_list} -eq 0 ]]; then
     # linux's deprecated ifconfig may truncate long interface names
-    net_intf_list=( $(ifconfig -a 2>/dev/null | sed -n 's/^\([^ 	:]*\).*/\1/p') )
-    if [[ -d /proc/sys/net/ipv4/conf ]]; then
+    net_intf_list=( $(_call_program interfaces "ifconfig -a 2>/dev/null | sed -n 's/^\([^ 	:]*\).*/\1/p'") )
+    if (( ${#net_intf_list} == 0 )) && [[ -d /proc/sys/net/ipv4/conf ]]; then
       # On linux we used to use the following as the default, without /sys/class/net/*.
-      # However, we now use ip or ifconfig since it finds additional devices such
+      # However, we now use ifconfig since it finds additional devices such
       # as tunnels.  So only do this if that didn't work.
-      net_intf_list=( /proc/sys/net/ipv4/conf/*~*(all|default)(N:t) )
+      typeset -gU net_intf_list
+      net_intf_list=( /proc/sys/net/ipv4/conf/*~*(all|default)(N:t) /sys/class/net/*(N:t) )
     fi
-  fi
   ;;
 esac

      parent reply	other threads:[~2015-08-12  0:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-11  0:49 Eric Cook
2015-08-11  9:47 ` Oliver Kiddle
2015-08-11 13:27   ` Eric Cook
2015-08-12  0:25   ` Eric Cook [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55CA928C.5030203@gmx.com \
    --to=llua@gmx.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).