libmnl  1.0.4
x.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <arpa/inet.h>
5 #include <time.h>
6 #include <sys/select.h>
7 #include <string.h>
8 #include <libmnl/libmnl.h>
9 
10 int main(void)
11 {
12  struct mnl_socket *nl;
13  char snd_buf[4] = {};
14  struct nlmsghdr *nlh = snd_buf;
15  unsigned int seq, portid;
16  char buf[128];
17  int ret;
18 
19  nlh->nlmsg_len = 80;
20 
21  nl = mnl_socket_open(NETLINK_NETFILTER);
22  if (nl == NULL) {
23  perror("mnl_socket_open");
24  exit(EXIT_FAILURE);
25  }
26  if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
27  perror("mnl_socket_bind");
28  exit(EXIT_FAILURE);
29  }
30  portid = mnl_socket_get_portid(nl);
31 
32  ret = mnl_socket_sendto(nl, snd_buf, sizeof(snd_buf));
33  if (ret == -1) {
34  perror("mnl_socket_recvfrom");
35  exit(EXIT_FAILURE);
36  }
37  printf("sent %d\n", ret);
38 
39  ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
40 
41  printf("ret %d\n", ret);
42 
43  mnl_socket_close(nl);
44 
45  return 0;
46 }