1 /*
2 * Check decoding of recvfrom MSG_TRUNC.
3 *
4 * Copyright (c) 2019-2021 Dmitry V. Levin <ldv@strace.io>
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 #include "tests.h"
11 #include <stdio.h>
12 #include <sys/socket.h>
13
14 int
15 main(void)
16 {
17 static const char sbuf[2] = "AB";
18 int sv[2];
19 TAIL_ALLOC_OBJECT_CONST_PTR(char, rbuf);
20
21 if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv))
22 perror_msg_and_skip("socketpair");
23
24 if (send(sv[1], sbuf + 1, 1, 0) != 1)
25 perror_msg_and_skip("send");
26 if (recvfrom(sv[0], rbuf - 1, 2, MSG_PEEK, NULL, NULL) != 1)
27 perror_msg_and_fail("recvfrom");
28 printf("recvfrom(%d, \"B\", 2, MSG_PEEK, NULL, NULL) = 1\n", sv[0]);
29
30 if (recvfrom(sv[0], rbuf, 1, MSG_TRUNC, NULL, NULL) != 1)
31 perror_msg_and_skip("recvfrom");
32 printf("recvfrom(%d, \"B\", 1, MSG_TRUNC, NULL, NULL) = 1\n", sv[0]);
33
34 if (send(sv[1], sbuf, 2, 0) != 2)
35 perror_msg_and_skip("send");
36 if (recvfrom(sv[0], rbuf, 1, MSG_TRUNC, NULL, NULL) != 2)
37 perror_msg_and_skip("recvfrom");
38 printf("recvfrom(%d, \"A\", 1, MSG_TRUNC, NULL, NULL) = 2\n", sv[0]);
39
40 puts("+++ exited with 0 +++");
41 return 0;
42 }