1
0
Files
irix-657m-src/eoe/cmd/sun/netdisk/convert_to_hex
2022-09-29 17:59:04 +03:00

30 lines
950 B
Bash

#!/bin/sh
#
# IP to hex converter
# Handles all three classes of addresses (A, B & C)
#
# Method:
# echo argument into stdin of awk
# use awk to separate fields and provide input to dc
# use dc to calculate the IP address value and print it out in hex
# use awk to pad to 8 bytes, if necessary
#
# @(#)convert_to_hex 1.1 88/06/08 4.0NFSSRC; from 1.4 88/03/07 D/NFS
# @(#) from convert_to_hex 1.10 88/02/08
#
# Copyright (c) 1987 by Sun Microsystems, Inc.
#
HOME=/; export HOME
PATH=/bin:/usr/bin:/etc:/usr/etc:/usr/etc/netdisk:/usr/bsd
echo $1 | \
awk 'BEGIN { FS="."; OFS=" "; print "16 o"; } { \
print $1; \
if (NF == 4) { print "256 *", $2, "+ 256 *", $3, "+ 256 *", $4; } \
if (NF == 3) { print "256 *", " 256 *", $2, "+ 256 *", $3; } \
if (NF == 2) { print "256 *", " 256 *", " 256 *", $2; } \
print "+ p"; }' | \
dc | \
awk 'BEGIN { ORS=""; } { \
for (i = length($1); i < 8; i++) { print "0"; }; print $1, "\n" }'