On 01/09/2018 05:30 AM, Jesper Dangaard Brouer wrote: > On Mon, 08 Jan 2018 10:05:07 -0800 > John Fastabend <john.fastab...@gmail.com> wrote: > >> sockmap sample program takes arguments from cmd line but it reads them >> in using offsets into the array. Because we want to add more arguments >> in the future lets do proper argument handling. >> >> Also refactor code to pull apart sock init and ping/pong test. This >> allows us to add new tests in the future. >> >> Signed-off-by: John Fastabend <john.fastab...@gmail.com> >> --- >> samples/sockmap/sockmap_user.c | 142 >> +++++++++++++++++++++++++++++----------- >> 1 file changed, 103 insertions(+), 39 deletions(-) >> >> diff --git a/samples/sockmap/sockmap_user.c b/samples/sockmap/sockmap_user.c >> index 7cc9d22..5cbe7a5 100644 >> --- a/samples/sockmap/sockmap_user.c >> +++ b/samples/sockmap/sockmap_user.c >> @@ -35,6 +35,8 @@ >> #include <assert.h> >> #include <libgen.h> >> >> +#include <getopt.h> >> + >> #include "../bpf/bpf_load.h" >> #include "../bpf/bpf_util.h" >> #include "../bpf/libbpf.h" >> @@ -46,15 +48,39 @@ >> #define S1_PORT 10000 >> #define S2_PORT 10001 >> >> -static int sockmap_test_sockets(int rate, int dot) >> +/* global sockets */ >> +int s1, s2, c1, c2, p1, p2; >> + >> +static const struct option long_options[] = { >> + {"help", no_argument, NULL, 'h' }, >> + {"cgroup", required_argument, NULL, 'c' }, >> + {"rate", required_argument, NULL, 'r' }, >> + {"verbose", no_argument, NULL, 'v' }, >> + {0, 0, NULL, 0 } >> +}; >> + >> +static void usage(char *argv[]) >> +{ >> + int i; >> + >> + printf(" Usage: %s --cgroup <cgroup_path>\n", argv[0]); >> + printf(" options:\n"); >> + for (i = 0; long_options[i].name != 0; i++) { >> + printf(" --%-12s", long_options[i].name); >> + if (long_options[i].flag != NULL) >> + printf(" flag (internal value:%d)\n", >> + *long_options[i].flag); >> + else >> + printf(" -%c\n", long_options[i].val); >> + } >> + printf("\n"); >> +} >> + > > I love that you are using --long-options :-)
Yep, saw it being used in xdp_rxq_info_user.c > > Acked-by: Jesper Dangaard Brouer <bro...@redhat.com> >