Index: tests/testcnx.c
===================================================================
--- tests/testcnx.c	(revision 688)
+++ tests/testcnx.c	(revision 729)
@@ -466,7 +466,45 @@
 				"-----END RSA PRIVATE KEY-----\n";
 
-
-struct fd_list eps = FD_LIST_INITIALIZER(eps);
-
+/* Diffie-Hellman parameters, generated with GNUTLS certtool:
+certtool --generate-dh-params
+				Generator: 06
+
+				Prime: ea:c3:75:0b:32:cf:d9:17:98:5c:da:d1
+					e0:1d:b9:7c:be:29:60:b0:6f:68:a9:f6
+					8d:75:05:59:69:04:ae:39:7c:2b:74:04
+					3c:e2:da:28:8a:9b:93:aa:67:05:a7:3e
+					06:3e:0d:31:63:88:55:ad:5a:bd:41:22
+					b7:58:a7:45:b3:d5:03:ad:de:3c:8d:69
+					42:bf:84:3d:c1:90:e7:39:6a:4b:87:01
+					19:e5:f3:a4:e5:8e:e2:45:d5:0c:6b:17
+					22:2b:2e:50:83:91:0c:5b:82:fc:72:27
+					49:3b:9f:29:11:53:c7:90:b8:8d:87:73
+					1a:7b:05:ab:cb:30:59:16:71:30:60:1b
+					4c:80:15:3a:a2:d3:47:b7:4a:61:de:64
+					7e:79:de:88:53:b7:7a:c6:a2:9a:bb:55
+					40:2d:7a:71:c7:41:b5:29:df:d7:5c:fb
+					42:e4:d8:5e:0b:99:d3:3c:93:0f:33:51
+					8b:f4:60:e4:c5:b5:58:21:c0:51:c4:43
+					25:7c:37:fe:5c:d3:62:6c:2a:af:a7:2a
+					82:d5:d3:e2:bb:5d:ad:84:15:f6:78:d9
+					d5:a8:f7:f0:48:5c:8d:e0:3d:04:ac:cf
+					aa:34:3f:5d:f2:0d:3d:ee:ec:b8:d8:e8
+					ad:dc:d3:40:59:a0:fd:45:62:47:63:c0
+					bd:f5:df:8b
+*/
+static char dh_params_data[] =  "-----BEGIN DH PARAMETERS-----\n"
+				"MIIBCAKCAQEA6sN1CzLP2ReYXNrR4B25fL4pYLBvaKn2jXUFWWkErjl8K3QEPOLa\n"
+				"KIqbk6pnBac+Bj4NMWOIVa1avUEit1inRbPVA63ePI1pQr+EPcGQ5zlqS4cBGeXz\n"
+				"pOWO4kXVDGsXIisuUIORDFuC/HInSTufKRFTx5C4jYdzGnsFq8swWRZxMGAbTIAV\n"
+				"OqLTR7dKYd5kfnneiFO3esaimrtVQC16ccdBtSnf11z7QuTYXguZ0zyTDzNRi/Rg\n"
+				"5MW1WCHAUcRDJXw3/lzTYmwqr6cqgtXT4rtdrYQV9njZ1aj38EhcjeA9BKzPqjQ/\n"
+				"XfINPe7suNjordzTQFmg/UViR2PAvfXfiwIBBg==\n"
+				"-----END DH PARAMETERS-----\n";
+
+
+/* List server endpoints */
+static struct fd_list eps = FD_LIST_INITIALIZER(eps);
+
+/* Pass parameters to the connect thread */
 struct connect_flags {
 	int	proto;
@@ -474,5 +512,6 @@
 };
 
-void * connect_thr(void * arg)
+/* Client's side of the connection established from a separate thread */
+static void * connect_thr(void * arg)
 {
 	struct connect_flags * cf = arg;
@@ -506,4 +545,5 @@
 }
 
+/* Parameters to the handshake thread */
 struct handshake_flags {
 	struct cnxctx * cnx;
@@ -512,5 +552,6 @@
 };
 
-void * handshake_thr(void * arg)
+/* Handshake the client's side */
+static void * handshake_thr(void * arg)
 {
 	struct handshake_flags * hf = arg;
@@ -519,6 +560,7 @@
 	return NULL;
 }
