| 1 | package interfacesscip-go gomod github.com/insomniacslk/dhcp . `github.com/insomniacslk/dhcp/interfaces`/ |
| 2 | |
| 3 | import "netscip-go gomod github.com/golang/go/src go1.23.0 net/" |
| 4 | |
| 5 | // InterfaceMatcher is a function type used to match the interfaces we want. See |
| 6 | // GetInterfacesFunc below for usage. |
| 7 | type InterfaceMatcherscip-go gomod github.com/insomniacslk/dhcp . `github.com/insomniacslk/dhcp/interfaces`/InterfaceMatcher# func(netscip-go gomod github.com/golang/go/src go1.23.0 net/.Interfacescip-go gomod github.com/golang/go/src go1.23.0 net/Interface#) bool |
| 8 | |
| 9 | // interfaceGetter is used for testing purposes |
| 10 | var interfaceGetterscip-go gomod github.com/insomniacslk/dhcp . `github.com/insomniacslk/dhcp/interfaces`/interfaceGetter. = netscip-go gomod github.com/golang/go/src go1.23.0 net/.Interfacesscip-go gomod github.com/golang/go/src go1.23.0 net/Interfaces(). |
| 11 | |
| 12 | // GetInterfacesFunc loops through the available network interfaces, and returns |
| 13 | // a list of interfaces for which the passed InterfaceMatcher function returns |
| 14 | // true. |
| 15 | func GetInterfacesFuncscip-go gomod github.com/insomniacslk/dhcp . `github.com/insomniacslk/dhcp/interfaces`/GetInterfacesFunc().(matcher InterfaceMatcherscip-go gomod github.com/insomniacslk/dhcp . `github.com/insomniacslk/dhcp/interfaces`/InterfaceMatcher#) ([]netscip-go gomod github.com/golang/go/src go1.23.0 net/.Interfacescip-go gomod github.com/golang/go/src go1.23.0 net/Interface#, error) { |
| 16 | ifaces, err := interfaceGetterscip-go gomod github.com/insomniacslk/dhcp . `github.com/insomniacslk/dhcp/interfaces`/interfaceGetter.() |
| 17 | if err != nil { |
| 18 | return nil, err |
| 19 | } |
| 20 | ret := make([]netscip-go gomod github.com/golang/go/src go1.23.0 net/.Interfacescip-go gomod github.com/golang/go/src go1.23.0 net/Interface#, 0) |
| 21 | for _, iface := range ifaces { |
| 22 | if matcher(iface) { |
| 23 | ret = append(ret, iface) |
| 24 | } |
| 25 | } |
| 26 | return ret, nil |
| 27 | } |
| 28 | |
| 29 | // GetLoopbackInterfaces returns a list of loopback interfaces. |
| 30 | func GetLoopbackInterfacesscip-go gomod github.com/insomniacslk/dhcp . `github.com/insomniacslk/dhcp/interfaces`/GetLoopbackInterfaces().() ([]netscip-go gomod github.com/golang/go/src go1.23.0 net/.Interfacescip-go gomod github.com/golang/go/src go1.23.0 net/Interface#, error) { |
| 31 | return GetInterfacesFuncscip-go gomod github.com/insomniacslk/dhcp . `github.com/insomniacslk/dhcp/interfaces`/GetInterfacesFunc().(func(iface netscip-go gomod github.com/golang/go/src go1.23.0 net/.Interfacescip-go gomod github.com/golang/go/src go1.23.0 net/Interface#) bool { |
| 32 | return iface.Flagsscip-go gomod github.com/golang/go/src go1.23.0 net/Interface#Flags.&netscip-go gomod github.com/golang/go/src go1.23.0 net/.FlagLoopbackscip-go gomod github.com/golang/go/src go1.23.0 net/FlagLoopback. != 0 |
| 33 | }) |
| 34 | } |
| 35 | |
| 36 | // GetNonLoopbackInterfaces returns a list of non-loopback interfaces. |
| 37 | func GetNonLoopbackInterfacesscip-go gomod github.com/insomniacslk/dhcp . `github.com/insomniacslk/dhcp/interfaces`/GetNonLoopbackInterfaces().() ([]netscip-go gomod github.com/golang/go/src go1.23.0 net/.Interfacescip-go gomod github.com/golang/go/src go1.23.0 net/Interface#, error) { |
| 38 | return GetInterfacesFuncscip-go gomod github.com/insomniacslk/dhcp . `github.com/insomniacslk/dhcp/interfaces`/GetInterfacesFunc().(func(iface netscip-go gomod github.com/golang/go/src go1.23.0 net/.Interfacescip-go gomod github.com/golang/go/src go1.23.0 net/Interface#) bool { |
| 39 | return iface.Flagsscip-go gomod github.com/golang/go/src go1.23.0 net/Interface#Flags.&netscip-go gomod github.com/golang/go/src go1.23.0 net/.FlagLoopbackscip-go gomod github.com/golang/go/src go1.23.0 net/FlagLoopback. == 0 |
| 40 | }) |
| 41 | } |