Skip to content

Commit

Permalink
lib: use fixed IP selection function
Browse files Browse the repository at this point in the history
Last release introduced a fixed firstOfEachIPFamily function, but didn't
integrate it.
  • Loading branch information
tsenart committed Jul 27, 2024
1 parent 1799abc commit ce93cd8
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions lib/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,20 +329,7 @@ func DNSCaching(ttl time.Duration) func(*Attacker) {

rng.Shuffle(len(ips), func(i, j int) { ips[i], ips[j] = ips[j], ips[i] })

// In place filtering of ips to only include the first IPv4 and IPv6.
j := 0
for i := 0; i < len(ips) && j < 2; i++ {
ip := net.ParseIP(ips[i])
switch {
case len(ip) == net.IPv4len && (j == 0 || len(ips[j-1]) == net.IPv6len):
fallthrough
case len(ip) == net.IPv6len && (j == 0 || len(ips[j-1]) == net.IPv4len):
ips[j] = ips[i]
j++
}
}

ips = ips[:j]
ips = firstOfEachIPFamily(ips)

type result struct {
conn net.Conn
Expand Down

0 comments on commit ce93cd8

Please sign in to comment.