(root)/
strace-6.5/
tests-m32/
recv-MSG_TRUNC.c
       1  /*
       2   * Check decoding of recv 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 <errno.h>
      12  #include <stdio.h>
      13  #include <sys/socket.h>
      14  #include "scno.h"
      15  
      16  #ifndef __NR_recv
      17  # define __NR_recv -1
      18  #endif
      19  #define SC_recv 10
      20  
      21  static int
      22  sys_recv(int sockfd, const void *buf, unsigned int len, int flags)
      23  {
      24  	int rc = socketcall(__NR_recv, SC_recv,
      25  			    sockfd, (long) buf, len, flags, 0);
      26  	if (rc < 0 && ENOSYS == errno)
      27  		perror_msg_and_skip("recv");
      28  	return rc;
      29  }
      30  
      31  int
      32  main(void)
      33  {
      34  	static const char sbuf[2] = "AB";
      35  	int sv[2];
      36  	TAIL_ALLOC_OBJECT_CONST_PTR(char, rbuf);
      37  
      38  	if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv))
      39  		perror_msg_and_skip("socketpair");
      40  
      41  	if (send(sv[1], sbuf + 1, 1, 0) != 1)
      42                  perror_msg_and_skip("send");
      43  	if (sys_recv(sv[0], rbuf - 1, 2, MSG_PEEK) != 1)
      44  		perror_msg_and_fail("recv");
      45  	printf("recv(%d, \"B\", 2, MSG_PEEK) = 1\n", sv[0]);
      46  
      47  	if (sys_recv(sv[0], rbuf, 1, MSG_TRUNC) != 1)
      48  		perror_msg_and_skip("recv");
      49  	printf("recv(%d, \"B\", 1, MSG_TRUNC) = 1\n", sv[0]);
      50  
      51  	if (send(sv[1], sbuf, 2, 0) != 2)
      52                  perror_msg_and_skip("send");
      53  	if (sys_recv(sv[0], rbuf, 1, MSG_TRUNC) != 2)
      54  		perror_msg_and_skip("recv");
      55  	printf("recv(%d, \"A\", 1, MSG_TRUNC) = 2\n", sv[0]);
      56  
      57  	puts("+++ exited with 0 +++");
      58  	return 0;
      59  }