Skip to content

Commit

Permalink
Merge pull request #19 from erikh/fix-subnet-calculation
Browse files Browse the repository at this point in the history
Fix off-by-one in subnet calculation
  • Loading branch information
erikh authored Apr 9, 2022
2 parents b4db027 + 3591816 commit 7edf477
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var networkTemplate string
const (
magicComment = "--- Managed by zerotier-systemd-manager. Do not remove this comment. ---"
networkDir = "/etc/systemd/network"
ipv4bits = net.IPv4len * 8
ipv4bits = 32
)

// parameter list for multiple template operations
Expand Down Expand Up @@ -158,14 +158,15 @@ func main() {
}

used, total := ipnet.Mask.Size()
bits := int(math.Ceil(float64(total) / float64(used)))

octets := make([]byte, bits)
bits := int(math.Trunc(math.Ceil(float64(total) / float64(used))))

octets := make([]byte, bits+1)
if total == ipv4bits {
ip = ip.To4()
}

for i := 0; i < bits; i++ {
for i := 0; i <= bits; i++ {
octets[i] = ip[i]
}

Expand Down

0 comments on commit 7edf477

Please sign in to comment.