The netlink package provides a simple netlink library for go. Netlink is the interface a user-space program in linux uses to communicate with the kernel.
more information here
func (c *ExecCollector) prepareSocket() (*netlink.NetlinkSocket, error) {
ns, err := netlink.NewNetlinkSocket(netlink.CONNECTOR, netlink.CN_IDX_PROC)
if err != nil {
return nil, fmt.Errorf("create netlink socket: %v", err)
}
req := netlink.NewNetlinkRequest()
{
msg := netlink.NewCnMsg()
req.AddData(msg)
op := netlink.PROC_CN_MCAST_LISTEN
req.AddData(&op)
}
err = ns.Send(req)
if err != nil {
return nil, fmt.Errorf("Exec: %v", err)
}
go func() {
<-c.shutdown
ns.Close()
}()
return ns, nil
}
WIP