diff options
author | Joe Stringer <joe@ovn.org> | 2016-12-08 18:46:20 -0800 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-12-20 12:00:40 -0300 |
commit | 9899694a7f67714216665b87318eb367e2c5c901 (patch) | |
tree | 54f29b8abd381ca36208b9cc6fe8de308800f881 /samples/bpf/libbpf.c | |
parent | 205c8ada314f78e6637342089e5b585a051d6cf5 (diff) | |
download | linux-9899694a7f67714216665b87318eb367e2c5c901.tar.bz2 |
samples/bpf: Move open_raw_sock to separate header
This function was declared in libbpf.c and was the only remaining
function in this library, but has nothing to do with BPF. Shift it out
into a new header, sock_example.h, and include it from the relevant
samples.
Signed-off-by: Joe Stringer <joe@ovn.org>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/20161209024620.31660-8-joe@ovn.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'samples/bpf/libbpf.c')
-rw-r--r-- | samples/bpf/libbpf.c | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/samples/bpf/libbpf.c b/samples/bpf/libbpf.c deleted file mode 100644 index bee473a494f1..000000000000 --- a/samples/bpf/libbpf.c +++ /dev/null @@ -1,36 +0,0 @@ -/* eBPF mini library */ -#include <stdlib.h> -#include <stdio.h> -#include <linux/unistd.h> -#include <unistd.h> -#include <string.h> -#include <errno.h> -#include <net/ethernet.h> -#include <net/if.h> -#include <linux/if_packet.h> -#include <arpa/inet.h> -#include "libbpf.h" - -int open_raw_sock(const char *name) -{ - struct sockaddr_ll sll; - int sock; - - sock = socket(PF_PACKET, SOCK_RAW | SOCK_NONBLOCK | SOCK_CLOEXEC, htons(ETH_P_ALL)); - if (sock < 0) { - printf("cannot create raw socket\n"); - return -1; - } - - memset(&sll, 0, sizeof(sll)); - sll.sll_family = AF_PACKET; - sll.sll_ifindex = if_nametoindex(name); - sll.sll_protocol = htons(ETH_P_ALL); - if (bind(sock, (struct sockaddr *)&sll, sizeof(sll)) < 0) { - printf("bind to %s: %s\n", name, strerror(errno)); - close(sock); - return -1; - } - - return sock; -} |