init/functions: better not use ipcalc which is not present on minimal distro

This commit is contained in:
Frédéric Pierret (fepitre) 2019-06-22 18:05:45 +02:00
parent dba1020b4c
commit 3f5dc53d75
No known key found for this signature in database
GPG Key ID: 484010B5CDC576E2

View File

@ -158,9 +158,13 @@ get_qubes_managed_iface() {
fi
}
# Based on: https://forums.gentoo.org/viewtopic-t-888736-start-0.html
get_prefix_from_subnet() {
local subnet="$1"
prefix="$(ipcalc -p 0.0.0.0 "$subnet" | sed 's/PREFIX=//')"
local x=${subnet##*255.}
set -- 0^^^128^192^224^240^248^252^254^ $(( (${#1} - ${#x})*2 )) "${x%%.*}"
x=${1%%$3*}
prefix=$(( $2 + (${#x}/4) ))
if [ "x$prefix" != "x" ]; then
echo "$prefix"