-	
-void * destroy_thr(void * arg)
+
+/* Terminate the client's connection side */
+static void * destroy_thr(void * arg)
 {
 	struct cnxctx * cnx = arg;
@@ -541,11 +583,16 @@
 	gnutls_datum_t notrust_cert 	= { (uint8_t *)notrust_cert_data, 	sizeof(notrust_cert_data) };
 	gnutls_datum_t notrust_priv 	= { (uint8_t *)notrust_priv_data, 	sizeof(notrust_priv_data) };
-	
+	gnutls_datum_t dh_params	= { (uint8_t *)dh_params_data, 		sizeof(dh_params_data) 	  };
+	
+	/* Listening socket, server side */
 	struct cnxctx * listener;
 #ifndef DISABLE_SCTP
 	struct cnxctx * listener_sctp;
 #endif /* DISABLE_SCTP */
+	
+	/* Server & client connected sockets */
 	struct cnxctx * server_side;
 	struct cnxctx * client_side;
+	
 	pthread_t thr;
 	int ret, i;
@@ -579,8 +626,9 @@
 	
 	/* Set default DH params */
-	CHECK_GNUTLS_DO( ret = gnutls_dh_params_generate2( fd_g_config->cnf_sec_data.dh_cache, GNUTLS_DEFAULT_DHBITS), );
+	CHECK_GNUTLS_DO( ret = gnutls_dh_params_import_pkcs3( fd_g_config->cnf_sec_data.dh_cache, &dh_params, GNUTLS_X509_FMT_PEM), );
 	CHECK( GNUTLS_E_SUCCESS, ret );
 	
-	/* Initialize the server addresses */
+	
+	/* Initialize the server address (this should give a safe loopback address + port, even on non-standard configs) */
 	{
 		struct addrinfo hints, *ai, *aip;
@@ -595,4 +643,6 @@
 		};
 		freeaddrinfo(ai);
+		
+		CHECK( 0, FD_IS_LIST_EMPTY(&eps) ? 1 : 0 );
 	}
 	
@@ -647,5 +697,5 @@
 		fd_msg_dump_walk(0, cer);
 		#endif
-			
+		
 		CHECK( 0, fd_msg_bufferize( cer, &cer_buf, &cer_sz ) );
 		CHECK( 0, fd_msg_free(cer) );
@@ -660,5 +710,5 @@
 		
 		/* Start the client thread */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 
 		/* Accept the connection of the client */
@@ -686,5 +736,5 @@
 		free(rcv_buf);
 		
-		/* Now close the connection */
+		/* Now close the connections */
 		fd_cnx_destroy(client_side);
 		fd_cnx_destroy(server_side);
@@ -700,5 +750,5 @@
 		
 		/* Start the client thread */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 
 		/* Accept the connection of the client */
@@ -762,5 +812,5 @@
 		
 		/* Start the client thread */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 
 		/* Accept the connection of the client */
@@ -793,5 +843,5 @@
 		
 		/* At this point in legacy Diameter we start the handshake */
-		CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
+		CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
 		CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -815,5 +865,5 @@
 		
 		/* Now close the connection */
-		CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
+		CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
 		fd_cnx_destroy(server_side);
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -847,5 +897,5 @@
 		
 		/* Start the client thread */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 
 		/* Accept the connection of the client */
@@ -878,5 +928,5 @@
 		
 		/* At this point in legacy Diameter we start the handshake */
-		CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
+		CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
 		CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -900,5 +950,5 @@
 		
 		/* Now close the connection */
-		CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
+		CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
 		fd_cnx_destroy(server_side);
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -932,5 +982,5 @@
 		
 		/* Start the client thread */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 
 		/* Accept the connection of the client */
@@ -944,5 +994,5 @@
 		
 		/* Start the handshake directly */
-		CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
+		CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
 		CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -965,5 +1015,5 @@
 		
 		/* Now close the connection */
-		CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
+		CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
 		fd_cnx_destroy(server_side);
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -997,5 +1047,5 @@
 		
 		/* Start the client thread */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 
 		/* Accept the connection of the client */
@@ -1009,5 +1059,112 @@
 		
 		/* Start the handshake directly */
