aboutsummaryrefslogtreecommitdiffstats
path: root/tools/bpf/bpftool/main.c
diff options
context:
space:
mode:
authorQuentin Monnet <quentin.monnet@netronome.com>2017-10-23 09:24:06 -0700
committerDavid S. Miller <davem@davemloft.net>2017-10-24 01:25:08 +0100
commita2bc2e5c2c0604bf5366b5e56ef46335adaf7491 (patch)
treeedb5731ae927a422408f2f3dcad04b32218a67d0 /tools/bpf/bpftool/main.c
parenttools: bpftool: copy JSON writer from iproute2 repository (diff)
downloadlinux-dev-a2bc2e5c2c0604bf5366b5e56ef46335adaf7491.tar.xz
linux-dev-a2bc2e5c2c0604bf5366b5e56ef46335adaf7491.zip
tools: bpftool: add option parsing to bpftool, --help and --version
Add an option parsing facility to bpftool, in prevision of future options for demanding JSON output. Currently, two options are added: --help and --version, that act the same as the respective commands `help` and `version`. Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to '')
-rw-r--r--tools/bpf/bpftool/main.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 814d19e1b53f..613e3c75f78a 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -36,6 +36,7 @@
#include <bfd.h>
#include <ctype.h>
#include <errno.h>
+#include <getopt.h>
#include <linux/bpf.h>
#include <linux/version.h>
#include <stdio.h>
@@ -215,8 +216,32 @@ err_close:
int main(int argc, char **argv)
{
+ static const struct option options[] = {
+ { "help", no_argument, NULL, 'h' },
+ { "version", no_argument, NULL, 'V' },
+ { 0 }
+ };
+ int opt;
+
+ last_do_help = do_help;
bin_name = argv[0];
- NEXT_ARG();
+
+ while ((opt = getopt_long(argc, argv, "Vh",
+ options, NULL)) >= 0) {
+ switch (opt) {
+ case 'V':
+ return do_version(argc, argv);
+ case 'h':
+ return do_help(argc, argv);
+ default:
+ usage();
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+ if (argc < 0)
+ usage();
bfd_init();