#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <syslog.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <sys/socket.h>
#include "utils.h"
#include "genl_utils.h"
-int show_stats = 0;
-int show_details = 0;
-int show_raw = 0;
-int resolve_hosts = 0;
+int show_stats;
+int show_details;
+int show_raw;
static void *BODY;
-static struct genl_util * genl_list;
+static struct genl_util *genl_list;
-static int print_nofopt(const struct sockaddr_nl *who, struct nlmsghdr *n,
- void *arg)
+static int print_nofopt(struct nlmsghdr *n, void *arg)
{
fprintf((FILE *) arg, "unknown genl type ..\n");
return 0;
static int parse_nofopt(struct genl_util *f, int argc, char **argv)
{
if (argc) {
- fprintf(stderr, "Unknown genl \"%s\", hence option \"%s\" "
- "is unparsable\n", f->name, *argv);
+ fprintf(stderr,
+ "Unknown genl \"%s\", hence option \"%s\" is unparsable\n",
+ f->name, *argv);
return -1;
}
return 0;
}
-static struct genl_util *get_genl_kind(char *str)
+static struct genl_util *get_genl_kind(const char *str)
{
void *dlh;
char buf[256];
return f;
noexist:
- f = malloc(sizeof(*f));
+ f = calloc(1, sizeof(*f));
if (f) {
- memset(f, 0, sizeof(*f));
strncpy(f->name, str, 15);
f->parse_genlopt = parse_nofopt;
f->print_genlopt = print_nofopt;
static void usage(void)
{
- fprintf(stderr, "Usage: genl [ OPTIONS ] OBJECT | help }\n"
- "where OBJECT := { ctrl etc }\n"
- " OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] }\n");
+ fprintf(stderr,
+ "Usage: genl [ OPTIONS ] OBJECT [help] }\n"
+ "where OBJECT := { ctrl etc }\n"
+ " OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -V[ersion] | -h[elp] }\n");
exit(-1);
}
int main(int argc, char **argv)
{
- char *basename;
-
- basename = strrchr(argv[0], '/');
- if (basename == NULL)
- basename = argv[0];
- else
- basename++;
-
while (argc > 1) {
if (argv[1][0] != '-')
break;
} else if (matches(argv[1], "-help") == 0) {
usage();
} else {
- fprintf(stderr, "Option \"%s\" is unknown, try "
- "\"genl -help\".\n", argv[1]);
+ fprintf(stderr,
+ "Option \"%s\" is unknown, try \"genl -help\".\n",
+ argv[1]);
exit(-1);
}
argc--; argv++;
}
if (argc > 1) {
+ struct genl_util *a;
int ret;
- struct genl_util *a = NULL;
+
a = get_genl_kind(argv[1]);
- if (NULL == a) {
- fprintf(stderr,"bad genl %s\n",argv[1]);
+ if (!a) {
+ fprintf(stderr, "bad genl %s\n", argv[1]);
+ exit(-1);
}
ret = a->parse_genlopt(a, argc-1, argv+1);
return ret;
-
- if (matches(argv[1], "help") == 0)
- usage();
- fprintf(stderr, "Object \"%s\" is unknown, try \"genl "
- "-help\".\n", argv[1]);
- exit(-1);
}
usage();