2 # Chet Ramey <chet.ramey@case.edu>
4 # Copyright 2002 Chester Ramey
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # TThis program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 # inet2hex - Internet address conversion, dotted-decimal to hex
30 if (( $# != 4 )); then
31 echo "inet2hex: incorrect input format: $1" >&2
32 echo "inet2hex: usage: inet2hex XX.XX.XX.XX" >&2
36 printf "0x%02x%02x%02x%02x\n" $1 $2 $3 $4
40 # hex2inet - Internet address conversion, hex to dotted-decimal
52 *) echo "hex2inet: usage: hex2inet [-r] [0x]XXXXXXXX" >&2 ; exit 2;;
55 shift $(( $OPTIND - 1 ))
62 if (( ${#h} != 8 )); then
63 echo "hex2inet: $h not in inet format" >&2
64 echo "hex2inet: usage: hex2inet [0x]XXXXXXXX" >&2
73 if [ -z "$rev" ] ; then
74 printf "%d.%d.%d.%d\n" $x1 $x2 $x3 $x4
76 printf "%d.%d.%d.%d\n" $x4 $x3 $x2 $x1