From 3809eac54d575d52d8793df38f826f1d7d7398fb Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Wed, 7 Nov 2012 00:13:58 +0000 Subject: [PATCH] net/iwconfig: Even more bashism fun. Signed-off-by: Robin H. Johnson --- net/ip6rd.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/net/ip6rd.sh b/net/ip6rd.sh index 03b5897f..a35e2b76 100644 --- a/net/ip6rd.sh +++ b/net/ip6rd.sh @@ -117,27 +117,34 @@ _ip6rd_inet_atoi() { local IFS="${IFS}." ipi=0 j=3 for i in $1 ; do - ipi=$(( ipi | i << 8*j-- )) + # post-decrement isn't valid + ipi=$(( ipi | (i << (8*j)) )) + j=$(( j - 1 )) done echo ${ipi} } _ip6rd_inet_itoa() { - local ipi=$1 + local ipi=$1 bitmask v + bitmask=$(( (1 << 24)-1 )) for i in 0 1 2 3; do + v=$(( (ipi & ~bitmask) >> 24 )) + ipi=$(( (ipi & bitmask) << 8 )) if [ $i != 3 ] ; then - printf "%d." $(( (ipi & ~((1<<24)-1)) >> 24 )) - ipi=$(( (ipi & ((1<<24)-1)) << 8)) + printf "%d." $v else - printf "%d\n" $(( (ipi & ~((1<<24)-1)) >> 24 )) + printf "%d\n" $v fi done } _ip6rd_inet_get_network() { - echo $(_ip6rd_inet_itoa $(( ($(_ip6rd_inet_atoi $1) & ((1<<$2)-1) << (32-$2) ) )) ) + local a=$(_ip6rd_inet_atoi $1) + local net=$(( a & ( (1<<$2)-1 ) )) + local cidr=$(( 32 - $2 )) + echo $(_ip6rd_inet_itoa $(( (net << cidr ) )) ) } _ip6rd_inet_is_private_network()