annotate freeDiameter/tests/testsctp.c @ 478:b65f32c20e6d

Fix for FreeBSD which is less tolerant
author Sebastien Decugis <sdecugis@nict.go.jp>
date Mon, 09 Aug 2010 18:11:02 +0900
parents 4e4ed23028ca
children a186743b89a3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
477
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
5 * Copyright (c) 2010, WIDE Project and NICT *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 #include "tests.h"
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 #include <cnxctx.h>
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 #ifndef TEST_PORT
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41 #define TEST_PORT 3868
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42 #endif /* TEST_PORT */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
43
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
44 #ifndef NB_STREAMS
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
45 #define NB_STREAMS 10
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
46 #endif /* NB_STREAMS */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
47
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
48
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
49
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
50 /* Main test routine */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 int main(int argc, char *argv[])
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52 {
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53 #ifdef DISABLE_SCTP
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54 /* In this case, we don't perform this simple test */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55 PASSTEST();
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56 #endif
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
57 int sock, srvsock, clisock;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
58 char buf1[]="abcdef";
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
59 char *buf2;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
60 size_t sz;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
61 struct fd_list eps = FD_LIST_INITIALIZER(eps);
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
62 uint32_t status = 0;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
63 uint16_t str;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
64 int ev;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
65
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
66 /* Initialize the server addresses */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
67 {
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68 struct addrinfo hints, *ai, *aip;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
69 memset(&hints, 0, sizeof(hints));
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
70 hints.ai_flags = AI_NUMERICSERV;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
71 hints.ai_family = AF_INET;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
72 CHECK( 0, getaddrinfo("localhost", _stringize(TEST_PORT), &hints, &ai) );
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73 aip = ai;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
74 while (aip) {
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75 CHECK( 0, fd_ep_add_merge( &eps, aip->ai_addr, aip->ai_addrlen, EP_FL_DISC | EP_ACCEPTALL ));
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
76 aip = aip->ai_next;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
77 };
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
78 freeaddrinfo(ai);
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
79 }
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
80
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
81 /* First, initialize the daemon modules */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
82 INIT_FD();
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
83
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
84 /* Restrain the # of streams */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
85 fd_g_config->cnf_sctp_str = NB_STREAMS;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
86
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87 /* Create the server socket */
478
b65f32c20e6d Fix for FreeBSD which is less tolerant
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 477
diff changeset
88 CHECK( 0, fd_sctp_create_bind_server( &sock, AF_INET6, &eps, TEST_PORT ));
477
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
89
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
90 /* Accept incoming clients */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
91 CHECK( 0, fd_sctp_listen( sock ));
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
92
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
93 /* Now, create the client socket */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
94 CHECK( 0, fd_sctp_client( &clisock, 0, TEST_PORT, &eps ));
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
95
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
96 /* Accept this connection */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
97 srvsock = accept(sock, NULL, NULL);
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
98
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
99 /* Send a first message */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
100 CHECK( 0, fd_sctp_sendstr(srvsock, 1, (uint8_t *)buf1, sizeof(buf1), &status) );
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
101 CHECK( 0, status);
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
102
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
103 /* Receive this message */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
104 CHECK( 0, fd_sctp_recvmeta(clisock, &str, (uint8_t **)&buf2, &sz, &ev, &status) );
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
105 CHECK( FDEVP_CNX_MSG_RECV, ev);
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
106 CHECK( 0, status);
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
107 CHECK( 1, str);
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
108 CHECK( sizeof(buf1), sz );
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
109 CHECK( 0, memcmp(buf1, buf2, sz) );
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
110 free(buf2); buf2 = NULL;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
111
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
112 /* Send in the other direction */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
113 CHECK( 0, fd_sctp_sendstr(clisock, 2, (uint8_t *)buf1, sizeof(buf1), &status) );
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
114 CHECK( 0, status);
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
115
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
116 /* Receive this message */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
117 CHECK( 0, fd_sctp_recvmeta(srvsock, &str, (uint8_t **)&buf2, &sz, &ev, &status) );
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
118 CHECK( FDEVP_CNX_MSG_RECV, ev);
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
119 CHECK( 0, status);
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
120 CHECK( 2, str);
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
121 CHECK( sizeof(buf1), sz );
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
122 CHECK( 0, memcmp(buf1, buf2, sz) );
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
123 free(buf2); buf2 = NULL;
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
124
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
125 /* That's all for the tests yet */
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
126 PASSTEST();
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
127 }
4e4ed23028ca Add a simple test to verify ticket #12
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
128
"Welcome to our mercurial repository"