]>
git.proxmox.com Git - mirror_iproute2.git/blob - genl/genl.c
747074b029a7b98626ba32b70e15dc2e3b7aded9
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(const 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
= calloc(1, sizeof(*f
));
91 strncpy(f
->name
, str
, 15);
92 f
->parse_genlopt
= parse_nofopt
;
93 f
->print_genlopt
= print_nofopt
;
99 static void usage(void) __attribute__((noreturn
));
101 static void usage(void)
103 fprintf(stderr
, "Usage: genl [ OPTIONS ] OBJECT | help }\n"
104 "where OBJECT := { ctrl etc }\n"
105 " OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] }\n");
109 int main(int argc
, char **argv
)
112 if (argv
[1][0] != '-')
114 if (matches(argv
[1], "-stats") == 0 ||
115 matches(argv
[1], "-statistics") == 0) {
117 } else if (matches(argv
[1], "-details") == 0) {
119 } else if (matches(argv
[1], "-raw") == 0) {
121 } else if (matches(argv
[1], "-Version") == 0) {
122 printf("genl utility, iproute2-ss%s\n", SNAPSHOT
);
124 } else if (matches(argv
[1], "-help") == 0) {
127 fprintf(stderr
, "Option \"%s\" is unknown, try "
128 "\"genl -help\".\n", argv
[1]);
136 struct genl_util
*a
= NULL
;
137 a
= get_genl_kind(argv
[1]);
139 fprintf(stderr
,"bad genl %s\n", argv
[1]);
143 ret
= a
->parse_genlopt(a
, argc
-1, argv
+1);