1 /*
2 * Check decoding of getpeername 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 getpeername
11 #include "sockname.c"
12
13 int
14 main(void)
15 {
16 int lfd = socket(AF_UNIX, SOCK_STREAM, 0);
17 int cfd = socket(AF_UNIX, SOCK_STREAM, 0);
18 if (lfd < 0 || cfd < 0)
19 perror_msg_and_skip("socket");
20
21 (void) unlink(TEST_SOCKET);
22
23 const struct sockaddr_un un = {
24 .sun_family = AF_UNIX,
25 .sun_path = TEST_SOCKET
26 };
27
28 if (bind(lfd, (const void *) &un, sizeof(un)))
29 perror_msg_and_skip("bind");
30 if (listen(lfd, 1))
31 perror_msg_and_skip("listen");
32 if (connect(cfd, (const void *) &un, sizeof(un)))
33 perror_msg_and_skip("connect");
34 if (accept(lfd, 0, 0) < 0)
35 perror_msg_and_skip("accept");
36
37 test_sockname_syscall(cfd);
38
39 (void) unlink(TEST_SOCKET);
40
41 puts("+++ exited with 0 +++");
42 return 0;
43 }