From: Ian Campbell Subject: Re: [PATCH 5/5] hotplug/linux: Add IPv6 support to vif-route Date: Tue, 20 May 2014 10:20:26 +0100 Message-ID: <1400577626.25175.21.camel@kazak.uk.xensource.com> References: <1400081005-23895-1-git-send-email-s.munaut@whatever-company.com> <1400081005-23895-6-git-send-email-s.munaut@whatever-company.com> <1400170848.883.16.camel@kazak.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WmgDm-0006K6-Te for xen-devel@lists.xenproject.org; Tue, 20 May 2014 09:20:31 +0000 In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Sylvain Munaut Cc: xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org On Tue, 2014-05-20 at 10:06 +0200, Sylvain Munaut wrote: > >> +## > >> +# ip6_of interface > >> +# > >> +# Print the first IPv6 address currently in use at the given interface, or nothing if > >> +# the interface is not up. > >> +# > >> +ip6_of() > >> +{ > >> + ip -6 addr show primary dev "$1" | perl -wane '/scope global/ && /inet6 (([0-9a-f]+:*)+)/ && print $1;' > > > > Hrm, Perl again. Can this be done with awk? Looks tricky though. > > > > Changed to : > > ip -6 -o addr show primary dev "$1" scope global | awk '$3 == "inet6" > {split($4,i,"/"); print i[1]; exit}' > > which is now very similar to the ip_of() function. thanks. In theory I think this could be combined into a single helper which took $2 == '4' or '6' and "ip -$2 | ... inet${2%4}.." (then ip_of and ip6_of become invocations of that) But perhaps the ${2%4} bit is overly cryptic? Ian.