]>
git.proxmox.com Git - mirror_iproute2.git/blob - genl/genl.c
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
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
23 #include <linux/netlink.h>
24 #include <linux/rtnetlink.h> /* until we put our own header */
27 #include "genl_utils.h"
34 static struct genl_util
*genl_list
;
37 static int print_nofopt(struct nlmsghdr
*n
, void *arg
)
39 fprintf((FILE *) arg
, "unknown genl type ..\n");
43 static int parse_nofopt(struct genl_util
*f
, int argc
, char **argv
)
47 "Unknown genl \"%s\", hence option \"%s\" is unparsable\n",
55 static struct genl_util
*get_genl_kind(const char *str
)
61 for (f
= genl_list
; f
; f
= f
->next
)
62 if (strcmp(f
->name
, str
) == 0)
65 snprintf(buf
, sizeof(buf
), "%s.so", str
);
66 dlh
= dlopen(buf
, RTLD_LAZY
);
70 dlh
= BODY
= dlopen(NULL
, RTLD_LAZY
);
76 snprintf(buf
, sizeof(buf
), "%s_genl_util", str
);
87 f
= calloc(1, sizeof(*f
));
89 strncpy(f
->name
, str
, 15);
90 f
->parse_genlopt
= parse_nofopt
;
91 f
->print_genlopt
= print_nofopt
;
97 static void usage(void) __attribute__((noreturn
));
99 static void usage(void)
102 "Usage: genl [ OPTIONS ] OBJECT [help] }\n"
103 "where OBJECT := { ctrl etc }\n"
104 " OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -V[ersion] | -h[elp] }\n");
108 int main(int argc
, char **argv
)
111 if (argv
[1][0] != '-')
113 if (matches(argv
[1], "-stats") == 0 ||
114 matches(argv
[1], "-statistics") == 0) {
116 } else if (matches(argv
[1], "-details") == 0) {
118 } else if (matches(argv
[1], "-raw") == 0) {
120 } else if (matches(argv
[1], "-Version") == 0) {
121 printf("genl utility, iproute2-ss%s\n", SNAPSHOT
);
123 } else if (matches(argv
[1], "-help") == 0) {
127 "Option \"%s\" is unknown, try \"genl -help\".\n",
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);