Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Refactor addrFromAnswerHeader logic with a switch #214

Merged
merged 1 commit into from
Jan 27, 2025
Merged
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
15 changes: 9 additions & 6 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,8 @@
}

func addrFromAnswerHeader(a dnsmessage.ResourceHeader, p dnsmessage.Parser) (addr *netip.Addr, err error) {
if a.Type == dnsmessage.TypeA {
switch a.Type {
case dnsmessage.TypeA:
resource, err := p.AResource()
if err != nil {
return nil, err
Expand All @@ -1181,8 +1182,9 @@
return nil, fmt.Errorf("failed to convert A record: %w", ipToAddrError{resource.A[:]})
}
ipAddr = ipAddr.Unmap() // do not want 4-in-6
addr = &ipAddr
} else {

return &ipAddr, nil
case dnsmessage.TypeAAAA:
resource, err := p.AAAAResource()
if err != nil {
return nil, err
Expand All @@ -1191,10 +1193,11 @@
if !ok {
return nil, fmt.Errorf("failed to convert AAAA record: %w", ipToAddrError{resource.AAAA[:]})
}
addr = &ipAddr
}

return
return &ipAddr, nil
default:
return nil, fmt.Errorf("unsupported record type %d", a.Type) //nolint:err113 // Never happens

Check warning on line 1199 in conn.go

View check run for this annotation

Codecov / codecov/patch

conn.go#L1198-L1199

Added lines #L1198 - L1199 were not covered by tests
}
}

func isSupportedIPv6(addr netip.Addr, ipv6Only bool) bool {
Expand Down
Loading