samples/bpf/sock_example.c
Source file repositories/reference/linux-study-clean/samples/bpf/sock_example.c
File Facts
- System
- Linux kernel
- Corpus path
samples/bpf/sock_example.c- Extension
.c- Size
- 3019 bytes
- Lines
- 112
- Domain
- Support Tooling And Documentation
- Bucket
- samples
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hunistd.hassert.hlinux/bpf.hstring.hstdlib.herrno.hsys/socket.harpa/inet.hlinux/if_ether.hlinux/ip.hstddef.hbpf/bpf.hbpf_insn.hsock_example.hbpf_util.h
Detected Declarations
function test_sockfunction main
Annotated Snippet
sizeof(prog_fd)) < 0) {
printf("setsockopt %s\n", strerror(errno));
goto cleanup;
}
for (i = 0; i < 10; i++) {
key = IPPROTO_TCP;
assert(bpf_map_lookup_elem(map_fd, &key, &tcp_cnt) == 0);
key = IPPROTO_UDP;
assert(bpf_map_lookup_elem(map_fd, &key, &udp_cnt) == 0);
key = IPPROTO_ICMP;
assert(bpf_map_lookup_elem(map_fd, &key, &icmp_cnt) == 0);
printf("TCP %lld UDP %lld ICMP %lld packets\n",
tcp_cnt, udp_cnt, icmp_cnt);
sleep(1);
}
cleanup:
/* maps, programs, raw sockets will auto cleanup on process exit */
return 0;
}
int main(void)
{
FILE *f;
f = popen("ping -4 -c5 localhost", "r");
(void)f;
return test_sock();
}
Annotation
- Immediate include surface: `stdio.h`, `unistd.h`, `assert.h`, `linux/bpf.h`, `string.h`, `stdlib.h`, `errno.h`, `sys/socket.h`.
- Detected declarations: `function test_sock`, `function main`.
- Atlas domain: Support Tooling And Documentation / samples.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.