#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <syslog.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
return -1;
}
-int genl_ctrl_resolve_family(const char *family)
-{
- struct rtnl_handle rth;
- int ret = 0;
- struct {
- struct nlmsghdr n;
- struct genlmsghdr g;
- char buf[4096];
- } 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;
- struct nlmsghdr *answer = NULL;
-
- if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC) < 0) {
- fprintf(stderr, "Cannot open generic netlink socket\n");
- exit(1);
- }
-
- addattr_l(nlh, 128, CTRL_ATTR_FAMILY_NAME, family, strlen(family) + 1);
-
- if (rtnl_talk(&rth, nlh, &answer) < 0) {
- fprintf(stderr, "Error talking to the kernel\n");
- goto errout;
- }
-
- {
- struct rtattr *tb[CTRL_ATTR_MAX + 1];
- int len = answer->nlmsg_len;
- struct rtattr *attrs;
-
- if (answer->nlmsg_type != GENL_ID_CTRL) {
- fprintf(stderr, "Not a controller message, nlmsg_len=%d "
- "nlmsg_type=0x%x\n", answer->nlmsg_len, answer->nlmsg_type);
- goto errout;
- }
-
- if (ghdr->cmd != CTRL_CMD_NEWFAMILY) {
- fprintf(stderr, "Unknown controller command %d\n", ghdr->cmd);
- goto errout;
- }
-
- len -= NLMSG_LENGTH(GENL_HDRLEN);
-
- if (len < 0) {
- fprintf(stderr, "wrong controller message len %d\n", len);
- free(answer);
- return -1;
- }
-
- attrs = (struct rtattr *) ((char *) answer + NLMSG_LENGTH(GENL_HDRLEN));
- parse_rtattr(tb, CTRL_ATTR_MAX, attrs, len);
-
- if (tb[CTRL_ATTR_FAMILY_ID] == NULL) {
- fprintf(stderr, "Missing family id TLV\n");
- goto errout;
- }
-
- ret = rta_getattr_u16(tb[CTRL_ATTR_FAMILY_ID]);
- }
-
-errout:
- free(answer);
- rtnl_close(&rth);
- return ret;
-}
-
static void print_ctrl_cmd_flags(FILE *fp, __u32 fl)
{
fprintf(fp, "\n\t\tCapabilities (0x%x):\n ", fl);
/*
* The controller sends one nlmsg per family
*/
-static int print_ctrl(const struct sockaddr_nl *who,
- struct rtnl_ctrl_data *ctrl,
+static int print_ctrl(struct rtnl_ctrl_data *ctrl,
struct nlmsghdr *n, void *arg)
{
struct rtattr *tb[CTRL_ATTR_MAX + 1];
return 0;
}
-static int print_ctrl2(const struct sockaddr_nl *who,
- struct nlmsghdr *n, void *arg)
+static int print_ctrl2(struct nlmsghdr *n, void *arg)
{
- return print_ctrl(who, NULL, n, arg);
+ return print_ctrl(NULL, n, arg);
}
static int ctrl_list(int cmd, int argc, char **argv)
goto ctrl_done;
}
- if (print_ctrl2(NULL, answer, (void *) stdout) < 0) {
+ if (print_ctrl2(answer, (void *) stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
goto ctrl_done;
}