v0.1.1
ADDED: * The -s/--size argument to the VLSM splitter may now be a comma-delimited list of sizes instead of needing to specify -s/--size for each size. This change is backwards-compatible.
This commit is contained in:
33
cmd/subnetter/funcs_vlsmsize.go
Normal file
33
cmd/subnetter/funcs_vlsmsize.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
`strconv`
|
||||
`strings`
|
||||
)
|
||||
|
||||
// Sizes returns a parsed/split slice of uint8s from a vlsmSize.
|
||||
func (v *vlsmSize) Sizes() (sizes []uint8, err error) {
|
||||
|
||||
var s []string
|
||||
var u uint64
|
||||
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
s = strings.Split(string(*v), ",")
|
||||
for idx, i := range s {
|
||||
s[idx] = strings.TrimSpace(i)
|
||||
}
|
||||
|
||||
sizes = make([]uint8, len(s))
|
||||
|
||||
// No validation is performed since we don't have access to the addr inet family; that's up to the parsers.
|
||||
for idx, i := range s {
|
||||
if u, err = strconv.ParseUint(i, 10, 8); err != nil {
|
||||
return
|
||||
}
|
||||
sizes[idx] = uint8(u)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user