Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func main() {
AutoAggregate(nets, aaSettings)
nets = PackNETs(nets)
if *logStatistic {
log.Printf("After auto aggregate: %v networks/IPs with %v IPs coverage. Removed %.2v%% records (%v). Add %.2v%% IPs coverage (%v).\n", len(nets), nets.Count(), float32(netsL-len(nets))*100/float32(netsL), netsL-len(nets), float32(nets.Count()-netsC)*100/float32(netsC), nets.Count()-netsC)
log.Printf("After auto aggregate: %v networks/IPs with %v IPs coverage. Removed %.2v%% records (%v). Add %.2f%% IPs coverage (%v).\n", len(nets), nets.Count(), float32(netsL-len(nets))*100/float32(netsL), netsL-len(nets), float32(nets.Count()-netsC)*100/float32(netsC), nets.Count()-netsC)
}
}

Expand Down
49 changes: 46 additions & 3 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,44 @@ import (
"strings"
)

func isHex(b uint8) bool {
return (b >= '0' && b <= '9') ||
(b >= 'a' && b <= 'f')
}

func ParseV6Word(s string) (word string, i int) {
var w string
for i < len(s) && i < 4 && isHex(s[i]) {
w += string(s[i])
i++
}
word = w
return
}

func ParseIPv6(s string) (ip string, i int) {
for j := 0; j < 8; j++ {
word, skip := ParseV6Word(s[i:])
if skip == 0 {
return "", 0
}
ip += word
i += skip

if j < 7 {
if i >= len(s) || s[i] != ':' {
return "", 0
}
i++
} else {
if i < len(s) && s[i] >= '0' && s[i] <= '9' {
return "", 0
}
}
}
return
}

func isD(b uint8) bool { return b >= '0' && b <= '9' }

// Does not check anything after, ParseIPv4 do it.
Expand Down Expand Up @@ -120,10 +158,15 @@ func ParseIPsRow(s string) (nets NETv4s, ok bool) {
s = strings.TrimSpace(s[1:])
net, i := ParseNETv4(s)
if i == 0 {
return nil, false
_, i := ParseIPv6(s)
if i == 0 {
return nil, false
}
s = strings.TrimSpace(s[i:])
} else {
nets = append(nets, net)
s = strings.TrimSpace(s[i:])
}
nets = append(nets, net)
s = strings.TrimSpace(s[i:])
case ';':
return nets, true
default:
Expand Down