Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 1 | /* SCTP kernel Implementation |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 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 | * |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 8 | * The SCTP implementation is free software; |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 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 | * |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 14 | * The SCTP implementation is distributed in the hope that it |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 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@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 Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 44 | #include <netinet/in.h> /* for sockaddr_in */ |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 45 | #include <arpa/inet.h> |
| 46 | #include <errno.h> |
| 47 | #include <netinet/sctp.h> |
| 48 | #include <sys/uio.h> |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 49 | #include <sctputil.h> |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 50 | |
| 51 | char *TCID = __FILE__; |
| 52 | int TST_TOTAL = 1; |
| 53 | int TST_CNT = 0; |
| 54 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 55 | int |
| 56 | main (int argc, char **argv) |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 57 | { |
mridge | 64a341f | 2006-01-03 19:16:46 +0000 | [diff] [blame] | 58 | int sk1, sk2, sk3, pf_class; |
| 59 | socklen_t len; |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 60 | struct sockaddr_in lstn_addr, acpt_addr; |
| 61 | struct sockaddr_in conn_addr; |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 62 | char * buffer_rcv; |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 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 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 72 | /* Opening the socket*/ |
| 73 | |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 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 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 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); |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 82 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 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); |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 86 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 87 | test_bind(sk3, (struct sockaddr *) &lstn_addr, sizeof(lstn_addr)); |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 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); |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 102 | test_connect(sk1, (struct sockaddr *) &conn_addr, len); |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 103 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 104 | sk2 = test_accept(sk3, (struct sockaddr *) &acpt_addr, &len); |
mridge | 5ba96af | 2004-02-23 16:17:34 +0000 | [diff] [blame] | 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 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 115 | close (sk1); |
| 116 | close (sk2); |
| 117 | close (sk3); |
| 118 | |
| 119 | return 0; |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 120 | } |