tools/testing/selftests/net/reuseaddr_conflict.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/reuseaddr_conflict.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/reuseaddr_conflict.c- Extension
.c- Size
- 2690 bytes
- Lines
- 115
- 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
errno.herror.harpa/inet.hnetinet/in.hstdbool.hstdio.hsys/socket.hsys/types.hunistd.h
Detected Declarations
function b9470c27607bfunction main
Annotated Snippet
sizeof(v6only)) < 0) {
perror("setsockopt IPV6_V6ONLY");
goto out;
}
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr,
sizeof(reuseaddr)) < 0) {
perror("setsockopt SO_REUSEADDR");
goto out;
}
if (bind(fd, addr, addrlen) < 0) {
perror("bind");
goto out;
}
if (any)
return fd;
if (listen(fd, 1) < 0) {
perror("listen");
goto out;
}
return fd;
out:
close(fd);
return ret;
}
int main(void)
{
int listenfd;
int fd1, fd2;
fprintf(stderr, "Opening 127.0.0.1:%d\n", PORT);
listenfd = open_port(0, 0);
if (listenfd < 0)
error(1, errno, "Couldn't open listen socket");
fprintf(stderr, "Opening INADDR_ANY:%d\n", PORT);
fd1 = open_port(0, 1);
if (fd1 >= 0)
error(1, 0, "Was allowed to create an ipv4 reuseport on a already bound non-reuseport socket");
fprintf(stderr, "Opening in6addr_any:%d\n", PORT);
fd1 = open_port(1, 1);
if (fd1 < 0)
error(1, errno, "Couldn't open ipv6 reuseport");
fprintf(stderr, "Opening INADDR_ANY:%d\n", PORT);
fd2 = open_port(0, 1);
if (fd2 >= 0)
error(1, 0, "Was allowed to create an ipv4 reuseport on a already bound non-reuseport socket");
close(fd1);
fprintf(stderr, "Opening INADDR_ANY:%d after closing ipv6 socket\n", PORT);
fd1 = open_port(0, 1);
if (fd1 >= 0)
error(1, 0, "Was allowed to create an ipv4 reuseport on an already bound non-reuseport socket with no ipv6");
fprintf(stderr, "Success\n");
return 0;
}
Annotation
- Immediate include surface: `errno.h`, `error.h`, `arpa/inet.h`, `netinet/in.h`, `stdbool.h`, `stdio.h`, `sys/socket.h`, `sys/types.h`.
- Detected declarations: `function b9470c27607b`, `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.