tools/testing/selftests/net/sk_so_peek_off.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/sk_so_peek_off.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/sk_so_peek_off.c- Extension
.c- Size
- 4627 bytes
- Lines
- 203
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- 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.hstdlib.hstring.hunistd.herrno.hsys/types.hnetinet/in.harpa/inet.hkselftest.h
Detected Declarations
function sk_peek_offset_probefunction sk_peek_offset_setfunction sk_peek_offset_getfunction sk_peek_offset_testfunction do_testfunction main
Annotated Snippet
if (recv_sock <= 0) {
ksft_perror("Temporary socket accept() failed\n");
goto out;
}
}
/* Some basic tests of getting/setting offset */
offset = sk_peek_offset_get(recv_sock);
if (offset != -1) {
ksft_perror("Initial value of socket offset not -1\n");
goto out;
}
sk_peek_offset_set(recv_sock, 0);
offset = sk_peek_offset_get(recv_sock);
if (offset != 0) {
ksft_perror("Failed to set socket offset to 0\n");
goto out;
}
/* Transfer a message */
if (send(s[1], (char *)("ab"), 2, 0) != 2) {
ksft_perror("Temporary probe socket send() failed\n");
goto out;
}
/* Read first byte */
len = recv(recv_sock, buf, 1, MSG_PEEK);
if (len != 1 || buf[0] != 'a') {
ksft_perror("Failed to read first byte of message\n");
goto out;
}
offset = sk_peek_offset_get(recv_sock);
if (offset != 1) {
ksft_perror("Offset not forwarded correctly at first byte\n");
goto out;
}
/* Try to read beyond last byte */
len = recv(recv_sock, buf, 2, MSG_PEEK);
if (len != 1 || buf[0] != 'b') {
ksft_perror("Failed to read last byte of message\n");
goto out;
}
offset = sk_peek_offset_get(recv_sock);
if (offset != 2) {
ksft_perror("Offset not forwarded correctly at last byte\n");
goto out;
}
/* Flush message */
len = recv(recv_sock, buf, 2, MSG_TRUNC);
if (len != 2) {
ksft_perror("Failed to flush message\n");
goto out;
}
offset = sk_peek_offset_get(recv_sock);
if (offset != 0) {
ksft_perror("Offset not reverted correctly after flush\n");
goto out;
}
printf("%s with MSG_PEEK_OFF works correctly\n", afstr(af, proto));
res = 1;
out:
if (proto == IPPROTO_TCP && recv_sock >= 0)
close(recv_sock);
if (s[1] >= 0)
close(s[1]);
if (s[0] >= 0)
close(s[0]);
return res;
}
static int do_test(int proto)
{
int res4, res6;
res4 = sk_peek_offset_probe(AF_INET, proto);
res6 = sk_peek_offset_probe(AF_INET6, proto);
if (!res4 && !res6)
return KSFT_SKIP;
if (res4)
res4 = sk_peek_offset_test(AF_INET, proto);
if (res6)
res6 = sk_peek_offset_test(AF_INET6, proto);
if (!res4 || !res6)
return KSFT_FAIL;
return KSFT_PASS;
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`, `errno.h`, `sys/types.h`, `netinet/in.h`, `arpa/inet.h`.
- Detected declarations: `function sk_peek_offset_probe`, `function sk_peek_offset_set`, `function sk_peek_offset_get`, `function sk_peek_offset_test`, `function do_test`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.