1 /* SCTP kernel Implementation
2 * Copyright (c) 2003 Hewlett-Packard Development Company, L.P
3 * (C) Copyright IBM Corp. 2004
5 * This file has test cases to test the send() call for 1-1 style sockets
7 * TEST1: Bad socket descriptor
8 * TEST2: Invalid socket
9 * TEST3: On a listening socket
10 * TEST4: On a closed association
11 * TEST5: Invalid message address
12 * TEST6: send from client to server
13 * TEST7: send from server to client
14 * TEST8: sending partial data from a buffer
16 * The SCTP implementation is free software;
17 * you can redistribute it and/or modify it under the terms of
18 * the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
22 * The SCTP implementation is distributed in the hope that it
23 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
24 * ************************
25 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 * See the GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with GNU CC; see the file COPYING. If not, write to
30 * the Free Software Foundation, 59 Temple Place - Suite 330,
31 * Boston, MA 02111-1307, USA.
33 * Please send any bug reports or fixes you make to the
35 * lksctp developers <lksctp-developers@lists.sourceforge.net>
37 * Or submit a bug report through the following website:
38 * http://www.sf.net/projects/lksctp
40 * Any bugs reported given to us we will try to fix... any fixes shared will
41 * be incorporated into the next SCTP release
50 #include <sys/types.h>
51 #include <sys/socket.h>
52 #include <netinet/in.h> /* for sockaddr_in */
53 #include <arpa/inet.h>
55 #include <netinet/sctp.h>
57 #include <linux/socket.h>
60 char *TCID = __FILE__;
65 main(int argc, char *argv[])
67 socklen_t len,len_snd;
69 int sk,sk1,pf_class,lstn_sk,acpt_sk,acpt1_sk, flag, count;
70 char *message = "hello, world!\n";
73 struct sockaddr_in conn_addr,lstn_addr,svr_addr;
75 /* Rather than fflush() throughout the code, set stdout to
78 setvbuf(stdout, NULL, _IONBF, 0);
79 setvbuf(stderr, NULL, _IONBF, 0);
83 sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP);
85 sk1 = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP);
87 lstn_sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP);
89 conn_addr.sin_family = AF_INET;
90 conn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK;
91 conn_addr.sin_port = htons(SCTP_TESTPORT_1);
93 lstn_addr.sin_family = AF_INET;
94 lstn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK;
95 lstn_addr.sin_port = htons(SCTP_TESTPORT_1);
97 /*Binding the listen socket*/
98 test_bind(lstn_sk, (struct sockaddr *) &lstn_addr, sizeof(lstn_addr));
100 /*Listening the socket*/
101 test_listen(lstn_sk, 10);
103 len = sizeof(struct sockaddr_in);
105 test_connect(sk, (struct sockaddr *) &conn_addr, len);
107 acpt_sk = test_accept(lstn_sk, (struct sockaddr *)&svr_addr, &len);
109 len_snd = (strlen(message) + 1);
112 /*send () TEST1: Bad socket descriptor, EBADF Expected error*/
113 count = send(-1, message, len_snd, flag);
114 if (count != -1 || errno != EBADF)
115 tst_brkm(TBROK, tst_exit, "send with a bad socket "
116 "descriptor count:%d, errno:%d", count, errno);
118 tst_resm(TPASS, "send() with a bad socket descriptor - EBADF");
120 /*send () TEST2: Invalid socket, ENOTSOCK Expected error*/
121 count = send(0, message, len_snd, flag);
122 if (count != -1 || errno != ENOTSOCK)
123 tst_brkm(TBROK, tst_exit, "send with invalid socket "
124 "count:%d, errno:%d", count, errno);
126 tst_resm(TPASS, "send() with invalid socket - ENOTSOCK");
128 /*send () TEST3: send on listening socket, EPIPE Expected error*/
129 count = send(lstn_sk, message, len_snd, flag);
130 if (count != -1 || errno != EPIPE)
131 tst_brkm(TBROK, tst_exit, "send on a listening socket "
132 "count:%d, errno:%d", count, errno);
134 tst_resm(TPASS, "send() on a listening socket - EPIPE");
136 /*send () TEST4: Invalid message address, EFAULT Expected error*/
137 /* FIXME this test should pass. Don't catch why... */
138 count = send(sk, (char *)0x1, len_snd, flag);
139 if (count != -1 || errno != EFAULT)
140 tst_brkm(TBROK, tst_exit, "send with invalid message "
141 "pointer count:%d, errno:%d", count, errno);
143 tst_resm(TPASS, "send() with invalid message ptr - EFAULT");
146 test_connect(sk1, (struct sockaddr *) &lstn_addr, len);
148 count = test_send(sk1, message, len_snd, flag);
152 acpt1_sk = test_accept(lstn_sk, (struct sockaddr *)&conn_addr, &len);
154 /*send () TEST5: send on closed association, EPIPE Expected error*/
155 count = send(acpt1_sk, message, len_snd, flag);
156 if (count != -1 || errno != EPIPE)
157 tst_brkm(TBROK, tst_exit, "send on a closed association "
158 "count:%d, errno:%d", count, errno);
160 tst_resm(TPASS, "send() on a closed association - EPIPE");
167 sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP);
169 lstn_sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP);
171 message_rcv = malloc(512);
173 /*Binding the listen socket*/
174 test_bind(lstn_sk, (struct sockaddr *) &lstn_addr, sizeof(lstn_addr));
176 /*Listening the socket*/
177 test_listen(lstn_sk, 10);
179 conn_addr.sin_family = AF_INET;
180 conn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK;
181 conn_addr.sin_port = htons(SCTP_TESTPORT_1);
183 len = sizeof(struct sockaddr_in);
185 test_connect(sk, (struct sockaddr *) &conn_addr, len);
187 acpt_sk = test_accept(lstn_sk, (struct sockaddr *)&svr_addr, &len);
189 msg_count = strlen(message) + 1;
191 /*send() TEST6: Sending data from client socket to server socket*/
192 count = send(sk, message, msg_count, flag);
193 if (count != msg_count)
194 tst_brkm(TBROK, tst_exit, "send from client to server "
195 "count:%d, errno:%d", count, errno);
197 tst_resm(TPASS, "send() from client to server - SUCCESS");
199 test_recv(acpt_sk, message_rcv, msg_count, flag);
201 strncpy(message_rcv,"\0",512);
203 /*send() TEST7: Sending data from accept socket to client socket*/
204 count = send(acpt_sk, message, msg_count, flag);
205 if (count != msg_count)
206 tst_brkm(TBROK, tst_exit, "send from accept socket to client "
207 "count:%d, errno:%d", count, errno);
209 tst_resm(TPASS, "send() from accept socket to client - SUCCESS");
211 test_recv(sk, message_rcv, msg_count, flag);
213 /*send() TEST8: Sending less number of data from the buffer*/
214 /*Sending only 5 bytes so that only hello is received*/
215 test_send(sk, message, 5 , flag);
216 test_recv(acpt_sk, message_rcv, 5, flag);
218 tst_resm(TPASS, "send() partial data from a buffer - SUCCESS");
220 /* TEST9: sctp_send with no sinfo */
221 test_sctp_send(sk, message, strlen(message) + 1 , NULL, flag);
222 test_recv(acpt_sk, message_rcv, strlen(message) + 1, flag);
223 tst_resm(TPASS, "sctp_send() with no sinfo - SUCCESS");