File: test_1_to_1_rtoinfo.c

package info (click to toggle)
lksctp-tools 1.0.19%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 1,272 kB
  • sloc: ansic: 13,566; makefile: 270; sh: 26
file content (115 lines) | stat: -rw-r--r-- 3,739 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* SCTP kernel Implementation
 * Copyright (c) 2003 Hewlett-Packard Development Company, L.P
 * (C) Copyright IBM Corp. 2004
 *
 * This file has test cases to test the getsockopt () and sectsockopt () with
 * SCTP_RTOINFO option on 1-1 style socket
 *
 * This program first gets the default values using getsockopt(). It also sets
 * the value using setsockopt() and gets the set value using getsockopt().
 * A comparison between set values and get values are performed.
 *
 * The SCTP implementation is free software;
 * you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * The SCTP implementation is distributed in the hope that it
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
 *                 ************************
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU CC; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Please send any bug reports or fixes you make to the
 * email address(es):
 *    lksctp developers <lksctp-developers@lists.sourceforge.net>
 *
 * Or submit a bug report through the following website:
 *    http://www.sf.net/projects/lksctp
 *
 * Any bugs reported given to us we will try to fix... any fixes shared will
 * be incorporated into the next SCTP release
 *
 */

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/socket.h>
#include <linux/in.h>         /* for sockaddr_in */
#include <linux/in6.h>         /* for sockaddr_in6 */
#include <errno.h>
#include <sys/uio.h>
#include <netinet/sctp.h>
#include <sctputil.h>

char *TCID = __FILE__;
int TST_TOTAL = 3;
int TST_CNT = 0;

int 
main(void) 
{
	
	int sd, ret;
	socklen_t len;
	struct sctp_rtoinfo srtoinfo; /*setting the variables*/
	struct sctp_rtoinfo grtoinfo; /*Getting the variables*/

	sd = test_socket (PF_INET, SOCK_STREAM, IPPROTO_SCTP);

	len = sizeof(struct sctp_rtoinfo);
	
	/*TEST1 Getting the default values using getsockopt()*/
	ret = getsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &grtoinfo, &len);
	if (ret < 0)
		tst_brkm(TBROK, tst_exit, "getsockopt SCTP_RTOINFO "
			 "ret:%d, errno:%d", ret, errno);

	tst_resm(TPASS, "getsockopt() SCTP_RTOINFO - SUCCESS");

	/*Assigning the values to RTO initial and max and min bounds*/
	srtoinfo.srto_initial=60;
	srtoinfo.srto_max=100;
	srtoinfo.srto_min=40;
	srtoinfo.srto_assoc_id = 0;

	/*TEST2 Setting the values using setsockopt()*/
	ret = setsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &srtoinfo, 
		sizeof(struct sctp_rtoinfo));
	if (ret < 0)
		tst_brkm(TBROK, tst_exit, "setsockopt SCTP_RTOINFO "
			 "ret:%d, errno:%d", ret, errno);

	tst_resm(TPASS, "setsockopt() SCTP_RTOINFO - SUCCESS");

	/*Getting the values which are set using setsockopt()*/
	ret = getsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &grtoinfo, &len);
	if (ret < 0)
		tst_brkm(TBROK, tst_exit, "getsockopt SCTP_RTOINFO "
			 "ret:%d, errno:%d", ret, errno);

	/* TEST3 Compare the get values with the set values. */ 
	if (srtoinfo.srto_initial != grtoinfo.srto_initial &&
            srtoinfo.srto_max != grtoinfo.srto_max &&
            srtoinfo.srto_min != grtoinfo.srto_min)
		tst_brkm(TBROK, tst_exit, "setsockopt/getsockopt SCTP_RTOINFO "
			 "compare failed");

	tst_resm(TPASS, "setsockopt()/getsockopt SCTP_RTOINFO compare - "
		 "SUCCESS");

	close(sd);

	return 0;
}