From 56f0b37b25dfbc7a92dcf4a6b411fdf70bdcff72 Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Sat, 28 Nov 2020 21:56:39 +0000 Subject: Add function to convert new CIDR format netmasks to old style dotted quad. Replace setting of BROADCAST and NETWORK for use when writing files. --- netconfig | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'netconfig') 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: -- cgit v1.2.3