mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-11-22 03:13:33 +01:00
recommended fixes [2 of 2]
This commit is contained in:
parent
de2ca33700
commit
511d3f6aaf
1 changed files with 11 additions and 10 deletions
21
cmd/serve.go
21
cmd/serve.go
|
@ -314,18 +314,19 @@ func parseIPHostPrefix(host string) (prefixes []netip.Prefix, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// not a prefix, parse as host or IP
|
// not a prefix, parse as host or IP
|
||||||
// LookupHost forwards through if it's an IP
|
// LookupHost passes through an IP as is
|
||||||
ips, err := net.LookupHost(host)
|
ips, err := net.LookupHost(host)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
for _, i := range ips {
|
return nil, err
|
||||||
ip, err := netip.ParseAddr(i)
|
}
|
||||||
if err == nil {
|
for _, i := range ips {
|
||||||
prefix, err := ip.Prefix(ip.BitLen())
|
ip, err := netip.ParseAddr(i)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
return prefixes, errors.New(fmt.Sprint("ip", ip, " successfully parsed as IP but unable to turn into prefix. THIS SHOULD NEVER HAPPEN. err:", err.Error()))
|
prefix, err := ip.Prefix(ip.BitLen())
|
||||||
}
|
if err != nil {
|
||||||
prefixes = append(prefixes, prefix.Masked()) //also masked canonical ip
|
return nil, fmt.Errorf("%s successfully parsed but unable to make prefix: %s", ip.String(), err.Error())
|
||||||
}
|
}
|
||||||
|
prefixes = append(prefixes, prefix.Masked()) //also masked canonical ip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue