Debian Codegraph @

src/func_tests/test_1_to_1_sendto.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 file has test cases to test the sendto () call
6 * for 1-1 style sockets
7 *
8 * TEST1: Sending data from client socket to server socket
9 * TEST2: Sending data from accept (server) socket to client socket
10 * TEST3: Sending data from unconnected client socket to server
11 * TEST4: sending partial data from a buffer
12 *
13 * The SCTP implementation is free software;
14 * you can redistribute it and/or modify it under the terms of
15 * the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * The SCTP implementation is distributed in the hope that it
20 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
21 * ************************
22 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 * See the GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with GNU CC; see the file COPYING. If not, write to
27 * the Free Software Foundation, 59 Temple Place - Suite 330,
28 * Boston, MA 02111-1307, USA.
29 *
30 * Please send any bug reports or fixes you make to the
31 * email address(es):
32 * lksctp developers <[email protected]>
33 *
34 * Or submit a bug report through the following website:
35 * https://github.com/sctp/lksctp-tools/
36 *
37 * Any bugs reported given to us we will try to fix... any fixes shared will
38 * be incorporated into the next SCTP release
39 */
40
41 #include <stdio.h>
42 #include <unistd.h>
43 #include <fcntl.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <sys/types.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h> /* for sockaddr_in */
49 #include <arpa/inet.h>
50 #include <errno.h>
51 #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/
52 #include <sys/uio.h>
53 #include <linux/socket.h>
54 #include <sctputil.h>cxx . . $ `<file>/src/testlib/sctputil.h`/
55
56 char *TCIDcxx . . $ TCID. = __FILE__;
57 int TST_TOTALcxx . . $ TST_TOTAL. = 4;
58 int TST_CNTcxx . . $ TST_CNT. = 0;
59
60 int
61 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
62 {
63 int msg_count;
64 socklen_tcxx . . $ socklen_t# len;
65 int sk,sk1,pf_class,lstn_sk,acpt_sk,flag;
66 char *message = "hello, world!\n";
67 char *message_rcv;
68 int count;
69
70 struct sockaddr_incxx . . $ sockaddr_in# conn_addr,lstn_addr,svr_addr;
71
72 /* Rather than fflush() throughout the code, set stdout to
73 * be unbufferd
74 */
75 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);
76 setvbufcxx . . $ setvbuf(4da3ba8c983f31bc).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159: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 pf_class = PF_INETcxx . . $ `<external>/8962547315054503424/socket.h:45:9`!;
79
80 sk = test_socketcxx . . $ test_socket(2326284602b0bb2d).(pf_class, SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
81
82 lstn_sk = test_socketcxx . . $ test_socket(2326284602b0bb2d).(pf_class, SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
83
84 message_rcv = test_malloccxx . . $ test_malloc(bfcfa4d6b7f7ef64).(512);
85 conn_addr.sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
86 conn_addr.sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr. = SCTP_IP_LOOPBACKcxx . . $ `src/testlib/sctputil.h:76:9`!;
87 conn_addr.sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(SCTP_TESTPORT_1cxx . . $ `src/testlib/sctputil.h:71:9`!);
88
89 lstn_addr.sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
90 lstn_addr.sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr. = SCTP_IP_LOOPBACKcxx . . $ `src/testlib/sctputil.h:76:9`!;
91 lstn_addr.sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(SCTP_TESTPORT_1cxx . . $ `src/testlib/sctputil.h:71:9`!);
92
93 /*Binding the listen socket*/
94 test_bindcxx . . $ test_bind(18e507052d945257).(lstn_sk, (struct sockaddrcxx . . $ sockaddr# *) &lstn_addr, sizeof(lstn_addr));
95
96 /*Listening the socket*/
97 test_listencxx . . $ test_listen(9b79fb6aee4c0440).(lstn_sk, 10);
98
99 len = sizeof(struct sockaddr_incxx . . $ sockaddr_in#);
100 flag = MSG_NOSIGNALcxx . . $ `<external>/8962547315054503424/socket.h:242:9`!;
101
102 test_connectcxx . . $ test_connect(18e507052d945257).(sk, (struct sockaddrcxx . . $ sockaddr# *) &conn_addr, len);
103
104 acpt_sk = test_acceptcxx . . $ test_accept(46fcd054f4a4d98b).(lstn_sk, (struct sockaddrcxx . . $ sockaddr# *)&svr_addr, &len);
105
106 msg_count = strlencxx . . $ strlen(751346f8406fd082).(message) + 1;
107
108 /*sendto() TEST1: Sending data from client socket to server socket*/
109 count = sendtocxx . . $ sendto(5d9c589195de390a).(sk, message, msg_count, flag,
110 (const struct sockaddrcxx . . $ sockaddr# *) &conn_addr, len);
111 if (count != msg_count)
112 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "sendto from client to server "
113 "count:%d, errno:%d", count, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
114
115 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "sendto() from client to server - SUCCESS");
116
117 test_recvcxx . . $ test_recv(6076e73854a1e617).(acpt_sk, message_rcv, msg_count, flag);
118
119 strncpycxx . . $ strncpy(255158a415b673b0).(message_rcv,"\0",512);
120
121 /*sendto() TEST2: Sending data from accept socket to client socket*/
122 count = sendtocxx . . $ sendto(5d9c589195de390a).(acpt_sk, message, msg_count, flag,
123 (const struct sockaddrcxx . . $ sockaddr# *) &svr_addr, len);
124 if (count != msg_count)
125 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "sendto from accept socket to client "
126 "count:%d, errno:%d", count, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
127
128 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "sendto() from accept socket to client - SUCCESS");
129
130 test_recvcxx . . $ test_recv(6076e73854a1e617).(sk, message_rcv, msg_count, flag);
131
132 closecxx . . $ close(7864480464b09eea).(sk);
133 closecxx . . $ close(7864480464b09eea).(acpt_sk);
134
135 sk1 = test_socketcxx . . $ test_socket(2326284602b0bb2d).(pf_class, SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
136
137 /*sendto() TEST3: Sending data from unconnected client socket to
138 server socket*/
139 count = sendtocxx . . $ sendto(5d9c589195de390a).(sk1, message, msg_count, flag,
140 (const struct sockaddrcxx . . $ sockaddr# *) &conn_addr, len);
141 if (count != msg_count)
142 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "sendto from unconnected client to "
143 "server count:%d, errno:%d", count, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
144
145 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "sendto() from unconnected client to server - SUCCESS");
146
147 acpt_sk = test_acceptcxx . . $ test_accept(46fcd054f4a4d98b).(lstn_sk, (struct sockaddrcxx . . $ sockaddr# *)&svr_addr, &len);
148
149 test_recvcxx . . $ test_recv(6076e73854a1e617).(acpt_sk, message_rcv, msg_count, flag);
150
151 /*send() TEST4: Sending less number of data from the buffer*/
152 /*Sending only 5 bytes so that only hello is received*/
153 test_sendtocxx . . $ test_sendto(727eb71adbe2edd3).(sk1, message, 5, flag, (const struct sockaddrcxx . . $ sockaddr# *)&conn_addr,
154 len);
155 test_recvcxx . . $ test_recv(6076e73854a1e617).(acpt_sk, message_rcv, 5, flag);
156
157 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "sendto() partial data from a buffer - SUCCESS");
158
159 closecxx . . $ close(7864480464b09eea).(sk1);
160 closecxx . . $ close(7864480464b09eea).(lstn_sk);
161 closecxx . . $ close(7864480464b09eea).(acpt_sk);
162
163 freecxx . . $ free(5d22bdacc48458e8).(message_rcv);
164 return 0;
165 }