github.com/AbhinandanKurakure/podman/v3@v3.4.10/libpod/network/util/interfaces.go (about) 1 package util 2 3 import "net" 4 5 // GetLiveNetworkSubnets returns a slice of subnets representing what the system 6 // has defined as network interfaces 7 func GetLiveNetworkSubnets() ([]*net.IPNet, error) { 8 addrs, err := net.InterfaceAddrs() 9 if err != nil { 10 return nil, err 11 } 12 nets := make([]*net.IPNet, 0, len(addrs)) 13 for _, address := range addrs { 14 _, n, err := net.ParseCIDR(address.String()) 15 if err != nil { 16 return nil, err 17 } 18 nets = append(nets, n) 19 } 20 return nets, nil 21 } 22 23 // GetLiveNetworkNames returns a list of network interface names on the system 24 func GetLiveNetworkNames() ([]string, error) { 25 liveInterfaces, err := net.Interfaces() 26 if err != nil { 27 return nil, err 28 } 29 interfaceNames := make([]string, 0, len(liveInterfaces)) 30 for _, i := range liveInterfaces { 31 interfaceNames = append(interfaceNames, i.Name) 32 } 33 return interfaceNames, nil 34 }