blob: 8efb4f59cd7e51d3dec061dbd75b3ba1c34c4c9e [file] [log] [blame]
Simon Xu6f224942013-12-06 11:51:16 +08001/* SCTP kernel Implementation
mridge5ba96af2004-02-23 16:17:34 +00002 * Copyright (c) 2003 Hewlett-Packard Development Company, L.P
3 * (C) Copyright IBM Corp. 2004
4 *
5 * When init timeout is set to zero, a connect () crashed the system. This case
6 * tests the fix for the same.
7 *
Simon Xu6f224942013-12-06 11:51:16 +08008 * The SCTP implementation is free software;
mridge5ba96af2004-02-23 16:17:34 +00009 * you can redistribute it and/or modify it under the terms of
10 * the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
Simon Xu6f224942013-12-06 11:51:16 +080014 * The SCTP implementation is distributed in the hope that it
mridge5ba96af2004-02-23 16:17:34 +000015 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * ************************
17 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 * See the GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with GNU CC; see the file COPYING. If not, write to
22 * the Free Software Foundation, 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
24 *
25 * Please send any bug reports or fixes you make to the
26 * email address(es):
27 * lksctp developers <lksctp-developers@lists.sourceforge.net>
28 *
29 * Or submit a bug report through the following website:
30 * http://www.sf.net/projects/lksctp
31 *
32 *
33 * Any bugs reported given to us we will try to fix... any fixes shared will
34 * be incorporated into the next SCTP release.
35 *
36 */
37#include <stdio.h>
38#include <unistd.h>
39#include <fcntl.h>
40#include <stdlib.h>
41#include <string.h>
42#include <sys/types.h>
43#include <sys/socket.h>
Simon Xu6f224942013-12-06 11:51:16 +080044#include <netinet/in.h> /* for sockaddr_in */
mridge5ba96af2004-02-23 16:17:34 +000045#include <arpa/inet.h>
46#include <errno.h>
47#include <netinet/sctp.h>
48#include <sys/uio.h>
Simon Xu6f224942013-12-06 11:51:16 +080049#include <sctputil.h>
mridge5ba96af2004-02-23 16:17:34 +000050
51char *TCID = __FILE__;
52int TST_TOTAL = 1;
53int TST_CNT = 0;
54
Simon Xu6f224942013-12-06 11:51:16 +080055int
56main (int argc, char **argv)
mridge5ba96af2004-02-23 16:17:34 +000057{
mridge64a341f2006-01-03 19:16:46 +000058 int sk1, sk2, sk3, pf_class;
59 socklen_t len;
mridge5ba96af2004-02-23 16:17:34 +000060 struct sockaddr_in lstn_addr, acpt_addr;
61 struct sockaddr_in conn_addr;
Simon Xu6f224942013-12-06 11:51:16 +080062 char * buffer_rcv;
mridge5ba96af2004-02-23 16:17:34 +000063 struct sctp_initmsg sinmsg;
64 char *message = "Hello World!\n";
65
66 /* Rather than fflush() throughout the code, set stdout to
67 * be unbuffered.
68 */
69 setvbuf(stdout, NULL, _IONBF, 0);
70 setvbuf(stderr, NULL, _IONBF, 0);
71
Simon Xu6f224942013-12-06 11:51:16 +080072 /* Opening the socket*/
73
mridge5ba96af2004-02-23 16:17:34 +000074 pf_class = PF_INET;
75
76 sk1 = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP);
77 sk3 = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP);
78
Simon Xu6f224942013-12-06 11:51:16 +080079 conn_addr.sin_family = AF_INET;
80 conn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK;
81 conn_addr.sin_port = htons(SCTP_TESTPORT_1);
mridge5ba96af2004-02-23 16:17:34 +000082
Simon Xu6f224942013-12-06 11:51:16 +080083 lstn_addr.sin_family = AF_INET;
84 lstn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK;
85 lstn_addr.sin_port = htons(SCTP_TESTPORT_1);
mridge5ba96af2004-02-23 16:17:34 +000086
Simon Xu6f224942013-12-06 11:51:16 +080087 test_bind(sk3, (struct sockaddr *) &lstn_addr, sizeof(lstn_addr));
mridge5ba96af2004-02-23 16:17:34 +000088
89 len = sizeof(struct sctp_initmsg);
90 sinmsg.sinit_num_ostreams = 65535;
91 sinmsg.sinit_max_instreams = 10;
92 sinmsg.sinit_max_attempts = 1;
93 sinmsg.sinit_max_init_timeo = 0;
94 test_setsockopt(sk1, SCTP_INITMSG, &sinmsg, len);
95 sinmsg.sinit_num_ostreams = 10;
96 sinmsg.sinit_max_instreams = 65535;
97 test_setsockopt(sk3, SCTP_INITMSG, &sinmsg, len);
98
99 test_listen(sk3, 1);
100
101 len = sizeof(struct sockaddr_in);
Simon Xu6f224942013-12-06 11:51:16 +0800102 test_connect(sk1, (struct sockaddr *) &conn_addr, len);
mridge5ba96af2004-02-23 16:17:34 +0000103
Simon Xu6f224942013-12-06 11:51:16 +0800104 sk2 = test_accept(sk3, (struct sockaddr *) &acpt_addr, &len);
mridge5ba96af2004-02-23 16:17:34 +0000105
106 test_sctp_sendmsg(sk1, message, strlen(message) + 1,
107 (struct sockaddr *)&conn_addr, len,
108 0, 0, 65534, 0, 0);
109
110 buffer_rcv = malloc(100);
111 test_recv(sk2, buffer_rcv, (strlen(message) + 1), MSG_NOSIGNAL);
112
113 tst_resm(TPASS, "connect() with init timeout set to 0 - SUCCESS");
114
Simon Xu6f224942013-12-06 11:51:16 +0800115 close (sk1);
116 close (sk2);
117 close (sk3);
118
119 return 0;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700120}