Skip to content

Commit

Permalink
samples: bpf: get ifindex from ifname
Browse files Browse the repository at this point in the history
Find the ifindex with if_nametoindex() instead of requiring the
numeric ifindex.

Signed-off-by: Matteo Croce <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
  • Loading branch information
teknoraver authored and Alexei Starovoitov committed Dec 1, 2018
1 parent d606ee5 commit dc378a1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions samples/bpf/xdp1_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <unistd.h>
#include <libgen.h>
#include <sys/resource.h>
#include <net/if.h>

#include "bpf_util.h"
#include "bpf/bpf.h"
Expand Down Expand Up @@ -59,7 +60,7 @@ static void poll_stats(int map_fd, int interval)
static void usage(const char *prog)
{
fprintf(stderr,
"usage: %s [OPTS] IFINDEX\n\n"
"usage: %s [OPTS] IFACE\n\n"
"OPTS:\n"
" -S use skb-mode\n"
" -N enforce native mode\n",
Expand Down Expand Up @@ -102,7 +103,11 @@ int main(int argc, char **argv)
return 1;
}

ifindex = strtoul(argv[optind], NULL, 0);
ifindex = if_nametoindex(argv[1]);
if (!ifindex) {
perror("if_nametoindex");
return 1;
}

snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename;
Expand Down

0 comments on commit dc378a1

Please sign in to comment.