From 6b0fe7f6c1e1afc6f890a8650b2dcb7e91baab32 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Sat, 17 Feb 2024 15:49:38 +0900 Subject: [PATCH] wgConfGen: Fix to generating ipv6 addr --- wireguardConfigGenerator.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/wireguardConfigGenerator.sh b/wireguardConfigGenerator.sh index be2228e..0ebed1b 100755 --- a/wireguardConfigGenerator.sh +++ b/wireguardConfigGenerator.sh @@ -139,14 +139,10 @@ fi IPV6_SUBNET=$(( 128 - (32 - WG_SUBNET ) )) function to_ipv6_from_template() { - if (( $1 < (1 << 8) )); then + if (( $1 < (1 << 16) )); then echo "${IPV6_TEMPLATE/x/$(printf "%04x" "$1")}" - elif (( $1 < (1 << 16) )); then - echo "${IPV6_TEMPLATE/x/$(printf "%04x" $(( ($1 >> 8) & 0xFFFF )) ):$(printf "%04x" $(( $1 & 0xFFFF )) )}" - elif (( $1 < (1 << 24) )); then - echo "${IPV6_TEMPLATE/x/$(printf "%04x" $(( ($1 >> 16) & 0xFFFF)) ):$(printf "%04x" $(( ($1 >> 8) & 0xFFFF )) ):$(printf "%04x" $(( $1 & 0xFFFF )) )}" elif (( $1 < (1 << 32) )); then - echo "${IPV6_TEMPLATE/x/$(printf "%04x" $(( ($1 >> 24) & 0xFFFF)) ):$(printf "%04x" $(( ($1 >> 16) & 0xFFFF)) ):$(printf "%04x" $(( ($1 >> 8) & 0xFFFF )) ):$(printf "%04x" $(( $1 & 0xFFFF )) )}" + echo "${IPV6_TEMPLATE/x/$(printf "%04x" $(( ($1 >> 16) & 0xFFFF )) ):$(printf "%04x" $(( $1 & 0xFFFF )) )}" else echo "ERROR" return 1