Documentation
¶
Overview ¶
Package netconfig implements a network configuration watcher, or more accurately an interface to a network configuration watcher. The OS specific implementation implements the Notifier interface below and must be set via the SetNotifier method. No auto-registration mechanism is provided since the OS specific code may use CGO and some applications may prefer to avoid the use of cgo in order to allow for simple cross compilation.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetIPRoutes ¶
GetIPRoutes returns all kernel known routes. If defaultOnly is set, only default routes are returned. If SetOSNotifier has not been called then then an empty set of routes will be returned.
func NotifyChange ¶
func NotifyChange() (<-chan struct{}, error)
NotifyChange returns a channel that will be closed when the network configuration changes from the time this function was invoked. If SetOSNotifier has not been called then the channel returned will never be closed since no network changes will ever be detected.
Example ¶
package main import ( "fmt" "log" "v.io/x/lib/netconfig" "v.io/x/lib/netconfig/osnetconfig" ) func main() { netconfig.SetOSNotifier(osnetconfig.NewNotifier(0)) for { ch, err := netconfig.NotifyChange() if err != nil { log.Fatalf("oops: %s", err) } fmt.Println("Do something to your network.") <-ch fmt.Println("Network configuration changed.") } }
Output:
func SetOSNotifier ¶
func SetOSNotifier(n Notifier)
SetOSNotifier sets a the internal notifier to the one supplied. An existing Notifier will be shutdown.
Types ¶
type Notifier ¶
type Notifier interface { // NotifyChange returns a channel that will be closed when the network // configuration changes from the time this function was invoked. // // This may provide false positivies, i.e., a network change // will cause the channel to be closed but a channel closure // may not imply a network change. NotifyChange() (<-chan struct{}, error) // GetIPRoutes returns all kernel known routes. If defaultOnly is set, // only default routes are returned. GetIPRoutes(defaultOnly bool) []route.IPRoute // Shutdown will shutdown the notifier and close the channel returned // by NotifyChange. Shutdown() }
Notifier represents a notifier of network configuration changes and for obtaining current network state.
type NullNotifier ¶
type NullNotifier struct {
// contains filtered or unexported fields
}
NullNotifier represents a null implementation of Notifier that will never return any notifications or routes. It is provided as a default.
func (*NullNotifier) GetIPRoutes ¶
func (n *NullNotifier) GetIPRoutes(defaultOnly bool) []route.IPRoute
GetIPRoutes implements Notifier.
func (*NullNotifier) NotifyChange ¶
func (n *NullNotifier) NotifyChange() (<-chan struct{}, error)
NotifyChange implements Notifier.
Directories
¶
Path | Synopsis |
---|---|
Package osnetconfig provides OS specific routines for detecting network changes and reading the route table; it uses cgo to to do so on some systems.
|
Package osnetconfig provides OS specific routines for detecting network changes and reading the route table; it uses cgo to to do so on some systems. |
Package route defines the types of the values returned by netconfig.GetIPRoutes.
|
Package route defines the types of the values returned by netconfig.GetIPRoutes. |