-		CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
+		CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
+		CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
+		CHECK( 0, pthread_join(thr, NULL) );
+		CHECK( 0, hf.ret );
+		
+		/* Send a few TLS protected messages, and replies */
+		for (i = 0; i < 2 * NB_STREAMS; i++) {
+			CHECK( 0, fd_cnx_send(server_side, cer_buf, cer_sz, 0));
+			CHECK( 0, fd_cnx_receive(client_side, NULL, &rcv_buf, &rcv_sz));
+			CHECK( cer_sz, rcv_sz );
+			CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
+			free(rcv_buf);
+
+			CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz, 0));
+			CHECK( 0, fd_cnx_receive(server_side, NULL, &rcv_buf, &rcv_sz));
+			CHECK( cer_sz, rcv_sz );
+			CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
+			free(rcv_buf);
+		}
+		
+		
+		/* Now close the connection */
+		CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
+		fd_cnx_destroy(server_side);
+		CHECK( 0, pthread_join(thr, NULL) );
+		
+		/* Free the credentials */
+		gnutls_certificate_free_keys(hf.creds);
+		gnutls_certificate_free_cas(hf.creds);
+		gnutls_certificate_free_credentials(hf.creds);
+	}
+#endif /* DISABLE_SCTP */
+	
+	/* Test with different number of streams between server and client */
+#ifndef DISABLE_SCTP
+	{
+		struct connect_flags cf;
+		struct handshake_flags hf;
+		
+		memset(&cf, 0, sizeof(cf));
+		cf.proto = IPPROTO_SCTP;
+		
+		memset(&hf, 0, sizeof(hf));
+		
+		/* Initialize remote certificate */
+		CHECK_GNUTLS_DO( ret = gnutls_certificate_allocate_credentials (&hf.creds), );
+		CHECK( GNUTLS_E_SUCCESS, ret );
+		/* Set the CA */
+		CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_trust_mem( hf.creds, &ca, GNUTLS_X509_FMT_PEM), );
+		CHECK( 1, ret );
+		/* Set the key */
+		CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), );
+		CHECK( GNUTLS_E_SUCCESS, ret );
+		
+		/* Start the client thread with more streams than the server */
+		fd_g_config->cnf_sctp_str = 2 * NB_STREAMS;
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
+
+		/* Accept the connection of the client */
+		server_side = fd_cnx_serv_accept(listener_sctp);
+		CHECK( 1, server_side ? 1 : 0 );
+		
+		/* Retrieve the client connection object */
+		CHECK( 0, pthread_join( thr, (void *)&client_side ) );
+		CHECK( 1, client_side ? 1 : 0 );
+		hf.cnx = client_side;
+		
+		/* Start the handshake directly */
+		CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
+		CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
+		CHECK( 0, pthread_join(thr, NULL) );
+		CHECK( 0, hf.ret );
+		
+		/* Send a few TLS protected message, and replies */
+		for (i = 0; i < 4 * NB_STREAMS; i++) {
+			CHECK( 0, fd_cnx_send(server_side, cer_buf, cer_sz, 0));
+			CHECK( 0, fd_cnx_receive(client_side, NULL, &rcv_buf, &rcv_sz));
+			CHECK( cer_sz, rcv_sz );
+			CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
+			free(rcv_buf);
+
+			CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz, 0));
+			CHECK( 0, fd_cnx_receive(server_side, NULL, &rcv_buf, &rcv_sz));
+			CHECK( cer_sz, rcv_sz );
+			CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
+			free(rcv_buf);
+		}
+		
+		/* Now close the connection */
+		CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
+		fd_cnx_destroy(server_side);
+		CHECK( 0, pthread_join(thr, NULL) );
+		
+		/* Do the same test but with more streams on the server this time */
+		fd_g_config->cnf_sctp_str = NB_STREAMS / 2;
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
+
+		/* Accept the connection of the client */
+		server_side = fd_cnx_serv_accept(listener_sctp);
+		CHECK( 1, server_side ? 1 : 0 );
+		
+		/* Retrieve the client connection object */
+		CHECK( 0, pthread_join( thr, (void *)&client_side ) );
+		CHECK( 1, client_side ? 1 : 0 );
+		hf.cnx = client_side;
+		
+		/* Start the handshake directly */
+		CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
 		CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -1029,113 +1186,6 @@
 		}
 		
-		
 		/* Now close the connection */
