libmnl  1.0.4
receiver.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <time.h>
5 #include <arpa/inet.h>
6 
7 #include <libmnl/libmnl.h>
8 
9 int main(void)
10 {
11  struct mnl_socket *nl;
12  char buf[8192];
13  struct nlmsghdr *nlh;
14  struct nfgenmsg *nfh;
15  int ret;
16 
17  nl = mnl_socket_open(NETLINK_USERSOCK);
18  if (nl == NULL) {
19  perror("mnl_socket_open");
20  exit(EXIT_FAILURE);
21  }
22 
23  if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
24  perror("mnl_socket_bind");
25  exit(EXIT_FAILURE);
26  }
27 
28  printf("receiver at netlink port ID %u\n", mnl_socket_get_portid(nl));
29 
30  pause();
31 /*
32  while (1) {
33  ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
34  if (ret == -1) {
35  perror("mnl_socket_recvfrom");
36  exit(EXIT_FAILURE);
37  }
38 
39  printf("received data\n");
40  }
41 */
42  mnl_socket_close(nl);
43 
44  return 0;
45 }