Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix redundant WindowsDNS #1456

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion dns/system_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func dnsReadConfig() (servers []string, err error) {
if err != nil {
return
}

seenIPs := make(map[string]bool)

for _, aa := range aas {
for dns := aa.FirstDnsServerAddress; dns != nil; dns = dns.Next {
sa, err := dns.Address.Sockaddr.Sockaddr()
Expand All @@ -40,7 +43,12 @@ func dnsReadConfig() (servers []string, err error) {
// Unexpected type.
continue
}
servers = append(servers, ip.String())

ipStr := ip.String()
if !seenIPs[ipStr] {
Copy link
Collaborator

@Skyxim Skyxim Aug 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just store it in the map and get it from the map key. Map can be used as a set to store unique values, without having to judge once

seenIPs[ipStr] = true
servers = append(servers, ipStr)
}
}
}
return
Expand Down