aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-01-10 18:11:02 +0000
committerRoy Marples <roy@marples.name>2008-01-10 18:11:02 +0000
commit6244bcbe84aad1e1f62c063bfc47c76c6ebb66b4 (patch)
treef6d928386c03c9524592886bd7fd0d9cdc1f3178 /sh
parent6ca21b4c6a129ae563b39e6fa60ba005b5dd9aa6 (diff)
massage netmask to cidr for buggy shells.
Diffstat (limited to 'sh')
-rwxr-xr-xsh/net.sh16
1 files changed, 15 insertions, 1 deletions
diff --git a/sh/net.sh b/sh/net.sh
index 05081a7d..ab648a07 100755
--- a/sh/net.sh
+++ b/sh/net.sh
@@ -134,8 +134,22 @@ _wait_for_carrier() {
}
_netmask2cidr() {
- local i= len=0
+ # Some shells cannot handle hex arithmetic, so we massage it slightly
+ # Buggy shells include FreeBSD sh, dash and busybox.
+ # bash and NetBSD sh don't need this.
+ case $1 in
+ 0x*)
+ local hex=${1#0x*} quad=
+ while [ -n "${hex}" ]; do
+ local lastbut2=${hex#??*}
+ quad=${quad}${quad:+.}0x${hex%${lastbut2}*}
+ hex=${lastbut2}
+ done
+ set -- ${quad}
+ ;;
+ esac
+ local i= len=
local IFS=.
for i in $1; do
while [ ${i} != "0" ]; do