| 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 <[email protected]> |
| 32 | * |
| 33 | * Or submit a bug report through the following website: |
| 34 | * https://github.com/sctp/lksctp-tools/ |
| 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 <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 |
| 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 | srtoinfo.srto_assoc_id = 0; |
| 86 | |
| 87 | /*TEST2 Setting the values using setsockopt()*/ |
| 88 | ret = setsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &srtoinfo, |
| 89 | sizeof(struct sctp_rtoinfo)); |
| 90 | if (ret < 0) |
| 91 | tst_brkm(TBROK, tst_exit, "setsockopt SCTP_RTOINFO " |
| 92 | "ret:%d, errno:%d", ret, errno); |
| 93 | |
| 94 | tst_resm(TPASS, "setsockopt() SCTP_RTOINFO - SUCCESS"); |
| 95 | |
| 96 | /*Getting the values which are set using setsockopt()*/ |
| 97 | ret = getsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &grtoinfo, &len); |
| 98 | if (ret < 0) |
| 99 | tst_brkm(TBROK, tst_exit, "getsockopt SCTP_RTOINFO " |
| 100 | "ret:%d, errno:%d", ret, errno); |
| 101 | |
| 102 | /* TEST3 Compare the get values with the set values. */ |
| 103 | if (srtoinfo.srto_initial != grtoinfo.srto_initial && |
| 104 | srtoinfo.srto_max != grtoinfo.srto_max && |
| 105 | srtoinfo.srto_min != grtoinfo.srto_min) |
| 106 | tst_brkm(TBROK, tst_exit, "setsockopt/getsockopt SCTP_RTOINFO " |
| 107 | "compare failed"); |
| 108 | |
| 109 | tst_resm(TPASS, "setsockopt()/getsockopt SCTP_RTOINFO compare - " |
| 110 | "SUCCESS"); |
| 111 | |
| 112 | close(sd); |
| 113 | |
| 114 | return 0; |
| 115 | } |