Skip to content

Commit

Permalink
Adding additional error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-trimble committed Jun 2, 2021
1 parent 4f444d9 commit db03eef
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"net"
"os"
"strconv"
"strings"
"text/tabwriter"
)
Expand Down Expand Up @@ -39,6 +40,18 @@ func main() {
ipRange = strings.TrimSpace(ipRange)
}

spl := strings.Split(ipRange, "/")
if len(spl) < 2 {
log.Fatal("bad cidr")
}
r, err := strconv.Atoi(spl[1])
if err != nil {
log.Fatal(err)
}
if r < 8 {
log.Fatal("range cannot be smaller than 8")
}

addr, network, err := net.ParseCIDR(ipRange)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit db03eef

Please sign in to comment.