sock_example.c (3eb66e91a25497065c5322b1268cbc3953642227) sock_example.c (5c3cf87d477a461274452cb46f7654c5b6ae6294)
1/* eBPF example program:
2 * - creates arraymap in kernel with key 4 bytes and value 8 bytes
3 *
4 * - loads eBPF program:
5 * r0 = skb->data[ETH_HLEN + offsetof(struct iphdr, protocol)];
6 * *(u32*)(fp - 4) = r0;
7 * // assuming packet is IPv4, lookup ip->proto in a map
8 * value = bpf_map_lookup_elem(map_fd, fp - 4);

--- 85 unchanged lines hidden (view full) ---

94 /* maps, programs, raw sockets will auto cleanup on process exit */
95 return 0;
96}
97
98int main(void)
99{
100 FILE *f;
101
1/* eBPF example program:
2 * - creates arraymap in kernel with key 4 bytes and value 8 bytes
3 *
4 * - loads eBPF program:
5 * r0 = skb->data[ETH_HLEN + offsetof(struct iphdr, protocol)];
6 * *(u32*)(fp - 4) = r0;
7 * // assuming packet is IPv4, lookup ip->proto in a map
8 * value = bpf_map_lookup_elem(map_fd, fp - 4);

--- 85 unchanged lines hidden (view full) ---

94 /* maps, programs, raw sockets will auto cleanup on process exit */
95 return 0;
96}
97
98int main(void)
99{
100 FILE *f;
101
102 f = popen("ping -c5 localhost", "r");
102 f = popen("ping -4 -c5 localhost", "r");
103 (void)f;
104
105 return test_sock();
106}
103 (void)f;
104
105 return test_sock();
106}