1 /*
2 * Check decoding of sockaddr related arguments of recvfrom syscall.
3 *
4 * Copyright (c) 2016-2021 Dmitry V. Levin <ldv@strace.io>
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 #define TEST_SYSCALL_NAME recvfrom
11 #define TEST_SYSCALL_PREPARE send_un()
12 #define PREFIX_S_ARGS , recv_buf, 1, 0
13 #define PREFIX_S_STR ", \"A\", 1, 0"
14 #define PREFIX_F_ARGS , 0, 1, 0
15 #define PREFIX_F_STR ", NULL, 1, 0"
16 static void send_un(void);
17 static char recv_buf[1];
18 #include "sockname.c"
19
20 static int cfd;
21
22 static void
23 send_un(void)
24 {
25 if (send(cfd, "A", 1, 0) != 1)
26 perror_msg_and_skip("send");
27 }
28
29 int
30 main(void)
31 {
32 cfd = socket(AF_UNIX, SOCK_STREAM, 0);
33 int lfd = socket(AF_UNIX, SOCK_STREAM, 0);
34 if (cfd < 0 || lfd < 0)
35 perror_msg_and_skip("socket");
36
37 struct sockaddr_un un = {
38 .sun_family = AF_UNIX,
39 .sun_path = TEST_SOCKET ".send"
40 };
41
42 (void) unlink(un.sun_path);
43 if (bind(cfd, (const void *) &un, sizeof(un)))
44 perror_msg_and_skip("bind");
45 (void) unlink(un.sun_path);
46
47 un.sun_path[sizeof(TEST_SOCKET) - 1] = '\0';
48 (void) unlink(un.sun_path);
49
50 if (bind(lfd, (const void *) &un, sizeof(un)))
51 perror_msg_and_skip("bind");
52
53 if (listen(lfd, 1))
54 perror_msg_and_skip("listen");
55
56 if (connect(cfd, (const void *) &un, sizeof(un)))
57 perror_msg_and_skip("connect");
58
59 int afd = accept(lfd, 0, 0);
60 if (afd < 0)
61 perror_msg_and_skip("accept");
62
63 (void) unlink(un.sun_path);
64
65 test_sockname_syscall(afd);
66
67 puts("+++ exited with 0 +++");
68 return 0;
69 }