tools/testing/selftests/drivers/net/napi_id_helper.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/net/napi_id_helper.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/drivers/net/napi_id_helper.c- Extension
.c- Size
- 1849 bytes
- Lines
- 101
- 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.hstdio.hstdlib.hstring.hunistd.harpa/inet.hsys/socket.hnetdb.h../../net/lib/ksft.h
Detected Declarations
function main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include "../../net/lib/ksft.h"
int main(int argc, char *argv[])
{
struct sockaddr_storage address;
struct addrinfo *result;
struct addrinfo hints;
unsigned int napi_id;
socklen_t addr_len;
socklen_t optlen;
char buf[1024];
int opt = 1;
int family;
int server;
int client;
int ret;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
ret = getaddrinfo(argv[1], argv[2], &hints, &result);
if (ret != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(ret));
return 1;
}
family = result->ai_family;
addr_len = result->ai_addrlen;
server = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (server < 0) {
perror("socket creation failed");
freeaddrinfo(result);
if (errno == EAFNOSUPPORT)
return -1;
return 1;
}
if (setsockopt(server, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
perror("setsockopt");
freeaddrinfo(result);
return 1;
}
memcpy(&address, result->ai_addr, result->ai_addrlen);
freeaddrinfo(result);
if (bind(server, (struct sockaddr *)&address, addr_len) < 0) {
perror("bind failed");
return 1;
}
if (listen(server, 1) < 0) {
perror("listen");
return 1;
}
ksft_ready();
client = accept(server, NULL, 0);
if (client < 0) {
perror("accept");
return 1;
}
optlen = sizeof(napi_id);
ret = getsockopt(client, SOL_SOCKET, SO_INCOMING_NAPI_ID, &napi_id,
&optlen);
if (ret != 0) {
perror("getsockopt");
return 1;
}
read(client, buf, 1024);
ksft_wait();
Annotation
- Immediate include surface: `errno.h`, `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`, `arpa/inet.h`, `sys/socket.h`, `netdb.h`.
- Detected declarations: `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.