From b695d548a37dceacb42f504346fbbf1a12fbfb73 Mon Sep 17 00:00:00 2001 From: Sheldon Hearn Date: Mon, 19 Nov 2001 11:41:51 +0000 Subject: [PATCH] Use shell functions for printing hex instead of printf(1) so that printf(1) can be dropped from the system shell as a shell builtin. --- etc/rc.d/network_ipv6 | 36 ++++++++++++++++++++++++++++++++++-- etc/rc.network6 | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/etc/rc.d/network_ipv6 b/etc/rc.d/network_ipv6 index 99f6b32c8fc..1dc8473e0d8 100644 --- a/etc/rc.d/network_ipv6 +++ b/etc/rc.d/network_ipv6 @@ -32,6 +32,37 @@ # first before contemplating any changes here. If you do need to change # this file for some reason, we would like to know about it. +hexdigit () { + if [ $1 -lt 10 ]; then + echo $1 + else + case $1 in + 10) echo a ;; + 11) echo b ;; + 12) echo c ;; + 13) echo d ;; + 14) echo e ;; + 15) echo f ;; + esac + fi +} + +hexprint () { + val=$1 + str='' + + dig=`hexdigit $((${val} & 15))` + str=${dig}${str} + val=$((${val} >> 4)) + while [ ${val} -gt 0 ]; do + dig=`hexdigit $((${val} & 15))` + str=${dig}${str} + val=$((${val} >> 4)) + done + + echo ${str} +} + # IPv6 startup network6_pass1() { @@ -336,8 +367,9 @@ network6_stf_setup() { IFS=".$IFS" set ${stf_interface_ipv4addr} IFS="$OIFS" - ipv4_in_hexformat=`printf "%x:%x\n" \ - $(($1*256 + $2)) $(($3*256 + $4))` + hexfrag1=`hexprint $(($1*256 + $2))` + hexfrag2=`hexprint $(($3*256 + $4))` + ipv4_in_hexformat="${hexfrag1}:${hexfrag2}" case ${stf_interface_ipv6_ifid} in [Aa][Uu][Tt][Oo] | '') for i in ${ipv6_network_interfaces}; do diff --git a/etc/rc.network6 b/etc/rc.network6 index 99f6b32c8fc..1dc8473e0d8 100644 --- a/etc/rc.network6 +++ b/etc/rc.network6 @@ -32,6 +32,37 @@ # first before contemplating any changes here. If you do need to change # this file for some reason, we would like to know about it. +hexdigit () { + if [ $1 -lt 10 ]; then + echo $1 + else + case $1 in + 10) echo a ;; + 11) echo b ;; + 12) echo c ;; + 13) echo d ;; + 14) echo e ;; + 15) echo f ;; + esac + fi +} + +hexprint () { + val=$1 + str='' + + dig=`hexdigit $((${val} & 15))` + str=${dig}${str} + val=$((${val} >> 4)) + while [ ${val} -gt 0 ]; do + dig=`hexdigit $((${val} & 15))` + str=${dig}${str} + val=$((${val} >> 4)) + done + + echo ${str} +} + # IPv6 startup network6_pass1() { @@ -336,8 +367,9 @@ network6_stf_setup() { IFS=".$IFS" set ${stf_interface_ipv4addr} IFS="$OIFS" - ipv4_in_hexformat=`printf "%x:%x\n" \ - $(($1*256 + $2)) $(($3*256 + $4))` + hexfrag1=`hexprint $(($1*256 + $2))` + hexfrag2=`hexprint $(($3*256 + $4))` + ipv4_in_hexformat="${hexfrag1}:${hexfrag2}" case ${stf_interface_ipv6_ifid} in [Aa][Uu][Tt][Oo] | '') for i in ${ipv6_network_interfaces}; do