Follow these steps get the user space application running:
- The first thing we must do is get ourselves a socket. Traditionally, a socket is defined as an endpoint of communication; thus, a pair of sockets forms a connection. We will use the socket(2) system call to do this. Its signature is
int socket(int domain, int type, int protocol);.
Without going into too much detail, here's what we do:
-
- We specify domain as part of the special PF_NETLINK family, thus requesting a netlink socket.
- Set type to SOCK_RAW using a raw socket (effectively skipping the transport layer).
- protocol is the protocol to use. Since we're using a raw socket, the protocol is left to be implemented either by us or by the kernel; having the kernel netlink code do this is the right approach. Here, we use an unused protocol number; that is, 31.
- The next step is to bind the socket via the usual bind(2) system call semantics. First, we must...