blob: ec9c9354d12b2ea0e319e3b77e243aeed9ace091 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#include "netlink.h"
#include <stdio.h>
static struct mnl_socket *nl;
static uint32_t seq;
bool nl_init(void) {
nl = mnl_socket_open(NETLINK_ROUTE);
if (nl == NULL) {
perror("mnl_socket_open");
return false;
}
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
perror("mnl_socket_bind");
nl_deinit();
return false;
}
return true;
}
void nl_deinit(void) {
if (!nl)
return;
mnl_socket_close(nl);
nl = NULL;
}
struct mnl_socket * nl_socket(void) {
return nl;
}
uint32_t nl_seq(void) {
return seq++;
}
|