mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2026-02-19 00:39:46 +00:00
Simplify net_accept() with UDP sockets
This is made possible by the new API where net_accept() gets a pointer to bind_ctx, so it can update it.
This commit is contained in:
@@ -273,13 +273,6 @@ reset:
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* With UDP, bind_fd is hijacked by client_fd, so bind a new one */
|
||||
if( ( ret = mbedtls_net_bind( &listen_fd, NULL, "4433", MBEDTLS_NET_PROTO_UDP ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mbedtls_net_bind returned -0x%x\n\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* For HelloVerifyRequest cookies */
|
||||
if( ( ret = mbedtls_ssl_set_client_transport_id( &ssl,
|
||||
client_ip, cliip_len ) ) != 0 )
|
||||
|
||||
@@ -1896,28 +1896,6 @@ reset:
|
||||
|
||||
mbedtls_printf( " ok\n" );
|
||||
|
||||
/*
|
||||
* With UDP, bind_fd is hijacked by client_fd, so bind a new one
|
||||
*/
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
{
|
||||
mbedtls_printf( " . Re-bind on udp://%s:%s/ ...",
|
||||
opt.server_addr ? opt.server_addr : "*",
|
||||
opt.server_port );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = mbedtls_net_bind( &listen_fd, opt.server_addr,
|
||||
opt.server_port, MBEDTLS_NET_PROTO_UDP ) ) != 0 )
|
||||
{
|
||||
mbedtls_printf( " failed\n ! mbedtls_net_bind returned -0x%x\n\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf( " ok\n" );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
||||
|
||||
/*
|
||||
* 4. Handshake
|
||||
*/
|
||||
|
||||
@@ -533,6 +533,8 @@ int main( int argc, char *argv[] )
|
||||
* 2. Wait until a client connects
|
||||
*/
|
||||
accept:
|
||||
mbedtls_net_free( &client_fd );
|
||||
|
||||
mbedtls_printf( " . Waiting for a remote connection ..." );
|
||||
fflush( stdout );
|
||||
|
||||
@@ -543,20 +545,6 @@ accept:
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf( " ok\n" );
|
||||
fflush( stdout );
|
||||
|
||||
mbedtls_printf( " . Re-bind on UDP/%s/%s ...",
|
||||
opt.listen_addr, opt.listen_port );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = mbedtls_net_bind( &listen_fd, opt.listen_addr, opt.listen_port,
|
||||
MBEDTLS_NET_PROTO_UDP ) ) != 0 )
|
||||
{
|
||||
mbedtls_printf( " failed\n ! mbedtls_net_bind returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf( " ok\n" );
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user