-		CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
-		fd_cnx_destroy(server_side);
-		CHECK( 0, pthread_join(thr, NULL) );
-		
-		/* Free the credentials */
-		gnutls_certificate_free_keys(hf.creds);
-		gnutls_certificate_free_cas(hf.creds);
-		gnutls_certificate_free_credentials(hf.creds);
-	}
-#endif /* DISABLE_SCTP */
-	
-	/* Test with different number of streams between server and client */
-#ifndef DISABLE_SCTP
-	{
-		struct connect_flags cf;
-		struct handshake_flags hf;
-		
-		memset(&cf, 0, sizeof(cf));
-		cf.proto = IPPROTO_SCTP;
-		
-		memset(&hf, 0, sizeof(hf));
-		
-		/* Initialize remote certificate */
-		CHECK_GNUTLS_DO( ret = gnutls_certificate_allocate_credentials (&hf.creds), );
-		CHECK( GNUTLS_E_SUCCESS, ret );
-		/* Set the CA */
-		CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_trust_mem( hf.creds, &ca, GNUTLS_X509_FMT_PEM), );
-		CHECK( 1, ret );
-		/* Set the key */
-		CHECK_GNUTLS_DO( ret = gnutls_certificate_set_x509_key_mem( hf.creds, &client_cert, &client_priv, GNUTLS_X509_FMT_PEM), );
-		CHECK( GNUTLS_E_SUCCESS, ret );
-		
-		/* Start the client thread with more streams than the server */
-		fd_g_config->cnf_sctp_str = 2 * NB_STREAMS;
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
-
-		/* Accept the connection of the client */
-		server_side = fd_cnx_serv_accept(listener_sctp);
-		CHECK( 1, server_side ? 1 : 0 );
-		
-		/* Retrieve the client connection object */
-		CHECK( 0, pthread_join( thr, (void *)&client_side ) );
-		CHECK( 1, client_side ? 1 : 0 );
-		hf.cnx = client_side;
-		
-		/* Start the handshake directly */
-		CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
-		CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
-		CHECK( 0, pthread_join(thr, NULL) );
-		CHECK( 0, hf.ret );
-		
-		/* Send a few TLS protected message, and replies */
-		for (i = 0; i < 4 * NB_STREAMS; i++) {
-			CHECK( 0, fd_cnx_send(server_side, cer_buf, cer_sz, 0));
-			CHECK( 0, fd_cnx_receive(client_side, NULL, &rcv_buf, &rcv_sz));
-			CHECK( cer_sz, rcv_sz );
-			CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
-			free(rcv_buf);
-
-			CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz, 0));
-			CHECK( 0, fd_cnx_receive(server_side, NULL, &rcv_buf, &rcv_sz));
-			CHECK( cer_sz, rcv_sz );
-			CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
-			free(rcv_buf);
-		}
-		
-		/* Now close the connection */
-		CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
-		fd_cnx_destroy(server_side);
-		CHECK( 0, pthread_join(thr, NULL) );
-		
-		/* Do the same test but with more streams on the server this time */
-		fd_g_config->cnf_sctp_str = NB_STREAMS / 2;
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
-
-		/* Accept the connection of the client */
-		server_side = fd_cnx_serv_accept(listener_sctp);
-		CHECK( 1, server_side ? 1 : 0 );
-		
-		/* Retrieve the client connection object */
-		CHECK( 0, pthread_join( thr, (void *)&client_side ) );
-		CHECK( 1, client_side ? 1 : 0 );
-		hf.cnx = client_side;
-		
-		/* Start the handshake directly */
-		CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
-		CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
-		CHECK( 0, pthread_join(thr, NULL) );
-		CHECK( 0, hf.ret );
-		
-		/* Send a few TLS protected message, and replies */
-		for (i = 0; i < 2 * NB_STREAMS; i++) {
-			CHECK( 0, fd_cnx_send(server_side, cer_buf, cer_sz, 0));
-			CHECK( 0, fd_cnx_receive(client_side, NULL, &rcv_buf, &rcv_sz));
-			CHECK( cer_sz, rcv_sz );
-			CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
-			free(rcv_buf);
-
-			CHECK( 0, fd_cnx_send(client_side, cer_buf, cer_sz, 0));
-			CHECK( 0, fd_cnx_receive(server_side, NULL, &rcv_buf, &rcv_sz));
-			CHECK( cer_sz, rcv_sz );
-			CHECK( 0, memcmp( rcv_buf, cer_buf, cer_sz ) );
-			free(rcv_buf);
-		}
-		
-		/* Now close the connection */
-		CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
+		CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
 		fd_cnx_destroy(server_side);
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -1174,5 +1224,5 @@
 		
 		/* Start the client thread */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 
 		/* Accept the connection of the client */
