Debian Codegraph @

src/func_tests/test_recvmsg.c

raw symbols SCIP
1 /* SCTP kernel Implementation
2 * (C) Copyright IBM Corp. 2002, 2003
3 * Copyright (c) 1999-2001 Motorola, Inc.
4 *
5 * This file is part of the SCTP kernel Implementation
6 *
7 * The SCTP implementation is free software;
8 * you can redistribute it and/or modify it under the terms of
9 * the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * The SCTP implementation is distributed in the hope that it
14 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
15 * ************************
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with GNU CC; see the file COPYING. If not, write to
21 * the Free Software Foundation, 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
23 *
24 * Please send any bug reports or fixes you make to the
25 * email address(es):
26 * lksctp developers <[email protected]>
27 *
28 * Or submit a bug report through the following website:
29 * https://github.com/sctp/lksctp-tools/
30 *
31 * Written or modified by:
32 * Sridhar Samudrala <[email protected]>
33 *
34 * Any bugs reported to us we will try to fix... any fixes shared will
35 * be incorporated into the next SCTP release.
36 */
37
38 /* This is a kernel test to verify
39 * 1. MSG_EOR flag is set correctly when a single message is read using multiple
40 * recvmsg() calls.
41 * 2. MSG_PEEK support.
42 */
43
44 #include <stdio.h>
45 #include <unistd.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <fcntl.h>
49 #include <sys/types.h>
50 #include <sys/socket.h>
51 #include <sys/uio.h>
52 #include <netinet/in.h>
53 #include <errno.h>
54 #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/
55 #include <sctputil.h>cxx . . $ `<file>/src/testlib/sctputil.h`/
56
57 char *TCIDcxx . . $ TCID. = __FILE__;
58 int TST_TOTALcxx . . $ TST_TOTAL. = 2;
59 int TST_CNTcxx . . $ TST_CNT. = 0;
60
61 int
62 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
63 {
64 int svr_sk, clt_sk;
65 struct sockaddr_incxx . . $ sockaddr_in# svr_loop, clt_loop;
66 struct ioveccxx . . $ iovec# iov, out_iov;
67 struct msghdrcxx . . $ msghdr# inmessage, outmessage;
68 char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(sctp_cmsg_data_t))];
69 int error, msglen, i;
70 char *big_buffer;
71 void *msg_buf;
72
73 /* Rather than fflush() throughout the code, set stdout to
74 * be unbuffered.
75 */
76 setvbufcxx . . $ setvbuf(4da3ba8c983f31bc).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, _IONBFcxx . . $ `<external>/232824719582829767/stdio.h:100:9`!, 0);
77
78 /* Initialize the server and client addresses. */
79 svr_loop.sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
80 svr_loop.sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr. = SCTP_IP_LOOPBACKcxx . . $ `src/testlib/sctputil.h:76:9`!;
81 svr_loop.sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(SCTP_TESTPORT_1cxx . . $ `src/testlib/sctputil.h:71:9`!);
82 clt_loop.sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
83 clt_loop.sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr. = SCTP_IP_LOOPBACKcxx . . $ `src/testlib/sctputil.h:76:9`!;
84 clt_loop.sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(SCTP_TESTPORT_2cxx . . $ `src/testlib/sctputil.h:73:9`!);
85
86 /* Create and bind the server socket. */
87 svr_sk = test_socketcxx . . $ test_socket(2326284602b0bb2d).(AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
88 test_bindcxx . . $ test_bind(18e507052d945257).(svr_sk, (struct sockaddrcxx . . $ sockaddr# *)&svr_loop, sizeof(svr_loop));
89
90 /* Mark server socket as being able to accept new associations. */
91 test_listencxx . . $ test_listen(9b79fb6aee4c0440).(svr_sk, 1);
92
93 /* Create and bind the client sockets. */
94 clt_sk = test_socketcxx . . $ test_socket(2326284602b0bb2d).(AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
95 test_bindcxx . . $ test_bind(18e507052d945257).(clt_sk, (struct sockaddrcxx . . $ sockaddr# *)&clt_loop, sizeof(clt_loop));
96
97 /* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */
98 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(svr_sk);
99 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(clt_sk);
100
101 /* Send a message. This will create the association. */
102 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&outmessage, 0, sizeof(outmessage));
103 outmessage.msg_namecxx . . $ msghdr#msg_name. = &svr_loop;
104 outmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(svr_loop);
105 outmessage.msg_iovcxx . . $ msghdr#msg_iov. = &out_iov;
106 outmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
107 msg_buf = test_build_msgcxx . . $ test_build_msg(d1680a912d714170).(30000);
108 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base. = msg_buf;
109 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_lencxx . . $ iovec#iov_len. = 30000;
110 test_sendmsgcxx . . $ test_sendmsg(c45a39c477f473e).(clt_sk, &outmessage, 0, 30000);
111
112 /* Initialize inmessage for all receives. */
113 big_buffer = test_malloccxx . . $ test_malloc(bfcfa4d6b7f7ef64).(REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!);
114 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof(inmessage));
115 iov.iov_basecxx . . $ iovec#iov_base. = big_buffer;
116 iov.iov_lencxx . . $ iovec#iov_len. = 2000;
117 inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
118 inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
119 inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg;
120
121 /* Receive COMM_UP on clt_sk. */
122 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
123 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(clt_sk, &inmessage, 0);
124 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
125 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
126 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
127
128 /* Receive COMM_UP on svr_sk. */
129 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
130 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(svr_sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
131 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
132 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
133 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
134
135 /* Read the 30000 byte message using multiple recvmsg() calls in a
136 * loop with 2000 bytes per read.
137 */
138 for (i = 0, msglen = 30000; i < 15; i++, msglen-=2000) {
139 iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!;
140 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
141 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(svr_sk, &inmessage, MSG_PEEKcxx . . $ `<external>/8962547315054503424/socket.h:211:9`!);
142 test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, error, msglen,
143 MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!, 0, 0);
144
145 iov.iov_lencxx . . $ iovec#iov_len. = 2000;
146 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
147 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(svr_sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
148 test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, error, 2000,
149 ((i==14)?MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!:0), 0, 0);
150 }
151
152 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "recvmsg with MSG_PEEK flag");
153 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "MSG_EOR in msg_flags set correctly");
154
155 closecxx . . $ close(7864480464b09eea).(svr_sk);
156 closecxx . . $ close(7864480464b09eea).(clt_sk);
157
158 freecxx . . $ free(5d22bdacc48458e8).(big_buffer);
159 freecxx . . $ free(5d22bdacc48458e8).(msg_buf);
160 /* Indicate successful completion. */
161 return 0;
162 }