#include <linux/genetlink.h>
#include <linux/if.h>
-#include <libmnl/libmnl.h>
-#include <sys/socket.h>
-
#include "utils.h"
#include "cmdl.h"
#include "msg.h"
static int generate_multicast(short af, char *buf, int bufsize)
{
- int netid;
- char mnl_msg[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
+ int netid;
- if (!(nlh = msg_init(mnl_msg, TIPC_NL_NET_GET))) {
+ nlh = msg_init(TIPC_NL_NET_GET);
+ if (!nlh) {
fprintf(stderr, "error, message initialization failed\n");
return -1;
}
{
int err;
char *media;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct opt *opt;
struct nlattr *attrs;
struct opt opts[] = {
return -EINVAL;
}
- if (!(nlh = msg_init(buf, TIPC_NL_BEARER_ADD))) {
+ nlh = msg_init(TIPC_NL_BEARER_ADD);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
int err;
struct opt *opt;
struct nlattr *nest;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct opt opts[] = {
{ "device", OPT_KEYVAL, NULL },
{ "domain", OPT_KEYVAL, NULL },
return -EINVAL;
}
- if (!(nlh = msg_init(buf, TIPC_NL_BEARER_ENABLE))) {
+ nlh = msg_init(TIPC_NL_BEARER_ENABLE);
+ if (!nlh) {
fprintf(stderr, "error: message initialisation failed\n");
return -1;
}
struct cmdl *cmdl, void *data)
{
int err;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlattr *nest;
struct opt opts[] = {
{ "device", OPT_KEYVAL, NULL },
return -EINVAL;
}
- if (!(nlh = msg_init(buf, TIPC_NL_BEARER_DISABLE))) {
+ nlh = msg_init(TIPC_NL_BEARER_DISABLE);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
int err;
int val;
int prop;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlattr *props;
struct nlattr *attrs;
struct opt opts[] = {
}
}
- if (!(nlh = msg_init(buf, TIPC_NL_BEARER_SET))) {
+ nlh = msg_init(TIPC_NL_BEARER_SET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
{
int err;
char *media;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct opt *opt;
struct cb_data cb_data = {0};
struct nlattr *attrs;
return -EINVAL;
}
- if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) {
+ nlh = msg_init(TIPC_NL_BEARER_GET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
{
int err;
int prop;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlattr *attrs;
struct opt opts[] = {
{ "device", OPT_KEYVAL, NULL },
}
}
- if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) {
+ nlh = msg_init(TIPC_NL_BEARER_GET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
static int cmd_bearer_list(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
-
if (help_flag) {
fprintf(stderr, "Usage: %s bearer list\n", cmdl->argv[0]);
return -EINVAL;
}
- if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) {
+ nlh = msg_init(TIPC_NL_BEARER_GET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
#include <string.h>
#include <errno.h>
-#include <libmnl/libmnl.h>
-
#include "cmdl.h"
static const struct cmd *find_cmd(const struct cmd *cmds, char *str)
#include <linux/tipc_netlink.h>
#include <linux/tipc.h>
#include <linux/genetlink.h>
-#include <libmnl/libmnl.h>
#include "cmdl.h"
#include "msg.h"
static int cmd_link_list(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
int err = 0;
if (help_flag) {
return -EINVAL;
}
- nlh = msg_init(buf, TIPC_NL_LINK_GET);
+ nlh = msg_init(TIPC_NL_LINK_GET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
struct cmdl *cmdl, void *data)
{
int prop;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlattr *attrs;
struct opt *opt;
struct opt opts[] = {
if (parse_opts(opts, cmdl) < 0)
return -EINVAL;
- nlh = msg_init(buf, TIPC_NL_LINK_GET);
+ nlh = msg_init(TIPC_NL_LINK_GET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
struct cmdl *cmdl, void *data)
{
int prop = TIPC_NLA_PROP_BROADCAST;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlattr *attrs;
if (help_flag) {
return -EINVAL;
}
- nlh = msg_init(buf, TIPC_NL_LINK_GET);
+ nlh = msg_init(TIPC_NL_LINK_GET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
struct cmdl *cmdl, void *data)
{
char *link;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct opt *opt;
struct nlattr *nest;
struct opt opts[] = {
return -EINVAL;
}
- nlh = msg_init(buf, TIPC_NL_LINK_RESET_STATS);
+ nlh = msg_init(TIPC_NL_LINK_RESET_STATS);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
struct cmdl *cmdl, void *data)
{
char *link = NULL;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct opt *opt;
struct opt opts[] = {
{ "link", OPT_KEYVAL, NULL },
return -EINVAL;
}
- nlh = msg_init(buf, TIPC_NL_LINK_GET);
+ nlh = msg_init(TIPC_NL_LINK_GET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
{
int val;
int prop;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlattr *props;
struct nlattr *attrs;
struct opt *opt;
if (parse_opts(opts, cmdl) < 0)
return -EINVAL;
- nlh = msg_init(buf, TIPC_NL_LINK_SET);
+ nlh = msg_init(TIPC_NL_LINK_SET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
static int cmd_link_set_bcast(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlattr *props;
struct nlattr *attrs;
struct opt *opt;
return -EINVAL;
}
- nlh = msg_init(buf, TIPC_NL_LINK_SET);
+ nlh = msg_init(TIPC_NL_LINK_SET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
struct cmdl *cmdl, void *data)
{
int size;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlattr *attrs;
if (cmdl->argc != cmdl->optind + 1) {
}
size = atoi(shift_cmdl(cmdl));
- nlh = msg_init(buf, TIPC_NL_MON_SET);
+ nlh = msg_init(TIPC_NL_MON_SET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
static int cmd_link_mon_summary(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
int err = 0;
if (help_flag) {
return -EINVAL;
}
- nlh = msg_init(buf, TIPC_NL_MON_GET);
+ nlh = msg_init(TIPC_NL_MON_GET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
static int link_mon_peer_list(uint32_t mon_ref)
{
struct nlmsghdr *nlh;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlattr *nest;
int err = 0;
- nlh = msg_init(buf, TIPC_NL_MON_PEER_GET);
+ nlh = msg_init(TIPC_NL_MON_PEER_GET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
static int cmd_link_mon_list(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
char bname[TIPC_MAX_BEARER_NAME] = {0};
struct opt opts[] = {
{ "media", OPT_KEYVAL, NULL },
return -EINVAL;
}
- nlh = msg_init(buf, TIPC_NL_MON_GET);
+ nlh = msg_init(TIPC_NL_MON_GET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
static int cmd_link_mon_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
- nlh = msg_init(buf, TIPC_NL_MON_GET);
+ nlh = msg_init(TIPC_NL_MON_GET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
#include <errno.h>
#include <linux/tipc_netlink.h>
-#include <linux/tipc.h>
#include <linux/genetlink.h>
-#include <libmnl/libmnl.h>
#include "cmdl.h"
#include "msg.h"
static int cmd_media_list(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
-
if (help_flag) {
fprintf(stderr, "Usage: %s media list\n", cmdl->argv[0]);
return -EINVAL;
}
- if (!(nlh = msg_init(buf, TIPC_NL_MEDIA_GET))) {
+ nlh = msg_init(TIPC_NL_MEDIA_GET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
struct cmdl *cmdl, void *data)
{
int prop;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlattr *nest;
struct opt *opt;
struct opt opts[] = {
if (parse_opts(opts, cmdl) < 0)
return -EINVAL;
- if (!(nlh = msg_init(buf, TIPC_NL_MEDIA_GET))) {
+ nlh = msg_init(TIPC_NL_MEDIA_GET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
{
int val;
int prop;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlattr *props;
struct nlattr *attrs;
struct opt *opt;
if (parse_opts(opts, cmdl) < 0)
return -EINVAL;
- if (!(nlh = msg_init(buf, TIPC_NL_MEDIA_SET))) {
+ nlh = msg_init(TIPC_NL_MEDIA_SET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
#include <time.h>
#include <errno.h>
-#include <linux/tipc_netlink.h>
-#include <linux/tipc.h>
-#include <linux/genetlink.h>
#include <libmnl/libmnl.h>
+#include "mnl_utils.h"
#include "msg.h"
+extern struct mnlu_gen_socket tipc_nlg;
+
int parse_attrs(const struct nlattr *attr, void *data)
{
const struct nlattr **tb = data;
return MNL_CB_OK;
}
-static int family_id_cb(const struct nlmsghdr *nlh, void *data)
-{
- struct nlattr *tb[CTRL_ATTR_MAX + 1] = {};
- struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
- int *id = data;
-
- mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, tb);
- if (!tb[CTRL_ATTR_FAMILY_ID])
- return MNL_CB_ERROR;
-
- *id = mnl_attr_get_u16(tb[CTRL_ATTR_FAMILY_ID]);
-
- return MNL_CB_OK;
-}
-
-static struct mnl_socket *msg_send(struct nlmsghdr *nlh)
-{
- int ret;
- struct mnl_socket *nl;
-
- nl = mnl_socket_open(NETLINK_GENERIC);
- if (nl == NULL) {
- perror("mnl_socket_open");
- return NULL;
- }
-
- ret = mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID);
- if (ret < 0) {
- perror("mnl_socket_bind");
- return NULL;
- }
-
- ret = mnl_socket_sendto(nl, nlh, nlh->nlmsg_len);
- if (ret < 0) {
- perror("mnl_socket_send");
- return NULL;
- }
-
- return nl;
-}
-
-static int msg_recv(struct mnl_socket *nl, mnl_cb_t callback, void *data, int seq)
-{
- int ret;
- unsigned int portid;
- char buf[MNL_SOCKET_BUFFER_SIZE];
-
- portid = mnl_socket_get_portid(nl);
-
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- while (ret > 0) {
- ret = mnl_cb_run(buf, ret, seq, portid, callback, data);
- if (ret <= 0)
- break;
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- }
- if (ret == -1)
- perror("error");
-
- mnl_socket_close(nl);
-
- return ret;
-}
-
-static int msg_query(struct nlmsghdr *nlh, mnl_cb_t callback, void *data)
-{
- unsigned int seq;
- struct mnl_socket *nl;
-
- seq = time(NULL);
- nlh->nlmsg_seq = seq;
-
- nl = msg_send(nlh);
- if (!nl)
- return -ENOTSUP;
-
- return msg_recv(nl, callback, data, seq);
-}
-
-static int get_family(void)
-{
- int err;
- int nl_family;
- struct nlmsghdr *nlh;
- struct genlmsghdr *genl;
- char buf[MNL_SOCKET_BUFFER_SIZE];
-
- nlh = mnl_nlmsg_put_header(buf);
- nlh->nlmsg_type = GENL_ID_CTRL;
- nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
-
- genl = mnl_nlmsg_put_extra_header(nlh, sizeof(struct genlmsghdr));
- genl->cmd = CTRL_CMD_GETFAMILY;
- genl->version = 1;
-
- mnl_attr_put_u16(nlh, CTRL_ATTR_FAMILY_ID, GENL_ID_CTRL);
- mnl_attr_put_strz(nlh, CTRL_ATTR_FAMILY_NAME, TIPC_GENL_V2_NAME);
-
- if ((err = msg_query(nlh, family_id_cb, &nl_family)))
- return err;
-
- return nl_family;
-}
-
int msg_doit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data)
{
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
- return msg_query(nlh, callback, data);
+ return mnlu_gen_socket_sndrcv(&tipc_nlg, nlh, callback, data);
}
int msg_dumpit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data)
{
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
- return msg_query(nlh, callback, data);
+ return mnlu_gen_socket_sndrcv(&tipc_nlg, nlh, callback, data);
}
-struct nlmsghdr *msg_init(char *buf, int cmd)
+struct nlmsghdr *msg_init(int cmd)
{
- int family;
struct nlmsghdr *nlh;
- struct genlmsghdr *genl;
-
- family = get_family();
- if (family <= 0) {
- fprintf(stderr,
- "Unable to get TIPC nl family id (module loaded?)\n");
- return NULL;
- }
-
- nlh = mnl_nlmsg_put_header(buf);
- nlh->nlmsg_type = family;
- genl = mnl_nlmsg_put_extra_header(nlh, sizeof(struct genlmsghdr));
- genl->cmd = cmd;
- genl->version = 1;
+ nlh = mnlu_gen_socket_cmd_prepare(&tipc_nlg, cmd, 0);
return nlh;
}
#ifndef _TIPC_MSG_H
#define _TIPC_MSG_H
-struct nlmsghdr *msg_init(char *buf, int cmd);
+struct nlmsghdr *msg_init(int cmd);
int msg_doit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data);
int msg_dumpit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data);
int parse_attrs(const struct nlattr *attr, void *data);
#include <linux/tipc_netlink.h>
#include <linux/tipc.h>
#include <linux/genetlink.h>
-#include <libmnl/libmnl.h>
#include "cmdl.h"
#include "msg.h"
struct cmdl *cmdl, void *data)
{
int iteration = 0;
- char buf[MNL_SOCKET_BUFFER_SIZE];
int rc = 0;
if (help_flag) {
return -EINVAL;
}
- if (!(nlh = msg_init(buf, TIPC_NL_NAME_TABLE_GET))) {
+ nlh = msg_init(TIPC_NL_NAME_TABLE_GET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
#include <linux/tipc_netlink.h>
#include <linux/tipc.h>
#include <linux/genetlink.h>
-#include <libmnl/libmnl.h>
#include "cmdl.h"
#include "msg.h"
static int cmd_node_list(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
-
if (help_flag) {
fprintf(stderr, "Usage: %s node list\n", cmdl->argv[0]);
return -EINVAL;
}
- if (!(nlh = msg_init(buf, TIPC_NL_NODE_GET))) {
+ nlh = msg_init(TIPC_NL_NODE_GET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
char *str;
uint32_t addr;
struct nlattr *nest;
- char buf[MNL_SOCKET_BUFFER_SIZE];
if (cmdl->argc != cmdl->optind + 1) {
fprintf(stderr, "Usage: %s node set address ADDRESS\n",
if (!addr)
return -1;
- if (!(nlh = msg_init(buf, TIPC_NL_NET_SET))) {
+ nlh = msg_init(TIPC_NL_NET_SET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
static int cmd_node_set_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
uint8_t id[16] = {0,};
uint64_t *w0 = (uint64_t *) &id[0];
uint64_t *w1 = (uint64_t *) &id[8];
return -EINVAL;
}
- nlh = msg_init(buf, TIPC_NL_NET_SET);
+ nlh = msg_init(TIPC_NL_NET_SET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
};
struct nlattr *nest;
struct opt *opt_algname, *opt_nodeid, *opt_master, *opt_rekeying;
- char buf[MNL_SOCKET_BUFFER_SIZE];
uint8_t id[TIPC_NODEID_LEN] = {0,};
uint32_t rekeying = 0;
bool has_key = false;
}
/* Init & do the command */
- nlh = msg_init(buf, TIPC_NL_KEY_SET);
+ nlh = msg_init(TIPC_NL_KEY_SET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
static int cmd_node_flush_key(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
-
if (help_flag) {
(cmd->help)(cmdl);
return -EINVAL;
}
/* Init & do the command */
- nlh = msg_init(buf, TIPC_NL_KEY_FLUSH);
+ nlh = msg_init(TIPC_NL_KEY_FLUSH);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
static int cmd_node_get_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
-
if (help_flag) {
(cmd->help)(cmdl);
return -EINVAL;
}
- nlh = msg_init(buf, TIPC_NL_NET_GET);
+ nlh = msg_init(TIPC_NL_NET_GET);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
static int cmd_node_get_netid(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
-
if (help_flag) {
(cmd->help)(cmdl);
return -EINVAL;
}
- if (!(nlh = msg_init(buf, TIPC_NL_NET_GET))) {
+ nlh = msg_init(TIPC_NL_NET_GET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
struct cmdl *cmdl, void *data)
{
int netid;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlattr *nest;
if (help_flag) {
return -EINVAL;
}
- if (!(nlh = msg_init(buf, TIPC_NL_NET_SET))) {
+ nlh = msg_init(TIPC_NL_NET_SET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
#include <linux/tipc_netlink.h>
#include <linux/tipc.h>
#include <linux/genetlink.h>
-#include <libmnl/libmnl.h>
#include "cmdl.h"
#include "msg.h"
char *str;
uint32_t addr;
struct nlattr *nest;
- char buf[MNL_SOCKET_BUFFER_SIZE];
if ((cmdl->argc != cmdl->optind + 1) || help_flag) {
fprintf(stderr, "Usage: %s peer remove address ADDRESS\n",
if (!addr)
return -1;
- if (!(nlh = msg_init(buf, TIPC_NL_PEER_REMOVE))) {
+ nlh = msg_init(TIPC_NL_PEER_REMOVE);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
static int cmd_peer_rm_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
__u8 id[16] = {0,};
__u64 *w0 = (__u64 *)&id[0];
__u64 *w1 = (__u64 *)&id[8];
return -EINVAL;
}
- nlh = msg_init(buf, TIPC_NL_PEER_REMOVE);
+ nlh = msg_init(TIPC_NL_PEER_REMOVE);
if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
#include <linux/tipc.h>
#include <linux/tipc_netlink.h>
#include <linux/genetlink.h>
-#include <libmnl/libmnl.h>
#include "cmdl.h"
#include "msg.h"
static int publ_list(uint32_t sock)
{
struct nlmsghdr *nlh;
- char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlattr *nest;
- if (!(nlh = msg_init(buf, TIPC_NL_PUBL_GET))) {
+ nlh = msg_init(TIPC_NL_PUBL_GET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
static int cmd_socket_list(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
{
- char buf[MNL_SOCKET_BUFFER_SIZE];
-
if (help_flag) {
fprintf(stderr, "Usage: %s socket list\n", cmdl->argv[0]);
return -EINVAL;
}
- if (!(nlh = msg_init(buf, TIPC_NL_SOCK_GET))) {
+ nlh = msg_init(TIPC_NL_SOCK_GET);
+ if (!nlh) {
fprintf(stderr, "error, message initialisation failed\n");
return -1;
}
#include <stdlib.h>
#include <getopt.h>
#include <unistd.h>
+#include <linux/tipc_netlink.h>
+#include <libmnl/libmnl.h>
+#include <errno.h>
+#include "mnl_utils.h"
#include "bearer.h"
#include "link.h"
#include "nametable.h"
int help_flag;
int json;
+struct mnlu_gen_socket tipc_nlg;
static void about(struct cmdl *cmdl)
{
cmdl.argc = argc;
cmdl.argv = argv;
- if ((res = run_cmd(NULL, &cmd, cmds, &cmdl, NULL)) != 0)
- return 1;
+ res = mnlu_gen_socket_open(&tipc_nlg, TIPC_GENL_V2_NAME,
+ TIPC_GENL_V2_VERSION);
+ if (res) {
+ fprintf(stderr,
+ "Unable to get TIPC nl family id (module loaded?)\n");
+ return -1;
+ }
+ res = run_cmd(NULL, &cmd, cmds, &cmdl, &tipc_nlg);
+ if (res != 0) {
+ mnlu_gen_socket_close(&tipc_nlg);
+ return -1;
+ }
+
+ mnlu_gen_socket_close(&tipc_nlg);
return 0;
}