From 93b44ed48d144262a5633fe498a1b199fc6245a7 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Tue, 3 Apr 2012 10:06:00 -0400 Subject: [PATCH] Tidy up nl_getifdata() a bit. Eliminate some unnecessary local variables, and use NLMSG_LENGTH(). --- ndhc/netlink.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ndhc/netlink.c b/ndhc/netlink.c index 3d6e5fc..2e4fa1c 100644 --- a/ndhc/netlink.c +++ b/ndhc/netlink.c @@ -141,16 +141,12 @@ int nl_getifdata(const char *ifname, struct client_state_t *cs) { char buf[8192]; struct nlmsghdr *nlh = (struct nlmsghdr *)buf; - struct ifinfomsg *ifinfo; - size_t msgsize = NLMSG_HDRLEN + NLMSG_ALIGN(sizeof *ifinfo); - memset(buf, 0, msgsize); - nlh->nlmsg_len = msgsize; + memset(buf, 0, sizeof buf); + nlh->nlmsg_len = NLMSG_LENGTH(sizeof (struct ifinfomsg)); nlh->nlmsg_type = RTM_GETLINK; nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT; nlh->nlmsg_seq = time(NULL); - ifinfo = (struct ifinfomsg *)((char *)buf + NLMSG_HDRLEN); - ifinfo->ifi_family = AF_UNSPEC; struct sockaddr_nl addr = { .nl_family = AF_NETLINK,