From 3f5dc53d75d3acc5d9324e382034f65ce25cbfca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret=20=28fepitre=29?= Date: Sat, 22 Jun 2019 18:05:45 +0200 Subject: [PATCH] init/functions: better not use ipcalc which is not present on minimal distro --- init/functions | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/init/functions b/init/functions index d4cbdcf..7b99599 100644 --- a/init/functions +++ b/init/functions @@ -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"