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