Skip to content

net: File{Conn,PacketConn} cannot accept AF_NETLINK, AF_ROUTE or other sockets #10565

Closed
@mikioh

Description

@mikioh

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()
}
``

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions