summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren 'Tadgy' Austin <darren@afterdark.org.uk>2020-11-28 21:56:39 +0000
committerRobby Workman <rworkman@slackware.com>2021-02-27 23:47:58 -0600
commit56f0b37b25dfbc7a92dcf4a6b411fdf70bdcff72 (patch)
tree35f0283d563b5fdfb4d0799532d75d1a4d1294b9
parentbb5d94a4b50b1ba9bcdf9cc3c034492fec509efe (diff)
downloadslacknetsetup-56f0b37b25dfbc7a92dcf4a6b411fdf70bdcff72.tar.xz
Add function to convert new CIDR format netmasks to old style dotted quad.
Replace setting of BROADCAST and NETWORK for use when writing files.
-rw-r--r--netconfig14
1 files changed, 13 insertions, 1 deletions
diff --git a/netconfig b/netconfig
index acb9a85..0f1ce44 100644
--- a/netconfig
+++ b/netconfig
@@ -356,6 +356,14 @@ fi
rm -f $TMP/tempmsg /cardfound
} # end write_config_files
+# Covert CIDR notation masks to old style dotted quad.
+cidr2mask() {
+ # https://forum.archive.openwrt.org/viewtopic.php?id=47986&p=1#p220781
+ set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
+ [ $1 -gt 1 ] && shift $1 || shift
+ echo "${1-0}.${2-0}.${3-0}.${4-0}"
+}
+
# This checks IPv4 address syntax.
# usage: syntax_check_v4 ADDRESS #-OF-EXPECTED-SEGMENTS (up to 4)
# example: syntax_check_v4 123.22.43.1 4
@@ -635,7 +643,6 @@ else
fi
if [ "$LOOPBACK" = "no" -a ! "$USE_DHCP" = "yes" -a ! "$USE_SLAAC" = "yes" ]; then
-# FIXME: need to check the logic in these:
while [ 0 ]; do
while [ 0 ]; do
if [ -r $TMP/SeTIPSv4 ]; then
@@ -1068,6 +1075,11 @@ can do that now using 'Edit' (or reconfigure later using 'netconfig')." \
break
fi
done
+ if [ ! "${IPADDRS[0]}" = "" ]; then
+ NM="$(cidr2mask "${IPADDRS[0]#*/}")"
+ BROADCAST="$(ipmask "$NM" "${IPADDRS[0]%/*}" | cut -f 1 -d ' ')"
+ NETWORK="$(ipmask "$NM" "${IPADDRS[0]%/*}" | cut -f 2 -d ' ')"
+ fi
else # DHCP was used
dialog --title "CONFIRM NETWORK SETUP" \
--yesno "Your networking system is now configured to use DHCP: