summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjorn Andersson <bjorn.andersson@linaro.org>2017-06-06 22:15:33 -0700
committerBjorn Andersson <bjorn.andersson@linaro.org>2017-06-06 22:15:33 -0700
commitb804dcae1bf74e5f8715da96c06809986eba95cd (patch)
tree80d9f481d5d28c6572582daa6a9143233cf19e7b
parent0b9959552e76e1a4c560165733d559936831f20c (diff)
cfg: Request and check return valuev0.2
Request the return value of the operation from the kernel and check if it's an error, to inform the user about e.g. not having sufficient permission. Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
-rw-r--r--src/cfg.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/cfg.c b/src/cfg.c
index 79dec37..dc6082b 100644
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -1,4 +1,5 @@
#include <err.h>
+#include <errno.h>
#include <limits.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
@@ -25,6 +26,10 @@ int main(int argc, char **argv)
struct ifaddrmsg ifa;
char attrbuf[32];
} req;
+ struct {
+ struct nlmsghdr nh;
+ struct nlmsgerr err;
+ } resp;
struct rtattr *rta;
unsigned long addrul;
uint32_t addr;
@@ -46,7 +51,7 @@ int main(int argc, char **argv)
memset(&req, 0, sizeof(req));
req.nh.nlmsg_len = NLMSG_SPACE(sizeof(struct ifaddrmsg));
- req.nh.nlmsg_flags = NLM_F_REQUEST;
+ req.nh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
req.nh.nlmsg_type = RTM_NEWADDR;
req.ifa.ifa_family = AF_QIPCRTR;
@@ -61,5 +66,14 @@ int main(int argc, char **argv)
if (ret < 0)
err(1, "failed to send netlink request");
+ ret = recv(sock, &resp, sizeof(resp), 0);
+ if (ret < 0)
+ err(1, "failed to receive netlink response");
+
+ if (resp.nh.nlmsg_type == NLMSG_ERROR && resp.err.error != 0) {
+ errno = -resp.err.error;
+ err(1, "failed to configure node id");
+ }
+
return 0;
}