Imported from ../bash-2.02.tar.gz.
This commit is contained in:
parent
e8ce775db8
commit
cce855bc5b
323 changed files with 33916 additions and 12321 deletions
44
examples/functions/inetaddr
Normal file
44
examples/functions/inetaddr
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#
|
||||
# inet2hex - Internet address conversion, dotted-decimal to hex
|
||||
#
|
||||
inet2hex ()
|
||||
{
|
||||
local IFS
|
||||
|
||||
IFS=.
|
||||
set -- $1
|
||||
|
||||
if (( $# != 4 )); then
|
||||
echo "inet2hex: incorrect input format: $1" >&2
|
||||
echo "inet2hex: usage: inet2hex XX.XX.XX.XX" >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
printf "0x%02x%02x%02x%02x\n" $1 $2 $3 $4
|
||||
}
|
||||
|
||||
#
|
||||
# hex2inet - Internet address conversion, hex to dotted-decimal
|
||||
#
|
||||
hex2inet ()
|
||||
{
|
||||
local x1 x2 x3 x4
|
||||
|
||||
case "$1" in
|
||||
0x*) h=${1#??} ;;
|
||||
*) h=$1 ;;
|
||||
esac
|
||||
|
||||
if (( ${#h} != 8 )); then
|
||||
echo "hex2inet: $h not in inet format" >&2
|
||||
echo "hex2inet: usage: hex2inet [0x]XXXXXXXX" >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
x1=$(( 0x${h:0:2} ))
|
||||
x2=$(( 0x${h:2:2} ))
|
||||
x3=$(( 0x${h:4:2} ))
|
||||
x4=$(( 0x${h:6:2} ))
|
||||
|
||||
printf "%d.%d.%d.%d\n" $x1 $x2 $x3 $x4
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue