Make 'port' a string in NET module

- avoids dependency on snprintf
- allows using "smtps" instead of "456" if desired
This commit is contained in:
Manuel Pégourié-Gonnard 2015-06-23 12:30:57 +02:00
parent e244f9ffc0
commit c0d749418b
16 changed files with 46 additions and 87 deletions

View file

@ -61,7 +61,7 @@ int main( void )
#include "mbedtls/certs.h"
#include "mbedtls/timing.h"
#define SERVER_PORT 4433
#define SERVER_PORT "4433"
#define SERVER_NAME "localhost"
#define SERVER_ADDR "127.0.0.1" /* forces IPv4 */
#define MESSAGE "Echo this"
@ -142,8 +142,7 @@ int main( int argc, char *argv[] )
/*
* 1. Start the connection
*/
mbedtls_printf( " . Connecting to udp/%s/%4d...", SERVER_NAME,
SERVER_PORT );
mbedtls_printf( " . Connecting to udp/%s/%s...", SERVER_NAME, SERVER_PORT );
fflush( stdout );
if( ( ret = mbedtls_net_connect( &server_fd, SERVER_ADDR,

View file

@ -167,7 +167,7 @@ int main( void )
printf( " . Bind on udp/*/4433 ..." );
fflush( stdout );
if( ( ret = mbedtls_net_bind( &listen_fd, NULL, 4433, MBEDTLS_NET_PROTO_UDP ) ) != 0 )
if( ( ret = mbedtls_net_bind( &listen_fd, NULL, "4433", MBEDTLS_NET_PROTO_UDP ) ) != 0 )
{
printf( " failed\n ! mbedtls_net_bind returned %d\n\n", ret );
goto exit;
@ -274,7 +274,7 @@ reset:
}
/* 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 )
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;

View file

@ -60,7 +60,7 @@ int main( void )
#include <string.h>
#define SERVER_PORT 4433
#define SERVER_PORT "4433"
#define SERVER_NAME "localhost"
#define GET_REQUEST "GET / HTTP/1.0\r\n\r\n"
@ -132,8 +132,7 @@ int main( void )
/*
* 1. Start the connection
*/
mbedtls_printf( " . Connecting to tcp/%s/%4d...", SERVER_NAME,
SERVER_PORT );
mbedtls_printf( " . Connecting to tcp/%s/%s...", SERVER_NAME, SERVER_PORT );
fflush( stdout );
if( ( ret = mbedtls_net_connect( &server_fd, SERVER_NAME,

View file

@ -70,7 +70,7 @@ int main( void )
#define DFL_SERVER_NAME "localhost"
#define DFL_SERVER_ADDR NULL
#define DFL_SERVER_PORT 4433
#define DFL_SERVER_PORT "4433"
#define DFL_REQUEST_PAGE "/"
#define DFL_REQUEST_SIZE -1
#define DFL_DEBUG_LEVEL 0
@ -272,7 +272,7 @@ struct options
{
const char *server_name; /* hostname of the server (client only) */
const char *server_addr; /* address of the server (client only) */
int server_port; /* port on which the ssl service runs */
const char *server_port; /* port on which the ssl service runs */
int debug_level; /* level of debugging */
int nbio; /* should I/O be blocking? */
uint32_t read_timeout; /* timeout on mbedtls_ssl_read() in milliseconds */
@ -502,11 +502,7 @@ int main( int argc, char *argv[] )
else if( strcmp( p, "server_addr" ) == 0 )
opt.server_addr = q;
else if( strcmp( p, "server_port" ) == 0 )
{
opt.server_port = atoi( q );
if( opt.server_port < 1 || opt.server_port > 65535 )
goto usage;
}
opt.server_port = q;
else if( strcmp( p, "dtls" ) == 0 )
{
int t = atoi( q );
@ -1026,7 +1022,7 @@ int main( int argc, char *argv[] )
if( opt.server_addr == NULL)
opt.server_addr = opt.server_name;
mbedtls_printf( " . Connecting to %s/%s/%-4d...",
mbedtls_printf( " . Connecting to %s/%s/%s...",
opt.transport == MBEDTLS_SSL_TRANSPORT_STREAM ? "tcp" : "udp",
opt.server_addr, opt.server_port );
fflush( stdout );

View file

@ -202,7 +202,7 @@ int main( void )
mbedtls_printf( " . Bind on https://localhost:4433/ ..." );
fflush( stdout );
if( ( ret = mbedtls_net_bind( &listen_fd, NULL, 4433, MBEDTLS_NET_PROTO_TCP ) ) != 0 )
if( ( ret = mbedtls_net_bind( &listen_fd, NULL, "4433", MBEDTLS_NET_PROTO_TCP ) ) != 0 )
{
mbedtls_printf( " failed\n ! mbedtls_net_bind returned %d\n\n", ret );
goto exit;

View file

@ -84,7 +84,7 @@ int main( void )
#endif
#define DFL_SERVER_NAME "localhost"
#define DFL_SERVER_PORT 465
#define DFL_SERVER_PORT "465"
#define DFL_USER_NAME "user"
#define DFL_USER_PWD "password"
#define DFL_MAIL_FROM ""
@ -140,7 +140,7 @@ int main( void )
struct options
{
const char *server_name; /* hostname of the server (client only) */
int server_port; /* port on which the ssl service runs */
const char *server_port; /* port on which the ssl service runs */
int debug_level; /* level of debugging */
int authentication; /* if authentication is required */
int mode; /* SSL/TLS (0) or STARTTLS (1) */
@ -416,11 +416,7 @@ int main( int argc, char *argv[] )
if( strcmp( p, "server_name" ) == 0 )
opt.server_name = q;
else if( strcmp( p, "server_port" ) == 0 )
{
opt.server_port = atoi( q );
if( opt.server_port < 1 || opt.server_port > 65535 )
goto usage;
}
opt.server_port = q;
else if( strcmp( p, "debug_level" ) == 0 )
{
opt.debug_level = atoi( q );
@ -566,7 +562,7 @@ int main( int argc, char *argv[] )
/*
* 2. Start the connection
*/
mbedtls_printf( " . Connecting to tcp/%s/%-4d...", opt.server_name,
mbedtls_printf( " . Connecting to tcp/%s/%s...", opt.server_name,
opt.server_port );
fflush( stdout );

View file

@ -448,7 +448,7 @@ int main( void )
mbedtls_printf( " . Bind on https://localhost:4433/ ..." );
fflush( stdout );
if( ( ret = mbedtls_net_bind( &listen_fd, NULL, 4433, MBEDTLS_NET_PROTO_TCP ) ) != 0 )
if( ( ret = mbedtls_net_bind( &listen_fd, NULL, "4433", MBEDTLS_NET_PROTO_TCP ) ) != 0 )
{
mbedtls_printf( " failed\n ! mbedtls_net_bind returned %d\n\n", ret );
goto exit;

View file

@ -161,7 +161,7 @@ int main( void )
mbedtls_printf( " . Bind on https://localhost:4433/ ..." );
fflush( stdout );
if( ( ret = mbedtls_net_bind( &listen_fd, NULL, 4433, MBEDTLS_NET_PROTO_TCP ) ) != 0 )
if( ( ret = mbedtls_net_bind( &listen_fd, NULL, "4433", MBEDTLS_NET_PROTO_TCP ) ) != 0 )
{
mbedtls_printf( " failed\n ! mbedtls_net_bind returned %d\n\n", ret );
goto exit;

View file

@ -91,7 +91,7 @@ int main( void )
#endif
#define DFL_SERVER_ADDR NULL
#define DFL_SERVER_PORT 4433
#define DFL_SERVER_PORT "4433"
#define DFL_DEBUG_LEVEL 0
#define DFL_NBIO 0
#define DFL_READ_TIMEOUT 0
@ -346,7 +346,7 @@ int main( void )
struct options
{
const char *server_addr; /* address on which the ssl service runs */
int server_port; /* port on which the ssl service runs */
const char *server_port; /* port on which the ssl service runs */
int debug_level; /* level of debugging */
int nbio; /* should I/O be blocking? */
uint32_t read_timeout; /* timeout on mbedtls_ssl_read() in milliseconds */
@ -931,11 +931,7 @@ int main( int argc, char *argv[] )
*q++ = '\0';
if( strcmp( p, "server_port" ) == 0 )
{
opt.server_port = atoi( q );
if( opt.server_port < 1 || opt.server_port > 65535 )
goto usage;
}
opt.server_port = q;
else if( strcmp( p, "server_addr" ) == 0 )
opt.server_addr = q;
else if( strcmp( p, "dtls" ) == 0 )
@ -1558,7 +1554,7 @@ int main( int argc, char *argv[] )
/*
* 2. Setup the listening TCP socket
*/
mbedtls_printf( " . Bind on %s://%s:%-4d/ ...",
mbedtls_printf( " . Bind on %s://%s:%s/ ...",
opt.transport == MBEDTLS_SSL_TRANSPORT_STREAM ? "tcp" : "udp",
opt.server_addr ? opt.server_addr : "*",
opt.server_port );
@ -1906,7 +1902,7 @@ reset:
#if defined(MBEDTLS_SSL_PROTO_DTLS)
if( opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
{
mbedtls_printf( " . Re-bind on udp://%s:%-4d/ ...",
mbedtls_printf( " . Re-bind on udp://%s:%s/ ...",
opt.server_addr ? opt.server_addr : "*",
opt.server_port );
fflush( stdout );