Skip to content

Commit

Permalink
Example
Browse files Browse the repository at this point in the history
  • Loading branch information
ipfreely-uk committed Apr 4, 2024
1 parent b550366 commit 998a236
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ip/subnet/masks_example_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package subnet_test

import (
"fmt"

"github.com/ipfreely-uk/go/ip"
"github.com/ipfreely-uk/go/ip/subnet"
)
Expand All @@ -13,3 +15,18 @@ func Example_subnet_Mask() {
println("Last: %s", mask.Not().Or(network).String())
println("Mask: %s", mask.String())
}

func Example_subnet_AddressCount() {
family := ip.V4()
for mask := 0; mask <= family.Width(); mask++ {
count := subnet.AddressCount(family, mask)
msg := fmt.Sprintf("IPv%d /%d ==\t%s", family.Version(), mask, count.String())
println(msg)
}
// family = ip.V6()
// for mask := 0; mask <= family.Width(); mask++ {
// count := subnet.AddressCount(family, mask)
// msg := fmt.Sprintf("IPv%d /%d ==\t%s", family.Version(), mask, count.String())
// println(msg)
// }
}

0 comments on commit 998a236

Please sign in to comment.