diff options
author | Matteo Croce | 2018-12-01 01:23:06 +0100 |
---|---|---|
committer | Alexei Starovoitov | 2018-11-30 22:06:41 -0800 |
commit | dc378a1ab5b6009629a3f8410f8b3030ac6b14c9 (patch) | |
tree | cdd8e745aba4dd3f7eeb1c8d4c6630e2deb4f56a /samples/bpf | |
parent | d606ee5c1d9a9bc4d1bba3c36fae615447f9851c (diff) |
samples: bpf: get ifindex from ifname
Find the ifindex with if_nametoindex() instead of requiring the
numeric ifindex.
Signed-off-by: Matteo Croce <mcroce@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'samples/bpf')
-rw-r--r-- | samples/bpf/xdp1_user.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/samples/bpf/xdp1_user.c b/samples/bpf/xdp1_user.c index 4f3d824fc044..0a197f86ac43 100644 --- a/samples/bpf/xdp1_user.c +++ b/samples/bpf/xdp1_user.c @@ -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" @@ -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", @@ -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; |