2 * genl.c "genl" utility frontend.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Jamal Hadi Salim
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
24 #include <linux/netlink.h>
25 #include <linux/rtnetlink.h> /* until we put our own header */
28 #include "genl_utils.h"
33 int resolve_hosts = 0;
36 static struct genl_util * genl_list;
39 static int print_nofopt(const struct sockaddr_nl *who, struct nlmsghdr *n,
42 fprintf((FILE *) arg, "unknown genl type ..\n");
46 static int parse_nofopt(struct genl_util *f, int argc, char **argv)
49 fprintf(stderr, "Unknown genl \"%s\", hence option \"%s\" "
50 "is unparsable\n", f->name, *argv);
57 static struct genl_util *get_genl_kind(char *str)
63 for (f = genl_list; f; f = f->next)
64 if (strcmp(f->name, str) == 0)
67 snprintf(buf, sizeof(buf), "%s.so", str);
68 dlh = dlopen(buf, RTLD_LAZY);
72 dlh = BODY = dlopen(NULL, RTLD_LAZY);
78 snprintf(buf, sizeof(buf), "%s_genl_util", str);
89 f = malloc(sizeof(*f));
91 memset(f, 0, sizeof(*f));
92 strncpy(f->name, str, 15);
93 f->parse_genlopt = parse_nofopt;
94 f->print_genlopt = print_nofopt;
100 static void usage(void) __attribute__((noreturn));
102 static void usage(void)
104 fprintf(stderr, "Usage: genl [ OPTIONS ] OBJECT | help }\n"
105 "where OBJECT := { ctrl etc }\n"
106 " OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] }\n");
110 int main(int argc, char **argv)
113 if (argv[1][0] != '-')
115 if (matches(argv[1], "-stats") == 0 ||
116 matches(argv[1], "-statistics") == 0) {
118 } else if (matches(argv[1], "-details") == 0) {
120 } else if (matches(argv[1], "-raw") == 0) {
122 } else if (matches(argv[1], "-Version") == 0) {
123 printf("genl utility, iproute2-ss%s\n", SNAPSHOT);
125 } else if (matches(argv[1], "-help") == 0) {
128 fprintf(stderr, "Option \"%s\" is unknown, try "
129 "\"genl -help\".\n", argv[1]);
137 struct genl_util *a = NULL;
138 a = get_genl_kind(argv[1]);
140 fprintf(stderr,"bad genl %s\n", argv[1]);
144 ret = a->parse_genlopt(a, argc-1, argv+1);