6 #include "sock_example.h"
9 #include <sys/resource.h>
11 struct bpf_flow_keys {
26 int main(int argc, char **argv)
28 struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
33 snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
34 setrlimit(RLIMIT_MEMLOCK, &r);
36 if (load_bpf_file(filename)) {
37 printf("%s", bpf_log_buf);
41 sock = open_raw_sock("lo");
43 assert(setsockopt(sock, SOL_SOCKET, SO_ATTACH_BPF, &prog_fd[4],
47 f = popen("ping -c5 localhost", "r");
49 f = popen("netperf -l 4 localhost", "r");
52 for (i = 0; i < 5; i++) {
53 struct bpf_flow_keys key = {}, next_key;
57 printf("IP src.port -> dst.port bytes packets\n");
58 while (bpf_map_get_next_key(map_fd[2], &key, &next_key) == 0) {
59 bpf_map_lookup_elem(map_fd[2], &next_key, &value);
60 printf("%s.%05d -> %s.%05d %12lld %12lld\n",
61 inet_ntoa((struct in_addr){htonl(next_key.src)}),
63 inet_ntoa((struct in_addr){htonl(next_key.dst)}),
65 value.bytes, value.packets);