34 lines
609 B
Go
34 lines
609 B
Go
|
package multinet
|
||
|
|
||
|
import "net"
|
||
|
|
||
|
// Interface provides information about net.Interface.
|
||
|
type Interface interface {
|
||
|
Name() string
|
||
|
Addrs() ([]net.Addr, error)
|
||
|
}
|
||
|
|
||
|
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()
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|