2023-10-24 12:43:08 +00:00
|
|
|
package multinet
|
|
|
|
|
|
|
|
import "net"
|
|
|
|
|
|
|
|
// Interface provides information about net.Interface.
|
|
|
|
type Interface interface {
|
|
|
|
Name() string
|
|
|
|
Addrs() ([]net.Addr, error)
|
2024-10-08 09:40:49 +00:00
|
|
|
Down() bool
|
2023-10-24 12:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type netInterface struct {
|
|
|
|
iface net.Interface
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *netInterface) Name() string {
|
|
|
|
return i.iface.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *netInterface) Addrs() ([]net.Addr, error) {
|
|
|
|
return i.iface.Addrs()
|
|
|
|
}
|
|
|
|
|
2024-10-08 09:40:49 +00:00
|
|
|
func (i *netInterface) Down() bool {
|
|
|
|
return i.iface.Flags&net.FlagUp == 0
|
|
|
|
}
|
|
|
|
|
2023-10-24 12:43:08 +00:00
|
|
|
func systemInterfaces() ([]Interface, error) {
|
|
|
|
ifaces, err := net.Interfaces()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var result []Interface
|
|
|
|
for _, iface := range ifaces {
|
|
|
|
result = append(result, &netInterface{iface: iface})
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|