1 /* SCTP kernel Implementation
2 * Copyright (c) 2003 Hewlett-Packard Development Company, L.P
3 * (C) Copyright IBM Corp. 2004
5 * This file has test cases to test the recvfrom () call for 1-1 style sockets
7 * TEST1: Bad socket descriptor
8 * TEST2: Invalid socket
9 * TEST3: Invalid message pointer
10 * TEST4: On a listening socket
11 * TEST5: Reading on a socket that received SHUTDOWN
12 * TEST6: Reading the pending message on socket that received SHUTDOWN
13 * TEST7: No more message and association is shutdown
15 * The SCTP implementation is free software;
16 * you can redistribute it and/or modify it under the terms of
17 * the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
21 * The SCTP implementation is distributed in the hope that it
22 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
23 * ************************
24 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25 * See the GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with GNU CC; see the file COPYING. If not, write to
29 * the Free Software Foundation, 59 Temple Place - Suite 330,
30 * Boston, MA 02111-1307, USA.
32 * Please send any bug reports or fixes you make to the
34 * lksctp developers <lksctp-developers@lists.sourceforge.net>
36 * Or submit a bug report through the following website:
37 * http://www.sf.net/projects/lksctp
39 * Any bugs reported given to us we will try to fix... any fixes shared will
40 * be incorporated into the next SCTP release
49 #include <sys/types.h>
50 #include <sys/socket.h>
51 #include <netinet/in.h> /* for sockaddr_in */
52 #include <arpa/inet.h>
54 #include <netinet/sctp.h>
56 #include <linux/socket.h>
59 char *TCID = __FILE__;
64 main(int argc, char *argv[])
68 int sk,pf_class,lstn_sk,acpt_sk, flag;
69 char *message = "hello, world!\n";
73 struct sockaddr_in conn_addr,lstn_addr,svr_addr;
75 /* Rather than fflush() throughout the code, set stdout to
78 setvbuf(stdout, NULL, _IONBF, 0);
79 setvbuf(stderr, NULL, _IONBF, 0);
81 message_rcv = malloc(512);
85 sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP);
87 lstn_sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP);
89 conn_addr.sin_family = AF_INET;
90 conn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK;
91 conn_addr.sin_port = htons(SCTP_TESTPORT_1);
93 lstn_addr.sin_family = AF_INET;
94 lstn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK;
95 lstn_addr.sin_port = htons(SCTP_TESTPORT_1);
97 /*Binding the listen socket*/
98 test_bind(lstn_sk, (struct sockaddr *) &lstn_addr, sizeof(lstn_addr));
100 /*Listening the socket*/
101 test_listen(lstn_sk, 10);
103 len = sizeof(struct sockaddr_in);
105 test_connect(sk, (struct sockaddr *) &conn_addr, len);
107 acpt_sk = test_accept(lstn_sk, (struct sockaddr *)&svr_addr, &len);
109 msg_count = (strlen(message) + 1);
112 /*Sending the message*/
113 count = test_send(sk, message, msg_count, flag);
115 /*recvfrom () TEST1: Bad socket descriptor, EBADF Expected error*/
116 count = recvfrom(-1, message_rcv, msg_count, flag,
117 (struct sockaddr *)&svr_addr, &len);
118 if (count != -1 || errno != EBADF)
119 tst_brkm(TBROK, tst_exit, "recvfrom with a bad socket "
120 "descriptor count:%d, errno:%d", count, errno);
122 tst_resm(TPASS, "recvfrom() with a bad socket descriptor - EBADF");
124 /*recvfrom () TEST2: Invalid socket , ENOTSOCK Expected error*/
125 count = recvfrom(0, message_rcv, msg_count, flag,
126 (struct sockaddr *)&svr_addr, &len);
127 if (count != -1 || errno != ENOTSOCK)
128 tst_brkm(TBROK, tst_exit, "recvfrom with invalid socket "
129 "count:%d, errno:%d", count, errno);
131 tst_resm(TPASS, "recvfrom() with invalid socket - ENOTSOCK");
133 /*recvfrom () TEST3: Invalid message pointer EFAULT, Expected error*/
134 count = recvfrom(acpt_sk, (char *)-1, msg_count, flag,
135 (struct sockaddr *)&svr_addr, &len);
136 if (count != -1 || errno != EFAULT)
137 tst_brkm(TBROK, tst_exit, "recvfrom with invalid message "
138 "pointer count:%d, errno:%d", count, errno);
140 tst_resm(TPASS, "recvfrom() with invalid message ptr - EFAULT");
142 /*TEST4: recvfrom on listening socket,ENOTCONN Expected error*/
143 count = recvfrom(lstn_sk, message_rcv, msg_count, flag,
144 (struct sockaddr *)&svr_addr, &len);
145 if (count != -1 || errno != ENOTCONN)
146 tst_brkm(TBROK, tst_exit, "recvfrom on listening socket "
147 "count:%d, errno:%d", count, errno);
149 tst_resm(TPASS, "recvfrom() on listening socket - ENOTCONN");
151 count = test_send(acpt_sk, message, msg_count, flag);
153 ret = test_shutdown(sk, SHUT_WR);
155 /*recvfrom () TEST5:reading on a socket that received SHUTDOWN*/
156 count = recvfrom(acpt_sk, message_rcv, msg_count, flag,
157 (struct sockaddr *)&svr_addr, &len);
159 tst_brkm(TBROK, tst_exit, "recvfrom on a socket that has "
160 "received shutdown count:%d, errno:%d", count, errno);
162 tst_resm(TPASS, "recvfrom() on a socket that has received shutdown - "
165 /*recvfrom () TEST6:reading the pending message on socket that sent
167 count = recvfrom(sk, message_rcv, msg_count, flag,
168 (struct sockaddr *)&svr_addr, &len);
170 tst_brkm(TBROK, tst_exit, "recvfrom on a socket with pending "
171 "message that has sent shutdown count:%d, errno:%d",
174 tst_resm(TPASS, "recvfrom() on a socket with pending message that has "
175 "sent shutdown - SUCCESS");
177 /*recvfrom () TEST7: No more message and association is shutdown,
178 ENOTCONN Expected error*/
179 count = recvfrom(sk, message_rcv, msg_count, flag,
180 (struct sockaddr *)&svr_addr, &len);
181 if (count != -1 || errno != ENOTCONN)
182 tst_brkm(TBROK, tst_exit, "recvfrom on a socket with no "
183 "pending messages and has sent shutdown count:%d, "
184 "errno:%d", count, errno);
186 tst_resm(TPASS, "recvfrom() on a socket with no pending messages and "
187 " has sent shutdown - ENOTCONN");