From: Junyeon LEE Date: Wed, 19 Apr 2017 09:55:37 +0000 (+0900) Subject: examples/dtls_client: support tash argument for testing X-Git-Tag: 1.1_Public_Release~597^2~129 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d115f08a72fad0d18b5b49a27f279b916dd0a698;p=rtos%2Ftinyara.git examples/dtls_client: support tash argument for testing After this commit, dtls client example supports ip address input. Change-Id: I869e5dc26a862486b2ab40694c5968b7ea03c9f0 Signed-off-by: Junyeon LEE --- diff --git a/apps/examples/dtls_client/dtls_client_main.c b/apps/examples/dtls_client/dtls_client_main.c index 8f83fba..ad7f1b7 100644 --- a/apps/examples/dtls_client/dtls_client_main.c +++ b/apps/examples/dtls_client/dtls_client_main.c @@ -65,6 +65,12 @@ #define READ_TIMEOUT_MS 1000 #define MAX_RETRY 5 +#define USAGE_DTLS \ +"\n--------------------------USAGE----------------------------\n" \ +"dtlsc\n" \ +"dtlsc server_addr=xxx.xxx.xxx.xxx\n" \ +"-----------------------------------------------------------\n" + #define DEBUG_LEVEL 0 /* @@ -93,7 +99,12 @@ static void my_debug(void *ctx, int level, const char *file, int line, const cha int dtls_client_cb(void *args) { - int ret; + int argc; + char **argv; + char *p; + char *q; + + int ret = 0; int len; mbedtls_net_context server_fd; uint32_t flags; @@ -112,6 +123,31 @@ int dtls_client_cb(void *args) mbedtls_debug_set_threshold(DEBUG_LEVEL); #endif + char *server_addr = SERVER_ADDR; + + argc = ((struct pthread_arg *)args)->argc; + argv = ((struct pthread_arg *)args)->argv; + + if (argc == 0) { +usage: + printf(USAGE_DTLS); + goto exit; + } else { + int i; + for (i = 1; i < argc; i++) { + p = argv[i]; + if ((q = strchr(p, '=')) == NULL) { + goto usage; + } + *q++ = '\0'; + if (strcmp(p, "server_addr") == 0) { + server_addr = q; + } else { + goto usage; + } + } + } + /* * 0. Initialize the RNG and the session data */ @@ -149,10 +185,10 @@ int dtls_client_cb(void *args) /* * 1. Start the connection */ - mbedtls_printf(" . Connecting to udp/%s/%s...", SERVER_NAME, SERVER_PORT); + mbedtls_printf(" . Connecting to udp/%s/%s...", server_addr, SERVER_PORT); fflush(stdout); - if ((ret = mbedtls_net_connect(&server_fd, SERVER_ADDR, SERVER_PORT, MBEDTLS_NET_PROTO_UDP)) != 0) { + if ((ret = mbedtls_net_connect(&server_fd, server_addr, SERVER_PORT, MBEDTLS_NET_PROTO_UDP)) != 0) { mbedtls_printf(" failed\n ! mbedtls_net_connect returned %d\n\n", ret); goto exit; }