aboutsummaryrefslogtreecommitdiffstats
path: root/tools/bpf/bpftool/main.c
diff options
context:
space:
mode:
authorQuentin Monnet <quentin.monnet@netronome.com>2017-10-23 12:24:06 -0400
committerDavid S. Miller <davem@davemloft.net>2017-10-23 20:25:08 -0400
commita2bc2e5c2c0604bf5366b5e56ef46335adaf7491 (patch)
treeedb5731ae927a422408f2f3dcad04b32218a67d0 /tools/bpf/bpftool/main.c
parentb66e907cfee240a09a4b5aabf950a0d4c8da8d32 (diff)
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 'tools/bpf/bpftool/main.c')
-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 @@
36#include <bfd.h> 36#include <bfd.h>
37#include <ctype.h> 37#include <ctype.h>
38#include <errno.h> 38#include <errno.h>
39#include <getopt.h>
39#include <linux/bpf.h> 40#include <linux/bpf.h>
40#include <linux/version.h> 41#include <linux/version.h>
41#include <stdio.h> 42#include <stdio.h>
@@ -215,8 +216,32 @@ err_close:
215 216
216int main(int argc, char **argv) 217int main(int argc, char **argv)
217{ 218{
219 static const struct option options[] = {
220 { "help", no_argument, NULL, 'h' },
221 { "version", no_argument, NULL, 'V' },
222 { 0 }
223 };
224 int opt;
225
226 last_do_help = do_help;
218 bin_name = argv[0]; 227 bin_name = argv[0];
219 NEXT_ARG(); 228
229 while ((opt = getopt_long(argc, argv, "Vh",
230 options, NULL)) >= 0) {
231 switch (opt) {
232 case 'V':
233 return do_version(argc, argv);
234 case 'h':
235 return do_help(argc, argv);
236 default:
237 usage();
238 }
239 }
240
241 argc -= optind;
242 argv += optind;
243 if (argc < 0)
244 usage();
220 245
221 bfd_init(); 246 bfd_init();
222 247