diff options
Diffstat (limited to 'genl')
-rw-r--r-- | genl/Makefile | 3 | ||||
-rw-r--r-- | genl/ctrl.c | 48 | ||||
-rw-r--r-- | genl/genl.c | 4 |
3 files changed, 22 insertions, 33 deletions
diff --git a/genl/Makefile b/genl/Makefile index 03d1f26a..de1635e4 100644 --- a/genl/Makefile +++ b/genl/Makefile @@ -1,6 +1,6 @@ GENLOBJ=genl.o -include ../Config +include ../config.mk SHARED_LIBS ?= y CFLAGS += -fno-strict-aliasing @@ -20,6 +20,7 @@ endif all: genl genl: $(GENLOBJ) $(LIBNETLINK) $(LIBUTIL) $(GENLLIB) + $(QUIET_LINK)$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@ install: all install -m 0755 genl $(DESTDIR)$(SBINDIR) diff --git a/genl/ctrl.c b/genl/ctrl.c index b7a8878c..448988eb 100644 --- a/genl/ctrl.c +++ b/genl/ctrl.c @@ -42,23 +42,19 @@ static int usage(void) int genl_ctrl_resolve_family(const char *family) { struct rtnl_handle rth; - struct nlmsghdr *nlh; - struct genlmsghdr *ghdr; int ret = 0; struct { struct nlmsghdr n; + struct genlmsghdr g; char buf[4096]; - } req; - - memset(&req, 0, sizeof(req)); - - nlh = &req.n; - nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); - nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; - nlh->nlmsg_type = GENL_ID_CTRL; - - ghdr = NLMSG_DATA(&req.n); - ghdr->cmd = CTRL_CMD_GETFAMILY; + } req = { + .n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN), + .n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK, + .n.nlmsg_type = GENL_ID_CTRL, + .g.cmd = CTRL_CMD_GETFAMILY, + }; + struct nlmsghdr *nlh = &req.n; + struct genlmsghdr *ghdr = &req.g; if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC) < 0) { fprintf(stderr, "Cannot open generic netlink socket\n"); @@ -74,7 +70,6 @@ int genl_ctrl_resolve_family(const char *family) { struct rtattr *tb[CTRL_ATTR_MAX + 1]; - struct genlmsghdr *ghdr = NLMSG_DATA(nlh); int len = nlh->nlmsg_len; struct rtattr *attrs; @@ -132,7 +127,7 @@ static void print_ctrl_cmd_flags(FILE *fp, __u32 fl) fprintf(fp, "\n"); } - + static int print_ctrl_cmds(FILE *fp, struct rtattr *arg, __u32 ctrl_ver) { struct rtattr *tb[CTRL_ATTR_OP_MAX + 1]; @@ -291,24 +286,19 @@ static int print_ctrl2(const struct sockaddr_nl *who, static int ctrl_list(int cmd, int argc, char **argv) { struct rtnl_handle rth; - struct nlmsghdr *nlh; - struct genlmsghdr *ghdr; int ret = -1; char d[GENL_NAMSIZ]; struct { struct nlmsghdr n; + struct genlmsghdr g; char buf[4096]; - } req; - - memset(&req, 0, sizeof(req)); - - nlh = &req.n; - nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); - nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; - nlh->nlmsg_type = GENL_ID_CTRL; - - ghdr = NLMSG_DATA(&req.n); - ghdr->cmd = CTRL_CMD_GETFAMILY; + } req = { + .n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN), + .n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK, + .n.nlmsg_type = GENL_ID_CTRL, + .g.cmd = CTRL_CMD_GETFAMILY, + }; + struct nlmsghdr *nlh = &req.n; if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC) < 0) { fprintf(stderr, "Cannot open generic netlink socket\n"); @@ -323,7 +313,7 @@ static int ctrl_list(int cmd, int argc, char **argv) if (matches(*argv, "name") == 0) { NEXT_ARG(); - strncpy(d, *argv, sizeof (d) - 1); + strlcpy(d, *argv, sizeof(d)); addattr_l(nlh, 128, CTRL_ATTR_FAMILY_NAME, d, strlen(d) + 1); } else if (matches(*argv, "id") == 0) { diff --git a/genl/genl.c b/genl/genl.c index e33fafdf..7e4a208d 100644 --- a/genl/genl.c +++ b/genl/genl.c @@ -30,7 +30,6 @@ int show_stats = 0; int show_details = 0; int show_raw = 0; -int resolve_hosts = 0; static void *BODY; static struct genl_util * genl_list; @@ -86,9 +85,8 @@ reg: return f; noexist: - f = malloc(sizeof(*f)); + f = calloc(1, sizeof(*f)); if (f) { - memset(f, 0, sizeof(*f)); strncpy(f->name, str, 15); f->parse_genlopt = parse_nofopt; f->print_genlopt = print_nofopt; |