Skip to content

Commit

Permalink
Check for nil interfaces on various functions
Browse files Browse the repository at this point in the history
This fixes #34 by ensuring that nil interfaces don't cause panics if supplied.
  • Loading branch information
rblenkinsopp committed May 16, 2022
1 parent 18549ed commit 0923f3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func NSEC(rr dns.RR, srv Service, iface *net.Interface) *dns.NSEC {
}

func A(srv Service, iface *net.Interface) []*dns.A {
if iface == nil {
return []*dns.A{}
}

ips := srv.IPsAtInterface(iface)

var as []*dns.A
Expand All @@ -135,6 +139,10 @@ func A(srv Service, iface *net.Interface) []*dns.A {
}

func AAAA(srv Service, iface *net.Interface) []*dns.AAAA {
if iface == nil {
return []*dns.AAAA{}
}

ips := srv.IPsAtInterface(iface)

var aaaas []*dns.AAAA
Expand Down
4 changes: 4 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func (s *Service) Interfaces() []*net.Interface {

// IPsAtInterface returns the ip address at a specific interface.
func (s *Service) IPsAtInterface(iface *net.Interface) []net.IP {
if iface == nil {
return []net.IP{}
}

if ips, ok := s.ifaceIPs[iface.Name]; ok {
return ips
}
Expand Down

0 comments on commit 0923f3c

Please sign in to comment.