MCPcopy Create free account
hub / github.com/google/nftables / ExampleNewMonitor

Function ExampleNewMonitor

monitor_test.go:18–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16)
17
18func ExampleNewMonitor() {
19 conn, err := nftables.New()
20 if err != nil {
21 log.Fatal(err)
22 }
23
24 mon := nftables.NewMonitor()
25 defer mon.Close()
26 events, err := conn.AddGenerationalMonitor(mon)
27 if err != nil {
28 log.Fatal(err)
29 }
30 for ev := range events {
31 log.Printf("ev: %+v, data = %T", ev, ev.Changes)
32
33 for _, change := range ev.Changes {
34 switch change.Type {
35 case nftables.MonitorEventTypeNewTable:
36 log.Printf("data = %+v", change.Data.(*nftables.Table))
37 // …more cases if needed…
38 }
39 }
40 }
41}
42
43func TestMonitor(t *testing.T) {
44 // Create a new network namespace to test these operations,

Callers

nothing calls this directly

Calls 4

CloseMethod · 0.95
NewFunction · 0.92
NewMonitorFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…