Home | History | Annotate | Download | only in func_tests
      1 /* SCTP kernel Implementation
      2  * 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  *
      8  * The SCTP implementation is free software;
      9  * 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  *
     14  * The SCTP implementation is distributed in the hope that it
     15  * 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 (at) 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>
     44 #include <netinet/in.h>         /* for sockaddr_in */
     45 #include <arpa/inet.h>
     46 #include <errno.h>
     47 #include <netinet/sctp.h>
     48 #include <sys/uio.h>
     49 #include <sctputil.h>
     50 
     51 char *TCID = __FILE__;
     52 int TST_TOTAL = 1;
     53 int TST_CNT = 0;
     54 
     55 int
     56 main (int argc, char **argv)
     57 {
     58 	int sk1, sk2, sk3, pf_class;
     59 	socklen_t len;
     60 	struct sockaddr_in lstn_addr, acpt_addr;
     61 	struct sockaddr_in conn_addr;
     62 	char * buffer_rcv;
     63 	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 
     72 	/* Opening the socket*/
     73 
     74 	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 
     79         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);
     82 
     83         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);
     86 
     87 	test_bind(sk3, (struct sockaddr *) &lstn_addr, sizeof(lstn_addr));
     88 
     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);
    102 	test_connect(sk1, (struct sockaddr *) &conn_addr, len);
    103 
    104 	sk2 = test_accept(sk3, (struct sockaddr *) &acpt_addr, &len);
    105 
    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 
    115 	close (sk1);
    116 	close (sk2);
    117 	close (sk3);
    118 
    119         return 0;
    120 }
    121