diff options
author | David S. Miller <davem@davemloft.net> | 2017-10-22 02:11:33 +0100 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-10-22 02:11:33 +0100 |
commit | a8e8c0ecb4bbeb28cab752e1b3c2ee96a595af26 (patch) | |
tree | 3c15e3ad7cc63f5a05994983138b36e1ad4a3c1e /tools/bpf/bpftool/main.c | |
parent | f3ae608edb3be2e9a3f668d47aced3553eaf6c14 (diff) | |
parent | 821cfbb0dcfbb24506dc6958361ca2b80b928049 (diff) |
Merge branch 'bpftool-add-a-version-command-and-fix-several-items'
Jakub Kicinski says:
====================
tools: bpftool: add a "version" command, and fix several items
Quentin says:
The first seven patches of this series bring several minor fixes to
bpftool. Please see individual commit logs for details.
Last patch adds a "version" commands to bpftool, which is in fact the
version of the kernel from which it was compiled.
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools/bpf/bpftool/main.c')
-rw-r--r-- | tools/bpf/bpftool/main.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c index e02d00d6e00b..814d19e1b53f 100644 --- a/tools/bpf/bpftool/main.c +++ b/tools/bpf/bpftool/main.c @@ -37,6 +37,7 @@ #include <ctype.h> #include <errno.h> #include <linux/bpf.h> +#include <linux/version.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -62,13 +63,23 @@ static int do_help(int argc, char **argv) fprintf(stderr, "Usage: %s OBJECT { COMMAND | help }\n" " %s batch file FILE\n" + " %s version\n" "\n" " OBJECT := { prog | map }\n", - bin_name, bin_name); + bin_name, bin_name, bin_name); return 0; } +static int do_version(int argc, char **argv) +{ + printf("%s v%d.%d.%d\n", bin_name, + LINUX_VERSION_CODE >> 16, + LINUX_VERSION_CODE >> 8 & 0xf, + LINUX_VERSION_CODE & 0xf); + return 0; +} + int cmd_select(const struct cmd *cmds, int argc, char **argv, int (*help)(int argc, char **argv)) { @@ -100,7 +111,7 @@ bool is_prefix(const char *pfx, const char *str) return !memcmp(str, pfx, strlen(pfx)); } -void print_hex(void *arg, unsigned int n, const char *sep) +void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep) { unsigned char *data = arg; unsigned int i; @@ -111,13 +122,13 @@ void print_hex(void *arg, unsigned int n, const char *sep) if (!i) /* nothing */; else if (!(i % 16)) - printf("\n"); + fprintf(f, "\n"); else if (!(i % 8)) - printf(" "); + fprintf(f, " "); else pfx = sep; - printf("%s%02hhx", i ? pfx : "", data[i]); + fprintf(f, "%s%02hhx", i ? pfx : "", data[i]); } } @@ -128,6 +139,7 @@ static const struct cmd cmds[] = { { "batch", do_batch }, { "prog", do_prog }, { "map", do_map }, + { "version", do_version }, { 0 } }; |