@@ -1186,10 +1236,10 @@
 		
 		/* Start the handshake directly */
-		CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
+		CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
 		CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
 		CHECK( 0, pthread_join(thr, NULL) );
 		
 		/* Now close the connection */
-		CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
+		CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
 		fd_cnx_destroy(server_side);
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -1224,5 +1274,5 @@
 		
 		/* Start the client thread */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 
 		/* Accept the connection of the client */
@@ -1236,10 +1286,10 @@
 		
 		/* Start the handshake directly */
-		CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
+		CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
 		CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
 		CHECK( 0, pthread_join(thr, NULL) );
 		
 		/* Now close the connection */
-		CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
+		CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
 		fd_cnx_destroy(server_side);
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -1273,5 +1323,5 @@
 		
 		/* Start the client thread */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 
 		/* Accept the connection of the client */
@@ -1285,10 +1335,10 @@
 		
 		/* Start the handshake directly */
-		CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
+		CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
 		CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
 		CHECK( 0, pthread_join(thr, NULL) );
 		
 		/* Now close the connection */
-		CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
+		CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
 		fd_cnx_destroy(server_side);
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -1322,5 +1372,5 @@
 		
 		/* Start the client thread */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 
 		/* Accept the connection of the client */
@@ -1337,5 +1387,5 @@
 		
 		/* Start the handshake, check it is successful */
-		CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
+		CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
 		CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -1343,10 +1393,10 @@
 		
 		/* Now close the connection */
-		CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
+		CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
 		fd_cnx_destroy(server_side);
 		CHECK( 0, pthread_join(thr, NULL) );
 		
 		/* Do it again with an invalid hostname */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 
 		/* Accept the connection of the client */
@@ -1363,10 +1413,10 @@
 		
 		/* Start the handshake, check it is successful */
-		CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
+		CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
 		CHECK( EINVAL, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
 		CHECK( 0, pthread_join(thr, NULL) );
 		
 		/* Now close the connection */
-		CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
+		CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
 		fd_cnx_destroy(server_side);
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -1405,5 +1455,5 @@
 		
 		/* Start the client thread */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 
 		/* Accept the connection of the client */
@@ -1417,5 +1467,5 @@
 		
 		/* Start the handshake */
-		CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
+		CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
 		CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -1459,5 +1509,5 @@
 		
 		/* Now close the connection */
-		CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
+		CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
 		fd_cnx_destroy(server_side);
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -1497,5 +1547,5 @@
 		
 		/* Start the client thread */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 
 		/* Accept the connection of the client */
@@ -1509,5 +1559,5 @@
 		
 		/* Start the handshake */
-		CHECK( 0, pthread_create(&thr, 0, handshake_thr, &hf) );
+		CHECK( 0, pthread_create(&thr, NULL, handshake_thr, &hf) );
 		CHECK( 0, fd_cnx_handshake(server_side, GNUTLS_SERVER, NULL, NULL) );
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -1550,5 +1600,5 @@
 		
 		/* Now close the connection */
-		CHECK( 0, pthread_create(&thr, 0, destroy_thr, client_side) );
+		CHECK( 0, pthread_create(&thr, NULL, destroy_thr, client_side) );
 		fd_cnx_destroy(server_side);
 		CHECK( 0, pthread_join(thr, NULL) );
@@ -1581,5 +1631,5 @@
 		
 		/* Start the client thread, that should fail */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 		CHECK( 0, pthread_join( thr, (void *)&client_side ) );
 		CHECK( 0, client_side ? 1 : 0 );
@@ -1595,5 +1645,5 @@
 		
 		/* Start the client thread, that should fail */
-		CHECK( 0, pthread_create(&thr, 0, connect_thr, &cf) );
+		CHECK( 0, pthread_create(&thr, NULL, connect_thr, &cf) );
 		CHECK( 0, pthread_join( thr, (void *)&client_side ) );
 		CHECK( 0, client_side ? 1 : 0 );
