1 // SPDX-License-Identifier: GPL-2.0
7 #include "sock_example.h"
11 int main(int ac
, char **argv
)
17 snprintf(filename
, sizeof(filename
), "%s_kern.o", argv
[0]);
19 if (load_bpf_file(filename
)) {
20 printf("%s", bpf_log_buf
);
24 sock
= open_raw_sock("lo");
26 assert(setsockopt(sock
, SOL_SOCKET
, SO_ATTACH_BPF
, prog_fd
,
27 sizeof(prog_fd
[0])) == 0);
29 f
= popen("ping -c5 localhost", "r");
32 for (i
= 0; i
< 5; i
++) {
33 long long tcp_cnt
, udp_cnt
, icmp_cnt
;
37 assert(bpf_map_lookup_elem(map_fd
[0], &key
, &tcp_cnt
) == 0);
40 assert(bpf_map_lookup_elem(map_fd
[0], &key
, &udp_cnt
) == 0);
43 assert(bpf_map_lookup_elem(map_fd
[0], &key
, &icmp_cnt
) == 0);
45 printf("TCP %lld UDP %lld ICMP %lld bytes\n",
46 tcp_cnt
, udp_cnt
, icmp_cnt
);