lib/osutil: Only announce address of interfaces which are up (fixes #7458) (#8422)

This commit is contained in:
Aroun 2022-07-07 19:19:29 +02:00 committed by GitHub
parent 8facaf5a6a
commit 7cb8af9029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,10 +11,21 @@ import (
)
func GetLans() ([]*net.IPNet, error) {
addrs, err := net.InterfaceAddrs()
ifs, err := net.Interfaces()
if err != nil {
return nil, err
}
addrs := []net.Addr{}
for _, currentIf := range ifs {
if currentIf.Flags&net.FlagUp != net.FlagUp {
continue
}
currentAddrs, err := currentIf.Addrs()
if err != nil {
return nil, err
}
addrs = append(addrs, currentAddrs...)
}
nets := make([]*net.IPNet, 0, len(addrs))