24 int main(int argc
, char **argv
)
30 snprintf(filename
, sizeof(filename
), "%s_kern.o", argv
[0]);
32 if (load_bpf_file(filename
)) {
33 printf("%s", bpf_log_buf
);
37 sock
= open_raw_sock("lo");
39 assert(setsockopt(sock
, SOL_SOCKET
, SO_ATTACH_BPF
, &prog_fd
[4],
43 f
= popen("ping -c5 localhost", "r");
45 f
= popen("netperf -l 4 localhost", "r");
48 for (i
= 0; i
< 5; i
++) {
49 struct flow_keys key
= {}, next_key
;
53 printf("IP src.port -> dst.port bytes packets\n");
54 while (bpf_get_next_key(map_fd
[2], &key
, &next_key
) == 0) {
55 bpf_lookup_elem(map_fd
[2], &next_key
, &value
);
56 printf("%s.%05d -> %s.%05d %12lld %12lld\n",
57 inet_ntoa((struct in_addr
){htonl(next_key
.src
)}),
59 inet_ntoa((struct in_addr
){htonl(next_key
.dst
)}),
61 value
.bytes
, value
.packets
);