Previous: , Up: Common API   [Contents]


2.1.3 Netlink Connections

The (netlink connection) module defines the following procedures, used to connect and communicate with another process or the kernel using a netlink socket.

Scheme Procedure: get-addr family pid groups

Return a bytevector that represents a netlink address. family should be AF_NETLINK, pid is the PID of the process with which to communicate or 0 for the kernel. groups is an integer representing the set of broadcast groups to which the connection subscribes.

Scheme Procedure: connect proto addr

Creates a netlink socket for proto and binds it to addr.

proto is the integer representing the protocol. For instance, rtnetlink can be selected by usin NETLINK_ROUTE (defined in (netlink constant)).

addr is a bytevector, as returned by get-addr.

Scheme Procedure: connect-route [#:groups 0]

This procedure is a wrapper for connect that creates a socket for the rtnetlink protocol, binds it to the kernel and returns it. By passing the optional groups keyword, you can select broadcast groups to subscribe to.

Scheme Procedure: close-socket socket

Closes a netlink socket. The socket cannot be used afterwards.

Scheme Procedure: send-msg msg sock [#:addr]

Send msg (it must be of type message, See Netlink Headers) to addr using sock. If not passed, addr is the address of the kernel.

Scheme Procedure: receive-msg sock [#:addr]

Receives a message from sock from addr. This procedure is blocking. If not passed, addr defaults to the address of the kernel. This procedure returns the message as a bytevector, that you can deserialize with deserialize (See Data Types)

Scheme Procedure: receive-and-decode-msg sock decoder [#:addr]

Receives one or more messages from sock from addr. this procedure is blocking. If not passed, addr defaults to the address of the kernel. This procedure returns a list of messages that were decoded using decoder.

When the answer has the NLM_F_MULTI flag, this procedure decodes the next message, until it receives a NLMSG_DONE message. It returns the list of every netlink messages it received, including the NLMSG_DONE.


Previous: , Up: Common API   [Contents]