mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-03-23 06:35:08 +00:00
Actually use UDP for DTLS in test client/server
This commit is contained in:
parent
f5a1312eaa
commit
8a06d9c5d6
|
@ -839,12 +839,14 @@ int main( int argc, char *argv[] )
|
|||
if( opt.server_addr == NULL)
|
||||
opt.server_addr = opt.server_name;
|
||||
|
||||
printf( " . Connecting to tcp/%s/%-4d...", opt.server_addr,
|
||||
opt.server_port );
|
||||
printf( " . Connecting to %s/%s/%-4d...",
|
||||
opt.transport == SSL_TRANSPORT_STREAM ? "tcp" : "udp",
|
||||
opt.server_addr, opt.server_port );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = net_connect( &server_fd, opt.server_addr,
|
||||
opt.server_port, NET_PROTO_TCP ) ) != 0 )
|
||||
if( ( ret = net_connect( &server_fd, opt.server_addr, opt.server_port,
|
||||
opt.transport == SSL_TRANSPORT_STREAM ?
|
||||
NET_PROTO_TCP : NET_PROTO_UDP ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! net_connect returned -0x%x\n\n", -ret );
|
||||
goto exit;
|
||||
|
@ -1259,8 +1261,9 @@ reconnect:
|
|||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = net_connect( &server_fd, opt.server_name,
|
||||
opt.server_port , NET_PROTO_TCP) ) != 0 )
|
||||
if( ( ret = net_connect( &server_fd, opt.server_name, opt.server_port,
|
||||
opt.transport == SSL_TRANSPORT_STREAM ?
|
||||
NET_PROTO_TCP : NET_PROTO_UDP ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! net_connect returned -0x%x\n\n", -ret );
|
||||
goto exit;
|
||||
|
|
|
@ -1242,11 +1242,15 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* 2. Setup the listening TCP socket
|
||||
*/
|
||||
printf( " . Bind on tcp://localhost:%-4d/ ...", opt.server_port );
|
||||
printf( " . Bind on %s://%s:%-4d/ ...",
|
||||
opt.transport == SSL_TRANSPORT_STREAM ? "tcp" : "udp",
|
||||
opt.server_addr ? opt.server_addr : "*",
|
||||
opt.server_port );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = net_bind( &listen_fd, opt.server_addr,
|
||||
opt.server_port, NET_PROTO_TCP ) ) != 0 )
|
||||
if( ( ret = net_bind( &listen_fd, opt.server_addr, opt.server_port,
|
||||
opt.transport == SSL_TRANSPORT_STREAM ?
|
||||
NET_PROTO_TCP : NET_PROTO_UDP ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! net_bind returned -0x%x\n\n", -ret );
|
||||
goto exit;
|
||||
|
@ -1435,8 +1439,33 @@ reset:
|
|||
#endif
|
||||
|
||||
if( client_fd != -1 )
|
||||
{
|
||||
net_close( client_fd );
|
||||
|
||||
/*
|
||||
* With UDP, client_fd == bind_fd, so we just closed bind_fd. Bind it
|
||||
* again. (We really want to close it, to empty the message queue.)
|
||||
*/
|
||||
#if defined(POLARSSL_SSL_PROTO_DTLS)
|
||||
if( opt.transport == SSL_TRANSPORT_DATAGRAM )
|
||||
{
|
||||
printf( " . Bind on udp://%s:%-4d/ ...",
|
||||
opt.server_addr ? opt.server_addr : "*",
|
||||
opt.server_port );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = net_bind( &listen_fd, opt.server_addr, opt.server_port,
|
||||
NET_PROTO_UDP ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! net_bind returned -0x%x\n\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n" );
|
||||
}
|
||||
#endif /* POLARSSL_SSL_PROTO_DTLS */
|
||||
}
|
||||
|
||||
ssl_session_reset( &ssl );
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue