From: Matteo Croce Subject: [PATCH bpf-next v2 2/2] samples: bpf: get ifindex from ifname Date: Sat, 1 Dec 2018 01:23:06 +0100 Message-ID: <20181201002306.25834-3-mcroce@redhat.com> References: <20181201002306.25834-1-mcroce@redhat.com> <20181201002306.25834-2-mcroce@redhat.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Y Song To: netdev@vger.kernel.org Return-path: Received: from mail-wm1-f66.google.com ([209.85.128.66]:50252 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726454AbeLALeU (ORCPT ); Sat, 1 Dec 2018 06:34:20 -0500 Received: by mail-wm1-f66.google.com with SMTP id 125so595066wmh.0 for ; Fri, 30 Nov 2018 16:23:12 -0800 (PST) In-Reply-To: <20181201002306.25834-2-mcroce@redhat.com> Sender: netdev-owner@vger.kernel.org List-ID: Find the ifindex with if_nametoindex() instead of requiring the numeric ifindex. Signed-off-by: Matteo Croce --- v2: use if_nametoindex() instead of ioctl() samples/bpf/xdp1_user.c | 9 +++++++-- 1 file 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 #include #include +#include #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; -- 2.19.1