mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-07-21 14:28:54 -04:00

find -name '*.go' -exec sed -i 's/SPDX-License-Identifier: AGPL-3.0-only/SPDX-License-Identifier: BUSL-1.1/' {} +
45 lines
829 B
Go
45 lines
829 B
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
package addresses
|
|
|
|
import (
|
|
"net"
|
|
)
|
|
|
|
// GetMachineNetworkAddresses retrieves all network interface addresses.
|
|
func GetMachineNetworkAddresses(interfaces []NetInterface) ([]string, error) {
|
|
var addresses []string
|
|
|
|
for _, i := range interfaces {
|
|
addrs, err := i.Addrs()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, addr := range addrs {
|
|
var ip net.IP
|
|
switch v := addr.(type) {
|
|
case *net.IPNet:
|
|
ip = v.IP
|
|
case *net.IPAddr:
|
|
ip = v.IP
|
|
default:
|
|
continue
|
|
}
|
|
if ip.IsLoopback() {
|
|
continue
|
|
}
|
|
addresses = append(addresses, ip.String())
|
|
}
|
|
}
|
|
|
|
return addresses, nil
|
|
}
|
|
|
|
// NetInterface represents a network interface used to get network addresses.
|
|
type NetInterface interface {
|
|
Addrs() ([]net.Addr, error)
|
|
}
|