From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17785 invoked by alias); 12 Aug 2015 00:25:59 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36113 Received: (qmail 11103 invoked from network); 12 Aug 2015 00:25:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 Subject: Re: [PATCH] _find_net_interfaces: use /sys/class/net/* for interface names in linux To: zsh-workers@zsh.org References: <1439254143-4608-1-git-send-email-llua@gmx.com> <27319.1439286441@thecus.kiddle.eu> From: Eric Cook X-Enigmail-Draft-Status: N1110 Message-ID: <55CA928C.5030203@gmx.com> Date: Tue, 11 Aug 2015 20:25:48 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <27319.1439286441@thecus.kiddle.eu> Content-Type: multipart/mixed; boundary="------------080106090209020400040908" X-Provags-ID: V03:K0:UdcyqgjvHpXfVyQ2BQsq66ydCGaQWtreQROfok8V517WcPUsBPc pfrFm8zhWFqwZPGR3OSx/9383CNWdjequlV1Ru2WNAjPnuXiQPNk6tXGZ2xiK3yP15r46bt 5yEziwN1HHmAxl60u23hPVQ8yBOSZ4wzSSMXpjTJsz0oVV3d5pg2mYdj83I9xPgKJ1Jv/S2 Wz1qoWv1kW9iAe9BYdJow== X-UI-Out-Filterresults: notjunk:1;V01:K0:Ww/owOjUEnw=:oxuuXeX8I3GbXMtWyTOPF1 4YSkoWiTcDd5EjDFzgETE0YcO84CHbxXp/9dz3JW/8NZ8JXt5bxtvfLhSPixhbhaY1+20r8Oh lp/XryWIdVceqHDoOXhUsUbXljHOgSrNi9Ou0h8NYEtxfpF92ujilm04Zm6e+FufeTAD7EV4f gZP3aKQPClXIs7CA2JtMVG9hPqgBn3jE41gNKuCf1aO50q5x7T8CjQwh6g2ocLlBOdNNsl5Sp vveyjFAsHjnvYALYwT8NyQR7TY9Ys3Hn8NU7P3t6R7z+Jlw0toDgR36TspVUzswh8QXwSSPa0 yDjCo/RtZ/MbUuQTT77MNfArAe44QAovjEX8Q3TqimWGwvDpbDgsZAPkXyMg09Lf9F7x8OISn vYlWYzqdmWojEN/rQXAGnyScne8N2JjMTqQ+KH0rtJ8p5X+0w6a9o5i1rrCLwxBWGlRyVbkf8 am8cE1R4JXtEfDBqow/yeCCxopH8VjXEy96lB56bUm2p8nIVjvwTWmn7a2lOzNYB77vFGSizj enbB2mAePrCdeKEIielVvhdrITzWgO350HXjX5zaytIiqsq26Q8D+fK8bGRE3X7Cbc73Ab1JG YgCoyZflLGgWIP7ABjo7mWFC68RyjaEjqqHtcqxELdAP6q9ySXfNcaarN27GrelTs9FtGGl/d e2fHMGEkaIkS3/U2DX1QRiOKyqHb6cslcUCngIZ0F8w/oF3/HCOUJfwDjd4yd+kO8IZAYENSu NtJoYs16GsHT5YzD --------------080106090209020400040908 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit 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/*. --------------080106090209020400040908 Content-Type: text/x-patch; name="0001-_find_net_interfaces-use-sys-class-net-for-interface-v3.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-_find_net_interfaces-use-sys-class-net-for-interface-v3"; filename*1=".patch" 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 --------------080106090209020400040908--