Closed
Description
For example, attached fails with "file file+net netlink: protocol not supported." When we want to know some status of network, routing information updates like "interface is going down", talking to a kernel by using netlink/route sockets is a only way to achieve it, and for handling chatty, sometimes massive events from/to the kernel we need support of runtime-integrated network poller.
package main
import (
"log"
"net"
"os"
"syscall"
)
func main() {
s, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW, syscall.NETLINK_ROUTE)
if err != nil {
log.Fatal(err)
}
lsa := syscall.SockaddrNetlink{Family: syscall.AF_NETLINK}
if err := syscall.Bind(s, &lsa); err != nil {
syscall.Close(s)
log.Fatal(err)
}
f := os.NewFile(uintptr(s), "netlink")
c, err := net.FilePacketConn(f)
f.Close()
if err != nil {
log.Fatal(err)
}
log.Println(c.LocalAddr())
c.Close()
}
``