Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
fork
Configure Feed
Select the types of activity you want to include in your feed.
1// SPDX-License-Identifier: GPL-2.0
2
3#include <errno.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <unistd.h>
8#include <arpa/inet.h>
9#include <sys/socket.h>
10
11#include "../../net/lib/ksft.h"
12
13int main(int argc, char *argv[])
14{
15 struct sockaddr_in address;
16 unsigned int napi_id;
17 unsigned int port;
18 socklen_t optlen;
19 char buf[1024];
20 int opt = 1;
21 int server;
22 int client;
23 int ret;
24
25 server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
26 if (server < 0) {
27 perror("socket creation failed");
28 if (errno == EAFNOSUPPORT)
29 return -1;
30 return 1;
31 }
32
33 port = atoi(argv[2]);
34
35 if (setsockopt(server, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
36 perror("setsockopt");
37 return 1;
38 }
39
40 address.sin_family = AF_INET;
41 inet_pton(AF_INET, argv[1], &address.sin_addr);
42 address.sin_port = htons(port);
43
44 if (bind(server, (struct sockaddr *)&address, sizeof(address)) < 0) {
45 perror("bind failed");
46 return 1;
47 }
48
49 if (listen(server, 1) < 0) {
50 perror("listen");
51 return 1;
52 }
53
54 ksft_ready();
55
56 client = accept(server, NULL, 0);
57 if (client < 0) {
58 perror("accept");
59 return 1;
60 }
61
62 optlen = sizeof(napi_id);
63 ret = getsockopt(client, SOL_SOCKET, SO_INCOMING_NAPI_ID, &napi_id,
64 &optlen);
65 if (ret != 0) {
66 perror("getsockopt");
67 return 1;
68 }
69
70 read(client, buf, 1024);
71
72 ksft_wait();
73
74 if (napi_id == 0) {
75 fprintf(stderr, "napi ID is 0\n");
76 return 1;
77 }
78
79 close(client);
80 close(server);
81
82 return 0;
83}