Debian Codegraph @

src/func_tests/test_1_to_1_events.c

raw symbols SCIP
1 /* SCTP kernel Implementation
2 * Copyright (c) 2003 Hewlett-Packard Development Company, L.P
3 * (C) Copyright IBM Corp. 2004
4 *
5 * This test tests the events for 1-1 style sockets.
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 *
32 * Any bugs reported given to us we will try to fix... any fixes shared will
33 * be incorporated into the next SCTP release.
34 *
35 */
36 #include <stdio.h>
37 #include <unistd.h>
38 #include <stdlib.h>
39 #include <sys/types.h>
40 #include <sys/socket.h> /* needed by linux/sctp.h */
41 #include <sys/uio.h>
42 #include <netinet/in.h> /* for sockaddr_in */
43 #include <errno.h>
44 #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/
45 #include <sctputil.h>cxx . . $ `<file>/src/testlib/sctputil.h`/
46 #include <string.h>
47
48 char *TCIDcxx . . $ TCID. = __FILE__;
49 int TST_TOTALcxx . . $ TST_TOTAL. = 4;
50 int TST_CNTcxx . . $ TST_CNT. = 0;
51
52 int
53 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
54 {
55 int svr_sk, clt_sk,acpt_sk;
56 struct sockaddr_incxx . . $ sockaddr_in# svr_loop, clt_loop,acpt_loop;
57 struct ioveccxx . . $ iovec# iov, out_iov;
58 struct msghdrcxx . . $ msghdr# inmessage, outmessage;
59 char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(sctp_cmsg_data_t))];
60 char outcmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(struct sctp_sndrcvinfo))];
61 int error;
62 socklen_tcxx . . $ socklen_t# len;
63 char *big_buffer;
64 struct sctp_event_subscribecxx . . $ sctp_event_subscribe# event;
65 struct cmsghdrcxx . . $ cmsghdr# *cmsg;
66 struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *sinfo;
67 char *message = "hello, world!\n";
68 uint32_tcxx . . $ uint32_t# ppid;
69 uint32_tcxx . . $ uint32_t# stream;
70
71 /* Rather than fflush() throughout the code, set stdout to
72 * be unbuffered.
73 */
74 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);
75
76 /* Initialize the server and client addresses. */
77 svr_loop.sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
78 svr_loop.sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr. = SCTP_IP_LOOPBACKcxx . . $ `src/testlib/sctputil.h:76:9`!;
79 svr_loop.sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(SCTP_TESTPORT_1cxx . . $ `src/testlib/sctputil.h:71:9`!);
80
81 clt_loop.sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
82 clt_loop.sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr. = SCTP_IP_LOOPBACKcxx . . $ `src/testlib/sctputil.h:76:9`!;
83 clt_loop.sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(SCTP_TESTPORT_1cxx . . $ `src/testlib/sctputil.h:71:9`!);
84
85 /* Create and bind the server socket. */
86 svr_sk = test_socketcxx . . $ test_socket(2326284602b0bb2d).(AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
87 test_bindcxx . . $ test_bind(18e507052d945257).(svr_sk, (struct sockaddrcxx . . $ sockaddr# *) &svr_loop, sizeof(svr_loop));
88
89 /* Mark server socket as being able to accept new associations. */
90 test_listencxx . . $ test_listen(9b79fb6aee4c0440).(svr_sk, 3);
91
92 /* Create the client socket. */
93 clt_sk = test_socketcxx . . $ test_socket(2326284602b0bb2d).(AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
94
95 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&event, 0, sizeof(event));
96 event.sctp_data_io_eventcxx . . $ sctp_event_subscribe#sctp_data_io_event. = 1;
97 event.sctp_association_eventcxx . . $ sctp_event_subscribe#sctp_association_event. = 1;
98 event.sctp_shutdown_eventcxx . . $ sctp_event_subscribe#sctp_shutdown_event. = 1;
99 #ifdef HAVE_SCTP_AUTH_NO_AUTHcxx . . $ `src/include/netinet/sctp.h:70:9`!
100 event.sctp_authentication_eventcxx . . $ sctp_event_subscribe#sctp_authentication_event. = 1;
101 #endif
102 len = sizeof(struct sctp_event_subscribecxx . . $ sctp_event_subscribe#);
103 test_setsockoptcxx . . $ test_setsockopt(57908ac6eaa2fecc).(svr_sk, SCTP_EVENTScxx . . $ `<external>/17169092326581286071/sctp.h:80:9`!, &event, len);
104 test_setsockoptcxx . . $ test_setsockopt(57908ac6eaa2fecc).(clt_sk, SCTP_EVENTScxx . . $ `<external>/17169092326581286071/sctp.h:80:9`!, &event, len);
105
106 len = sizeof(struct sockaddr_incxx . . $ sockaddr_in#);
107 test_connectcxx . . $ test_connect(18e507052d945257).(clt_sk, (struct sockaddrcxx . . $ sockaddr# *) &clt_loop, len);
108
109 acpt_sk = test_acceptcxx . . $ test_accept(46fcd054f4a4d98b).(svr_sk, (struct sockaddrcxx . . $ sockaddr# *) &acpt_loop, &len);
110
111 /* Build up a msghdr structure we can use for all sending. */
112 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&outmessage, 0, sizeof(outmessage));
113 outmessage.msg_namecxx . . $ msghdr#msg_name. = &svr_loop;
114 outmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(svr_loop);
115 outmessage.msg_iovcxx . . $ msghdr#msg_iov. = &out_iov;
116 outmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
117 outmessage.msg_controlcxx . . $ msghdr#msg_control. = outcmsg;
118 outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(outcmsg);
119 outmessage.msg_flagscxx . . $ msghdr#msg_flags. = 0;
120
121 cmsg = CMSG_FIRSTHDRcxx . . $ `<external>/8962547315054503424/socket.h:304:9`!(&outmessage);
122 cmsg->cmsg_levelcxx . . $ cmsghdr#cmsg_level. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!;
123 cmsg->cmsg_typecxx . . $ cmsghdr#cmsg_type. = SCTP_SNDRCVcxx . . $ `<external>/17169092326581286071/sctp.h:333:9`!;
124 cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len. = CMSG_LENcxx . . $ `<external>/8962547315054503424/socket.h:311:9`!(sizeof(struct sctp_sndrcvinfo));
125 outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len.;
126 sinfo = (struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *)CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(cmsg);
127 memsetcxx . . $ memset(d1de1e4fb215f1c6).(sinfo, 0x00, sizeof(struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo#));
128 ppid = randcxx . . $ rand(b126dc7c1de90089).(); /* Choose an arbitrary value. */
129 stream = 1;
130
131 sinfo->sinfo_ppidcxx . . $ sctp_sndrcvinfo#sinfo_ppid. = ppid;
132 sinfo->sinfo_streamcxx . . $ sctp_sndrcvinfo#sinfo_stream. = stream;
133
134 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base. = message;
135 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_lencxx . . $ iovec#iov_len. = (strlencxx . . $ strlen(751346f8406fd082).(message) + 1);
136
137 /* Send . This will create the association*/
138 test_sendmsgcxx . . $ test_sendmsg(c45a39c477f473e).(clt_sk, &outmessage, 0, strlencxx . . $ strlen(751346f8406fd082).(message)+1);
139
140 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof(inmessage));
141 /* NOW initialize inmessage with enough space for DATA... */
142 big_buffer = test_malloccxx . . $ test_malloc(bfcfa4d6b7f7ef64).(REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!);
143
144 /* Let's do a test to do a recvmsg when we are not listening and
145 * when we have no associations.
146 */
147 iov.iov_basecxx . . $ iovec#iov_base. = big_buffer;
148 iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!;
149 inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
150 inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
151 inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg;
152 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
153
154 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(clt_sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
155 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage,
156 error,
157 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
158 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!,
159 SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
160
161 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "COMM_UP notification on client socket - SUCCESS");
162
163 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(acpt_sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
164 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage,
165 error,
166 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
167 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!,
168 SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
169
170 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "COMM_UP notification on server socket - SUCCESS");
171
172 #ifdef HAVE_SCTP_AUTH_NO_AUTHcxx . . $ `src/include/netinet/sctp.h:70:9`!
173 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(acpt_sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
174 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage,
175 error,
176 sizeof(struct sctp_authkey_eventcxx . . $ sctp_authkey_event#),
177 SCTP_AUTHENTICATION_EVENTcxx . . $ SCTP_AUTHENTICATION_EVENT.,
178 SCTP_AUTH_NO_AUTHcxx . . $ SCTP_AUTH_NO_AUTH.);
179
180 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "AUTH_NO_AUTH notification on server socket - SUCCESS");
181 #endif
182
183 inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg;
184 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
185 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(acpt_sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
186 test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, error, strlencxx . . $ strlen(751346f8406fd082).(message) + 1,
187 MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!, stream, ppid);
188
189 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "Data message on server socket - SUCCESS");
190
191 closecxx . . $ close(7864480464b09eea).(clt_sk);
192 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(acpt_sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
193 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage,
194 error,
195 sizeof(struct sctp_shutdown_eventcxx . . $ sctp_shutdown_event#),
196 SCTP_SHUTDOWN_EVENTcxx . . $ `<external>/17169092326581286071/sctp.h:674:9`!,
197 0);
198
199 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "SHUTDOWN notification on accepted socket - SUCCESS");
200 closecxx . . $ close(7864480464b09eea).(svr_sk);
201 closecxx . . $ close(7864480464b09eea).(acpt_sk);
202
203 freecxx . . $ free(5d22bdacc48458e8).(big_buffer);
204 return 0;
205 }