summaryrefslogtreecommitdiffstats
path: root/src/netlink.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2019-01-06 07:20:08 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2019-01-06 07:20:08 +0100
commit44cb17317c40fa9d39b3402f0826006f20387be5 (patch)
tree54e9d8c49ec41b2d7fd953457ca51545182a779e /src/netlink.c
parentb4bdc797028a3789bb5e0c68bc428bfd54bd200e (diff)
downloadneco-44cb17317c40fa9d39b3402f0826006f20387be5.tar
neco-44cb17317c40fa9d39b3402f0826006f20387be5.zip
Implement simple setting of link state and IP addresses
Diffstat (limited to 'src/netlink.c')
-rw-r--r--src/netlink.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/netlink.c b/src/netlink.c
new file mode 100644
index 0000000..ec9c935
--- /dev/null
+++ b/src/netlink.c
@@ -0,0 +1,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++;
+}