diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net.sh | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/net.sh b/lib/net.sh new file mode 100644 index 000000000..518c955b6 --- /dev/null +++ b/lib/net.sh @@ -0,0 +1,9 @@ +net_netmask_to_prefix() {( + binaryNetmask=$(echo $1 | sed 's/^/obase=2;/;s/\./;/g' | bc | tr -d \\n) + binaryPrefix=$(echo $binaryNetmask | sed -n 's/^\(1*\)0*$/\1/p') + if ! echo $binaryPrefix | grep -q .; then + echo $0: bad netmask: $netmask >&2 + exit 4 + fi + printf %s $binaryPrefix | tr -d 0 | wc -c +)} |