• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 getsockopt () and sectsockopt () with
6  * SCTP_RTOINFO option on 1-1 style socket
7  *
8  * This program first gets the default values using getsockopt(). It also sets
9  * the value using setsockopt() and gets the set value using getsockopt().
10  * A comparison between set values and get values are performed.
11  *
12  * The SCTP implementation is free software;
13  * you can redistribute it and/or modify it under the terms of
14  * the GNU General Public License as published by
15  * the Free Software Foundation; either version 2, or (at your option)
16  * any later version.
17  *
18  * The SCTP implementation is distributed in the hope that it
19  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20  *                 ************************
21  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22  * See the GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with GNU CC; see the file COPYING.  If not, write to
26  * the Free Software Foundation, 59 Temple Place - Suite 330,
27  * Boston, MA 02111-1307, USA.
28  *
29  * Please send any bug reports or fixes you make to the
30  * email address(es):
31  *    lksctp developers <lksctp-developers@lists.sourceforge.net>
32  *
33  * Or submit a bug report through the following website:
34  *    http://www.sf.net/projects/lksctp
35  *
36  * Any bugs reported given to us we will try to fix... any fixes shared will
37  * be incorporated into the next SCTP release
38  *
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 <linux/socket.h>
49 #include <linux/in.h>         /* for sockaddr_in */
50 #include <linux/in6.h>         /* for sockaddr_in6 */
51 #include <sys/errno.h>
52 #include <sys/uio.h>
53 #include <netinet/sctp.h>
54 #include <sctputil.h>
55 
56 char *TCID = __FILE__;
57 int TST_TOTAL = 3;
58 int TST_CNT = 0;
59 
60 int
main(void)61 main(void)
62 {
63 
64 	int sd, ret;
65 	socklen_t len;
66 	struct sctp_rtoinfo srtoinfo; /*setting the variables*/
67 	struct sctp_rtoinfo grtoinfo; /*Getting the variables*/
68 
69 	sd = test_socket (PF_INET, SOCK_STREAM, IPPROTO_SCTP);
70 
71 	len = sizeof(struct sctp_rtoinfo);
72 
73 	/*TEST1 Getting the default values using getsockopt()*/
74 	ret = getsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &grtoinfo, &len);
75 	if (ret < 0)
76 		tst_brkm(TBROK, tst_exit, "getsockopt SCTP_RTOINFO "
77 			 "ret:%d, errno:%d", ret, errno);
78 
79 	tst_resm(TPASS, "getsockopt() SCTP_RTOINFO - SUCCESS");
80 
81 	/*Assigning the values to RTO initial and max and min bounds*/
82 	srtoinfo.srto_initial=60;
83 	srtoinfo.srto_max=100;
84 	srtoinfo.srto_min=40;
85 
86 	/*TEST2 Setting the values using setsockopt()*/
87 	ret = setsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &srtoinfo,
88 		sizeof(struct sctp_rtoinfo));
89 	if (ret < 0)
90 		tst_brkm(TBROK, tst_exit, "setsockopt SCTP_RTOINFO "
91 			 "ret:%d, errno:%d", ret, errno);
92 
93 	tst_resm(TPASS, "setsockopt() SCTP_RTOINFO - SUCCESS");
94 
95 	/*Getting the values which are set using setsockopt()*/
96 	ret = getsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &grtoinfo, &len);
97 	if (ret < 0)
98 		tst_brkm(TBROK, tst_exit, "getsockopt SCTP_RTOINFO "
99 			 "ret:%d, errno:%d", ret, errno);
100 
101 	/* TEST3 Compare the get values with the set values. */
102 	if (srtoinfo.srto_initial != grtoinfo.srto_initial &&
103             srtoinfo.srto_max != grtoinfo.srto_max &&
104             srtoinfo.srto_min != grtoinfo.srto_min)
105 		tst_brkm(TBROK, tst_exit, "setsockopt/getsockopt SCTP_RTOINFO "
106 			 "compare failed");
107 
108 	tst_resm(TPASS, "setsockopt()/getsockopt SCTP_RTOINFO compare - "
109 		 "SUCCESS");
110 
111 	close(sd);
112 
113 	return 0;
114 }
115