diff --git a/api/examples/tutorials/static-client-tutorial1.c b/api/examples/tutorials/static-client-tutorial1.c index c50ea07..4cfa2a8 100644 --- a/api/examples/tutorials/static-client-tutorial1.c +++ b/api/examples/tutorials/static-client-tutorial1.c @@ -30,7 +30,7 @@ int main(void) AwaStaticClient_SetLogLevel(AwaLogLevel_Error); AwaStaticClient_SetEndPointName(awaClient, "AwaStaticClient1"); - AwaStaticClient_SetCoAPListenAddressPort(awaClient, "0.0.0.0", 6000); + AwaStaticClient_SetCoAPListenAddressPort(awaClient, "0.0.0.0", 0); AwaStaticClient_SetBootstrapServerURI(awaClient, "coap://[127.0.0.1]:15685"); AwaStaticClient_Init(awaClient); diff --git a/api/examples/tutorials/static-client-tutorial2.c b/api/examples/tutorials/static-client-tutorial2.c index 857c5fd..b3d2f56 100644 --- a/api/examples/tutorials/static-client-tutorial2.c +++ b/api/examples/tutorials/static-client-tutorial2.c @@ -63,7 +63,7 @@ int main(void) AwaStaticClient_SetLogLevel(AwaLogLevel_Error); AwaStaticClient_SetEndPointName(awaClient, "AwaStaticClient1"); - AwaStaticClient_SetCoAPListenAddressPort(awaClient, "0.0.0.0", 6000); + AwaStaticClient_SetCoAPListenAddressPort(awaClient, "0.0.0.0", 0); AwaStaticClient_SetBootstrapServerURI(awaClient, "coap://[127.0.0.1]:15685"); AwaStaticClient_Init(awaClient); diff --git a/api/examples/tutorials/static-client-tutorial3.c b/api/examples/tutorials/static-client-tutorial3.c index e3eb400..93396f6 100644 --- a/api/examples/tutorials/static-client-tutorial3.c +++ b/api/examples/tutorials/static-client-tutorial3.c @@ -152,7 +152,7 @@ int main(void) AwaStaticClient_SetLogLevel(AwaLogLevel_Error); AwaStaticClient_SetEndPointName(awaClient, "AwaStaticClient1"); - AwaStaticClient_SetCoAPListenAddressPort(awaClient, "0.0.0.0", 6000); + AwaStaticClient_SetCoAPListenAddressPort(awaClient, "0.0.0.0", 0); AwaStaticClient_SetBootstrapServerURI(awaClient, "coap://[127.0.0.1]:15685"); AwaStaticClient_Init(awaClient); diff --git a/core/src/client/lwm2m_static.c b/core/src/client/lwm2m_static.c index 3439ed6..4d65a72 100644 --- a/core/src/client/lwm2m_static.c +++ b/core/src/client/lwm2m_static.c @@ -22,6 +22,8 @@ #include #include +#include +#include #include "awa/static.h" #include "lwm2m_security_object.h" @@ -99,6 +101,11 @@ AwaError AwaStaticClient_Init(AwaStaticClient * client) { if (client->CoAPConfigured && client->BootstrapConfigured && client->EndpointNameConfigured) { + if (client->CoAPListenPort == 0) + { + srand(time(NULL)); + client->CoAPListenPort = 6000 + (rand() % 32768); + } client->CoAPInfo = coap_Init(client->CoAPListenAddress, client->CoAPListenPort, false, Lwm2m_GetLogLevel()); if (client->CoAPInfo != NULL) diff --git a/daemon/src/bootstrap/awa_bootstrapd_cmdline.c b/daemon/src/bootstrap/awa_bootstrapd_cmdline.c index d70a0fc..1323c7c 100644 --- a/daemon/src/bootstrap/awa_bootstrapd_cmdline.c +++ b/daemon/src/bootstrap/awa_bootstrapd_cmdline.c @@ -107,7 +107,7 @@ void clear_args (struct gengetopt_args_info *args_info) args_info->logFile_arg = NULL; args_info->logFile_orig = NULL; args_info->version_flag = 0; - + } static @@ -128,7 +128,7 @@ void init_args_info(struct gengetopt_args_info *args_info) args_info->verbose_help = gengetopt_args_info_help[8] ; args_info->logFile_help = gengetopt_args_info_help[9] ; args_info->version_help = gengetopt_args_info_help[10] ; - + } void @@ -181,7 +181,7 @@ void cmdline_parser_params_init(struct cmdline_parser_params *params) { if (params) - { + { params->override = 0; params->initialize = 1; params->check_required = 1; @@ -193,9 +193,9 @@ cmdline_parser_params_init(struct cmdline_parser_params *params) struct cmdline_parser_params * cmdline_parser_params_create(void) { - struct cmdline_parser_params *params = + struct cmdline_parser_params *params = (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); - cmdline_parser_params_init(params); + cmdline_parser_params_init(params); return params; } @@ -225,7 +225,7 @@ struct generic_list }; /** - * @brief add a node at the head of the list + * @brief add a node at the head of the list */ static void add_node(struct generic_list **list) { struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list)); @@ -268,8 +268,8 @@ cmdline_parser_release (struct gengetopt_args_info *args_info) free_multiple_string_field (args_info->config_given, &(args_info->config_arg), &(args_info->config_orig)); free_string_field (&(args_info->logFile_arg)); free_string_field (&(args_info->logFile_orig)); - - + + for (i = 0; i < args_info->inputs_num; ++i) free (args_info->inputs [i]); @@ -321,7 +321,7 @@ write_into_file(FILE *outfile, const char *opt, const char *arg, const char *val int found = -1; if (arg) { if (values) { - found = check_possible_values(arg, values); + found = check_possible_values(arg, values); } if (found >= 0) fprintf(outfile, "%s=\"%s\" # %s\n", opt, arg, values[found]); @@ -336,7 +336,7 @@ static void write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[]) { int i; - + for (i = 0; i < len; ++i) write_into_file(outfile, opt, (arg ? arg[i] : 0), values); } @@ -373,7 +373,7 @@ cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) write_into_file(outfile, "logFile", args_info->logFile_orig, 0); if (args_info->version_given) write_into_file(outfile, "version", 0, 0 ); - + i = EXIT_SUCCESS; return i; @@ -413,9 +413,9 @@ gengetopt_strdup (const char *s) if (!s) return result; - result = (char *)malloc(strlen(s) + 1); - if (result == (char *)0) - return (char *)0; + result = (char*)malloc(strlen(s) + 1); + if (result == (char*)0) + return (char*)0; strcpy(result, s); return result; } @@ -459,8 +459,8 @@ get_multiple_arg_token(const char *arg) j = 0; while (arg[i] && (j < len-1)) { - if (arg[i] == '\\' && - arg[ i + 1 ] && + if (arg[i] == '\\' && + arg[ i + 1 ] && arg[ i + 1 ] == ',') ++i; @@ -552,7 +552,7 @@ check_multiple_option_occurrences(const char *prog_name, unsigned int option_giv } } } - + return error_occurred; } int @@ -573,7 +573,7 @@ cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info cmdline_parser_free (args_info); exit (EXIT_FAILURE); } - + return result; } @@ -582,7 +582,7 @@ cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, i { int result; struct cmdline_parser_params params; - + params.override = override; params.initialize = initialize; params.check_required = check_required; @@ -596,7 +596,7 @@ cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, i cmdline_parser_free (args_info); exit (EXIT_FAILURE); } - + return result; } @@ -613,7 +613,7 @@ cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog cmdline_parser_free (args_info); exit (EXIT_FAILURE); } - + return result; } @@ -626,8 +626,8 @@ cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *pro /* checks for required options */ if (check_multiple_option_occurrences(prog_name, args_info->config_given, args_info->config_min, args_info->config_max, "'--config' ('-c')")) error_occurred = 1; - - + + /* checks for dependences among options */ return error_occurred; @@ -646,7 +646,7 @@ cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *pro * */ -/* +/* * we must include anything we need since this file is not thought to be * inserted in a file already using getopt.h * @@ -1181,7 +1181,7 @@ static int getopt_internal_r(int argc, char *const *argv, const char *optstring, return -1; d->custom_optarg = NULL; - /* + /* * This is a big difference with GNU getopt, since optind == 0 * means initialization while here 1 means first call. */ @@ -1248,7 +1248,7 @@ static char *package_name = 0; */ static int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, + unsigned int *field_given, unsigned int *prev_given, char *value, const char *possible_values[], const char *default_value, cmdline_parser_arg_type arg_type, @@ -1269,11 +1269,11 @@ int update_arg(void *field, char **orig_field, if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) { if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", + fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", package_name, long_opt, short_opt, (additional_error ? additional_error : "")); else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", + fprintf (stderr, "%s: `--%s' option given more than once%s\n", package_name, long_opt, (additional_error ? additional_error : "")); return 1; /* failure */ @@ -1282,16 +1282,16 @@ int update_arg(void *field, char **orig_field, if (possible_values && (found = check_possible_values((value ? value : default_value), possible_values)) < 0) { if (short_opt != '-') - fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n", + fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n", package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt, short_opt, (additional_error ? additional_error : "")); else - fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s'%s\n", + fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s'%s\n", package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt, (additional_error ? additional_error : "")); return 1; /* failure */ } - + if (field_given && *field_given && ! override) return 0; if (prev_given) @@ -1318,7 +1318,7 @@ int update_arg(void *field, char **orig_field, break; default: break; - } + }; /* check numeric conversion */ switch(arg_type) { @@ -1330,7 +1330,7 @@ int update_arg(void *field, char **orig_field, break; default: ; - } + }; /* store the original value */ switch(arg_type) { @@ -1342,11 +1342,12 @@ int update_arg(void *field, char **orig_field, if (no_free) { *orig_field = value; } else { - free(*orig_field); /* free previous string */ + if (*orig_field) + free (*orig_field); /* free previous string */ *orig_field = gengetopt_strdup (value); } } - } + }; return 0; /* OK */ } @@ -1379,9 +1380,9 @@ int update_multiple_arg_temp(struct generic_list **list, { add_node (list); if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0, - prev_given, multi_token, possible_values, default_value, - arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) { - free(multi_token); + prev_given, multi_token, possible_values, default_value, + arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) { + if (multi_token) free(multi_token); return 1; /* failure */ } @@ -1410,7 +1411,8 @@ void free_list(struct generic_list *list, short string_arg) tmp = list; if (string_arg && list->arg.string_arg) free (list->arg.string_arg); - free(list->orig); + if (list->orig) + free (list->orig); list = list->next; free (tmp); } @@ -1434,19 +1436,17 @@ void update_multiple_arg(void *field, char ***orig_field, switch(arg_type) { case ARG_INT: - *((int **)field) = (int *)realloc (*((int **)field), - (field_given + prev_given) * sizeof (int)); break; + *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break; case ARG_STRING: - *((char ***)field) = (char **)realloc (*((char ***)field), - (field_given + prev_given) * sizeof (char *)); break; + *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break; default: break; - } - + }; + for (i = (prev_given - 1); i >= 0; --i) { tmp = list; - + switch(arg_type) { case ARG_INT: (*((int **)field))[i + field_given] = tmp->arg.int_arg; break; @@ -1454,7 +1454,7 @@ void update_multiple_arg(void *field, char ***orig_field, (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break; default: break; - } + } (*orig_field) [i + field_given] = list->orig; list = list->next; free (tmp); @@ -1465,7 +1465,7 @@ void update_multiple_arg(void *field, char ***orig_field, case ARG_INT: if (! *((int **)field)) { *((int **)field) = (int *)malloc (sizeof (int)); - (*((int **)field))[0] = default_value->int_arg; + (*((int **)field))[0] = default_value->int_arg; } break; case ARG_STRING: @@ -1494,7 +1494,7 @@ cmdline_parser_internal ( struct generic_list * config_list = NULL; int error_occurred = 0; struct gengetopt_args_info local_args_info; - + int override; int initialize; int check_required; @@ -1504,9 +1504,9 @@ cmdline_parser_internal ( int optind; int opterr; int optopt; - + package_name = argv[0]; - + override = params->override; initialize = params->initialize; check_required = params->check_required; @@ -1563,113 +1563,113 @@ cmdline_parser_internal ( exit (EXIT_SUCCESS); case 'a': /* Accept client bootstrap requests on IP address ADDR. */ - - - if (update_arg( (void *)&(args_info->ip_arg), - &(args_info->ip_orig), &(args_info->ip_given), - &(local_args_info.ip_given), optarg, 0, "0.0.0.0", ARG_STRING, - check_ambiguity, override, 0, 0, - "ip", 'a', - additional_error)) + + + if (update_arg( (void *)&(args_info->ip_arg), + &(args_info->ip_orig), &(args_info->ip_given), + &(local_args_info.ip_given), optarg, 0, "0.0.0.0", ARG_STRING, + check_ambiguity, override, 0, 0, + "ip", 'a', + additional_error)) goto failure; - + break; case 'e': /* Accept client bootstrap requests on network interface IF. */ - - - if (update_arg( (void *)&(args_info->interface_arg), - &(args_info->interface_orig), &(args_info->interface_given), - &(local_args_info.interface_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "interface", 'e', - additional_error)) + + + if (update_arg( (void *)&(args_info->interface_arg), + &(args_info->interface_orig), &(args_info->interface_given), + &(local_args_info.interface_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "interface", 'e', + additional_error)) goto failure; - + break; case 'f': /* Address family for network interface. AF=4 for IPv4, AF=6 for IPv6. */ - - - if (update_arg( (void *)&(args_info->addressFamily_arg), - &(args_info->addressFamily_orig), &(args_info->addressFamily_given), - &(local_args_info.addressFamily_given), optarg, cmdline_parser_addressFamily_values, "4", ARG_INT, - check_ambiguity, override, 0, 0, - "addressFamily", 'f', - additional_error)) + + + if (update_arg( (void *)&(args_info->addressFamily_arg), + &(args_info->addressFamily_orig), &(args_info->addressFamily_given), + &(local_args_info.addressFamily_given), optarg, cmdline_parser_addressFamily_values, "4", ARG_INT, + check_ambiguity, override, 0, 0, + "addressFamily", 'f', + additional_error)) goto failure; - + break; case 'p': /* Use port number PORT for CoAP communications. */ - - - if (update_arg( (void *)&(args_info->port_arg), - &(args_info->port_orig), &(args_info->port_given), - &(local_args_info.port_given), optarg, 0, "15685", ARG_INT, - check_ambiguity, override, 0, 0, - "port", 'p', - additional_error)) + + + if (update_arg( (void *)&(args_info->port_arg), + &(args_info->port_orig), &(args_info->port_given), + &(local_args_info.port_given), optarg, 0, "15685", ARG_INT, + check_ambiguity, override, 0, 0, + "port", 'p', + additional_error)) goto failure; - + break; case 'c': /* Load server list configuration from FILE. */ - - if (update_multiple_arg_temp(&config_list, + + if (update_multiple_arg_temp(&config_list, &(local_args_info.config_given), optarg, 0, 0, ARG_STRING, "config", 'c', additional_error)) goto failure; - + break; case 's': /* CoAP communications are secured with DTLS. */ - - + + if (update_arg((void *)&(args_info->secure_flag), 0, &(args_info->secure_given), - &(local_args_info.secure_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "secure", 's', - additional_error)) + &(local_args_info.secure_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "secure", 's', + additional_error)) goto failure; - + break; case 'd': /* Detach process from terminal and run in the background. */ - - + + if (update_arg((void *)&(args_info->daemonize_flag), 0, &(args_info->daemonize_given), - &(local_args_info.daemonize_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "daemonize", 'd', - additional_error)) + &(local_args_info.daemonize_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "daemonize", 'd', + additional_error)) goto failure; - + break; case 'v': /* Generate verbose output. */ - - + + if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given), - &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verbose", 'v', - additional_error)) + &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "verbose", 'v', + additional_error)) goto failure; - + break; case 'l': /* Log output to FILE. */ - - - if (update_arg( (void *)&(args_info->logFile_arg), - &(args_info->logFile_orig), &(args_info->logFile_given), - &(local_args_info.logFile_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "logFile", 'l', - additional_error)) + + + if (update_arg( (void *)&(args_info->logFile_arg), + &(args_info->logFile_orig), &(args_info->logFile_given), + &(local_args_info.logFile_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "logFile", 'l', + additional_error)) goto failure; - + break; case 'V': /* Print version and exit. */ - - + + if (update_arg((void *)&(args_info->version_flag), 0, &(args_info->version_given), - &(local_args_info.version_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "version", 'V', - additional_error)) + &(local_args_info.version_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "version", 'V', + additional_error)) goto failure; - + break; case 0: /* Long option with no short option */ @@ -1685,13 +1685,13 @@ cmdline_parser_internal ( update_multiple_arg((void *)&(args_info->config_arg), - &(args_info->config_orig), args_info->config_given, - local_args_info.config_given, 0, - ARG_STRING, config_list); + &(args_info->config_orig), args_info->config_given, + local_args_info.config_given, 0, + ARG_STRING, config_list); args_info->config_given += local_args_info.config_given; local_args_info.config_given = 0; - + if (check_required) { error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error); @@ -1722,7 +1722,7 @@ cmdline_parser_internal ( failure: free_list (config_list, 1 ); - + cmdline_parser_release (&local_args_info); return (EXIT_FAILURE); } diff --git a/daemon/src/bootstrap/awa_bootstrapd_cmdline.h b/daemon/src/bootstrap/awa_bootstrapd_cmdline.h index e962130..e854e0f 100644 --- a/daemon/src/bootstrap/awa_bootstrapd_cmdline.h +++ b/daemon/src/bootstrap/awa_bootstrapd_cmdline.h @@ -66,7 +66,7 @@ struct gengetopt_args_info const char *logFile_help; /**< @brief Log output to FILE help description. */ int version_flag; /**< @brief Print version and exit (default=off). */ const char *version_help; /**< @brief Print version and exit help description. */ - + unsigned int help_given ; /**< @brief Whether help was given. */ unsigned int ip_given ; /**< @brief Whether ip was given. */ unsigned int interface_given ; /**< @brief Whether interface was given. */ @@ -168,7 +168,7 @@ void cmdline_parser_print_help(void); void cmdline_parser_print_version(void); /** - * Initializes all the fields a cmdline_parser_params structure + * Initializes all the fields a cmdline_parser_params structure * to their default values * @param params the structure to initialize */ diff --git a/daemon/src/client/awa_clientd.ggo b/daemon/src/client/awa_clientd.ggo index 8ce4d9a..7764375 100644 --- a/daemon/src/client/awa_clientd.ggo +++ b/daemon/src/client/awa_clientd.ggo @@ -5,7 +5,7 @@ versiontext "Copyright (c) 2016 Imagination Technologies Limited and/or its affi args "--no-version" # Options -option "port" p "Use local port number PORT for CoAP communications" int optional default="6000" typestr="PORT" +option "port" p "Use local port number PORT for CoAP communications - zero will select random port" int optional default="0" typestr="PORT" option "addressFamily" a "Address family for network interface. AF=4 for IPv4, AF=6 for IPv6" int optional default="4" typestr="AF" values="4","6" option "ipcPort" i "Use port number PORT for IPC communications" int optional default="12345" typestr="PORT" @@ -13,12 +13,12 @@ option "endPointName" e "Use NAME as client end point name" option "bootstrap" b "Use bootstrap server URI" string optional typestr="URI" option "factoryBootstrap" f "Load factory bootstrap information from FILE" string optional typestr="FILE" option "secure" s "CoAP communications are secured with DTLS" flag off -option "pskIdentity" - "Default Identity of associated pre-shared key for DTLS" +option "pskIdentity" - "Default Identity of associated pre-shared key for DTLS" string optional typestr="IDENTITY" option "pskKey" - "Default pre-shared key for DTLS as a hex string" string optional typestr="KEY" option "certificate" c "Load client certificate from FILE" string optional typestr="FILE" -option "defaultContentType" t "Default content type to use when a request doesn't specify one (TLV=1542, JSON=50)" +option "defaultContentType" t "Default content type to use when a request doesn't specify one (TLV=1542, JSON=50)" int optional default="0" typestr="CONTENTTYPE" @@ -31,10 +31,10 @@ option "version" V "Print version and exit" text "\n" text "Example:\n" -text " awa_clientd --port 6000 --endPointName client1 --bootstrap coap://[::1]:2134\n" +text " awa_clientd --endPointName client1 --bootstrap coap://[::1]:2134\n" text "\n" text "PSK Example:\n" text "\n" -text " awa_clientd --port 6000 --endPointName client1 --bootstrap coaps://0.0.0.0:2134 --pskIdentity=myPskIdentity --pskKey=2646188672F6CCD4AAEA476C645F2565B83E15BF00D135A3A6944DF72218759F\n" +text " awa_clientd --endPointName client1 --bootstrap coaps://0.0.0.0:2134 --pskIdentity=myPskIdentity --pskKey=2646188672F6CCD4AAEA476C645F2565B83E15BF00D135A3A6944DF72218759F\n" text "\n" diff --git a/daemon/src/client/awa_clientd_cmdline.c b/daemon/src/client/awa_clientd_cmdline.c index 857933a..542eabb 100644 --- a/daemon/src/client/awa_clientd_cmdline.c +++ b/daemon/src/client/awa_clientd_cmdline.c @@ -34,7 +34,7 @@ const char *gengetopt_args_info_description = ""; const char *gengetopt_args_info_help[] = { " -h, --help Print help and exit", - " -p, --port=PORT Use local port number PORT for CoAP\n communications (default=`6000')", + " -p, --port=PORT Use local port number PORT for CoAP\n communications - zero will select random port\n (default=`0')", " -a, --addressFamily=AF Address family for network interface. AF=4 for\n IPv4, AF=6 for IPv6 (possible values=\"4\",\n \"6\" default=`4')", " -i, --ipcPort=PORT Use port number PORT for IPC communications\n (default=`12345')", " -e, --endPointName=NAME Use NAME as client end point name\n (default=`Awa Client')", @@ -50,7 +50,7 @@ const char *gengetopt_args_info_help[] = { " -v, --verbose Generate verbose output (default=off)", " -l, --logFile=FILE Log output to FILE", " -V, --version Print version and exit (default=off)", - "\nExample:\n awa_clientd --port 6000 --endPointName client1 --bootstrap\ncoap://[::1]:2134\n\nPSK Example:\n\n awa_clientd --port 6000 --endPointName client1 --bootstrap\ncoaps://0.0.0.0:2134 --pskIdentity=myPskIdentity\n--pskKey=2646188672F6CCD4AAEA476C645F2565B83E15BF00D135A3A6944DF72218759F\n\n", + "\nExample:\n awa_clientd --endPointName client1 --bootstrap coap://[::1]:2134\n\nPSK Example:\n\n awa_clientd --endPointName client1 --bootstrap coaps://0.0.0.0:2134\n--pskIdentity=myPskIdentity\n--pskKey=2646188672F6CCD4AAEA476C645F2565B83E15BF00D135A3A6944DF72218759F\n\n", 0 }; @@ -103,7 +103,7 @@ static void clear_args (struct gengetopt_args_info *args_info) { FIX_UNUSED (args_info); - args_info->port_arg = 6000; + args_info->port_arg = 0; args_info->port_orig = NULL; args_info->addressFamily_arg = 4; args_info->addressFamily_orig = NULL; @@ -131,7 +131,7 @@ void clear_args (struct gengetopt_args_info *args_info) args_info->logFile_arg = NULL; args_info->logFile_orig = NULL; args_info->version_flag = 0; - + } static @@ -158,7 +158,7 @@ void init_args_info(struct gengetopt_args_info *args_info) args_info->verbose_help = gengetopt_args_info_help[14] ; args_info->logFile_help = gengetopt_args_info_help[15] ; args_info->version_help = gengetopt_args_info_help[16] ; - + } void @@ -211,7 +211,7 @@ void cmdline_parser_params_init(struct cmdline_parser_params *params) { if (params) - { + { params->override = 0; params->initialize = 1; params->check_required = 1; @@ -223,9 +223,9 @@ cmdline_parser_params_init(struct cmdline_parser_params *params) struct cmdline_parser_params * cmdline_parser_params_create(void) { - struct cmdline_parser_params *params = + struct cmdline_parser_params *params = (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); - cmdline_parser_params_init(params); + cmdline_parser_params_init(params); return params; } @@ -255,7 +255,7 @@ struct generic_list }; /** - * @brief add a node at the head of the list + * @brief add a node at the head of the list */ static void add_node(struct generic_list **list) { struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list)); @@ -308,8 +308,8 @@ cmdline_parser_release (struct gengetopt_args_info *args_info) free_multiple_string_field (args_info->objDefs_given, &(args_info->objDefs_arg), &(args_info->objDefs_orig)); free_string_field (&(args_info->logFile_arg)); free_string_field (&(args_info->logFile_orig)); - - + + for (i = 0; i < args_info->inputs_num; ++i) free (args_info->inputs [i]); @@ -361,7 +361,7 @@ write_into_file(FILE *outfile, const char *opt, const char *arg, const char *val int found = -1; if (arg) { if (values) { - found = check_possible_values(arg, values); + found = check_possible_values(arg, values); } if (found >= 0) fprintf(outfile, "%s=\"%s\" # %s\n", opt, arg, values[found]); @@ -376,7 +376,7 @@ static void write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[]) { int i; - + for (i = 0; i < len; ++i) write_into_file(outfile, opt, (arg ? arg[i] : 0), values); } @@ -425,7 +425,7 @@ cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) write_into_file(outfile, "logFile", args_info->logFile_orig, 0); if (args_info->version_given) write_into_file(outfile, "version", 0, 0 ); - + i = EXIT_SUCCESS; return i; @@ -465,9 +465,9 @@ gengetopt_strdup (const char *s) if (!s) return result; - result = (char *)malloc(strlen(s) + 1); - if (result == (char *)0) - return (char *)0; + result = (char*)malloc(strlen(s) + 1); + if (result == (char*)0) + return (char*)0; strcpy(result, s); return result; } @@ -511,8 +511,8 @@ get_multiple_arg_token(const char *arg) j = 0; while (arg[i] && (j < len-1)) { - if (arg[i] == '\\' && - arg[ i + 1 ] && + if (arg[i] == '\\' && + arg[ i + 1 ] && arg[ i + 1 ] == ',') ++i; @@ -604,7 +604,7 @@ check_multiple_option_occurrences(const char *prog_name, unsigned int option_giv } } } - + return error_occurred; } int @@ -625,7 +625,7 @@ cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info cmdline_parser_free (args_info); exit (EXIT_FAILURE); } - + return result; } @@ -634,7 +634,7 @@ cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, i { int result; struct cmdline_parser_params params; - + params.override = override; params.initialize = initialize; params.check_required = check_required; @@ -648,7 +648,7 @@ cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, i cmdline_parser_free (args_info); exit (EXIT_FAILURE); } - + return result; } @@ -665,7 +665,7 @@ cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog cmdline_parser_free (args_info); exit (EXIT_FAILURE); } - + return result; } @@ -678,8 +678,8 @@ cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *pro /* checks for required options */ if (check_multiple_option_occurrences(prog_name, args_info->objDefs_given, args_info->objDefs_min, args_info->objDefs_max, "'--objDefs' ('-o')")) error_occurred = 1; - - + + /* checks for dependences among options */ return error_occurred; @@ -698,7 +698,7 @@ cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *pro * */ -/* +/* * we must include anything we need since this file is not thought to be * inserted in a file already using getopt.h * @@ -1233,7 +1233,7 @@ static int getopt_internal_r(int argc, char *const *argv, const char *optstring, return -1; d->custom_optarg = NULL; - /* + /* * This is a big difference with GNU getopt, since optind == 0 * means initialization while here 1 means first call. */ @@ -1300,7 +1300,7 @@ static char *package_name = 0; */ static int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, + unsigned int *field_given, unsigned int *prev_given, char *value, const char *possible_values[], const char *default_value, cmdline_parser_arg_type arg_type, @@ -1321,11 +1321,11 @@ int update_arg(void *field, char **orig_field, if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) { if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", + fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", package_name, long_opt, short_opt, (additional_error ? additional_error : "")); else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", + fprintf (stderr, "%s: `--%s' option given more than once%s\n", package_name, long_opt, (additional_error ? additional_error : "")); return 1; /* failure */ @@ -1334,16 +1334,16 @@ int update_arg(void *field, char **orig_field, if (possible_values && (found = check_possible_values((value ? value : default_value), possible_values)) < 0) { if (short_opt != '-') - fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n", + fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n", package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt, short_opt, (additional_error ? additional_error : "")); else - fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s'%s\n", + fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s'%s\n", package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt, (additional_error ? additional_error : "")); return 1; /* failure */ } - + if (field_given && *field_given && ! override) return 0; if (prev_given) @@ -1370,7 +1370,7 @@ int update_arg(void *field, char **orig_field, break; default: break; - } + }; /* check numeric conversion */ switch(arg_type) { @@ -1382,7 +1382,7 @@ int update_arg(void *field, char **orig_field, break; default: ; - } + }; /* store the original value */ switch(arg_type) { @@ -1394,11 +1394,12 @@ int update_arg(void *field, char **orig_field, if (no_free) { *orig_field = value; } else { - free(*orig_field); /* free previous string */ + if (*orig_field) + free (*orig_field); /* free previous string */ *orig_field = gengetopt_strdup (value); } } - } + }; return 0; /* OK */ } @@ -1431,9 +1432,9 @@ int update_multiple_arg_temp(struct generic_list **list, { add_node (list); if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0, - prev_given, multi_token, possible_values, default_value, - arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) { - free(multi_token); + prev_given, multi_token, possible_values, default_value, + arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) { + if (multi_token) free(multi_token); return 1; /* failure */ } @@ -1462,7 +1463,8 @@ void free_list(struct generic_list *list, short string_arg) tmp = list; if (string_arg && list->arg.string_arg) free (list->arg.string_arg); - free(list->orig); + if (list->orig) + free (list->orig); list = list->next; free (tmp); } @@ -1486,19 +1488,17 @@ void update_multiple_arg(void *field, char ***orig_field, switch(arg_type) { case ARG_INT: - *((int **)field) = (int *)realloc (*((int **)field), - (field_given + prev_given) * sizeof (int)); break; + *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break; case ARG_STRING: - *((char ***)field) = (char **)realloc (*((char ***)field), - (field_given + prev_given) * sizeof (char *)); break; + *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break; default: break; - } - + }; + for (i = (prev_given - 1); i >= 0; --i) { tmp = list; - + switch(arg_type) { case ARG_INT: (*((int **)field))[i + field_given] = tmp->arg.int_arg; break; @@ -1506,7 +1506,7 @@ void update_multiple_arg(void *field, char ***orig_field, (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break; default: break; - } + } (*orig_field) [i + field_given] = list->orig; list = list->next; free (tmp); @@ -1517,7 +1517,7 @@ void update_multiple_arg(void *field, char ***orig_field, case ARG_INT: if (! *((int **)field)) { *((int **)field) = (int *)malloc (sizeof (int)); - (*((int **)field))[0] = default_value->int_arg; + (*((int **)field))[0] = default_value->int_arg; } break; case ARG_STRING: @@ -1546,7 +1546,7 @@ cmdline_parser_internal ( struct generic_list * objDefs_list = NULL; int error_occurred = 0; struct gengetopt_args_info local_args_info; - + int override; int initialize; int check_required; @@ -1556,9 +1556,9 @@ cmdline_parser_internal ( int optind; int opterr; int optopt; - + package_name = argv[0]; - + override = params->override; initialize = params->initialize; check_required = params->check_required; @@ -1620,194 +1620,194 @@ cmdline_parser_internal ( cmdline_parser_free (&local_args_info); exit (EXIT_SUCCESS); - case 'p': /* Use local port number PORT for CoAP communications. */ - - - if (update_arg( (void *)&(args_info->port_arg), - &(args_info->port_orig), &(args_info->port_given), - &(local_args_info.port_given), optarg, 0, "6000", ARG_INT, - check_ambiguity, override, 0, 0, - "port", 'p', - additional_error)) + case 'p': /* Use local port number PORT for CoAP communications - zero will select random port. */ + + + if (update_arg( (void *)&(args_info->port_arg), + &(args_info->port_orig), &(args_info->port_given), + &(local_args_info.port_given), optarg, 0, "0", ARG_INT, + check_ambiguity, override, 0, 0, + "port", 'p', + additional_error)) goto failure; - + break; case 'a': /* Address family for network interface. AF=4 for IPv4, AF=6 for IPv6. */ - - - if (update_arg( (void *)&(args_info->addressFamily_arg), - &(args_info->addressFamily_orig), &(args_info->addressFamily_given), - &(local_args_info.addressFamily_given), optarg, cmdline_parser_addressFamily_values, "4", ARG_INT, - check_ambiguity, override, 0, 0, - "addressFamily", 'a', - additional_error)) + + + if (update_arg( (void *)&(args_info->addressFamily_arg), + &(args_info->addressFamily_orig), &(args_info->addressFamily_given), + &(local_args_info.addressFamily_given), optarg, cmdline_parser_addressFamily_values, "4", ARG_INT, + check_ambiguity, override, 0, 0, + "addressFamily", 'a', + additional_error)) goto failure; - + break; case 'i': /* Use port number PORT for IPC communications. */ - - - if (update_arg( (void *)&(args_info->ipcPort_arg), - &(args_info->ipcPort_orig), &(args_info->ipcPort_given), - &(local_args_info.ipcPort_given), optarg, 0, "12345", ARG_INT, - check_ambiguity, override, 0, 0, - "ipcPort", 'i', - additional_error)) + + + if (update_arg( (void *)&(args_info->ipcPort_arg), + &(args_info->ipcPort_orig), &(args_info->ipcPort_given), + &(local_args_info.ipcPort_given), optarg, 0, "12345", ARG_INT, + check_ambiguity, override, 0, 0, + "ipcPort", 'i', + additional_error)) goto failure; - + break; case 'e': /* Use NAME as client end point name. */ - - - if (update_arg( (void *)&(args_info->endPointName_arg), - &(args_info->endPointName_orig), &(args_info->endPointName_given), - &(local_args_info.endPointName_given), optarg, 0, "Awa Client", ARG_STRING, - check_ambiguity, override, 0, 0, - "endPointName", 'e', - additional_error)) + + + if (update_arg( (void *)&(args_info->endPointName_arg), + &(args_info->endPointName_orig), &(args_info->endPointName_given), + &(local_args_info.endPointName_given), optarg, 0, "Awa Client", ARG_STRING, + check_ambiguity, override, 0, 0, + "endPointName", 'e', + additional_error)) goto failure; - + break; case 'b': /* Use bootstrap server URI. */ - - - if (update_arg( (void *)&(args_info->bootstrap_arg), - &(args_info->bootstrap_orig), &(args_info->bootstrap_given), - &(local_args_info.bootstrap_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "bootstrap", 'b', - additional_error)) + + + if (update_arg( (void *)&(args_info->bootstrap_arg), + &(args_info->bootstrap_orig), &(args_info->bootstrap_given), + &(local_args_info.bootstrap_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "bootstrap", 'b', + additional_error)) goto failure; - + break; case 'f': /* Load factory bootstrap information from FILE. */ - - - if (update_arg( (void *)&(args_info->factoryBootstrap_arg), - &(args_info->factoryBootstrap_orig), &(args_info->factoryBootstrap_given), - &(local_args_info.factoryBootstrap_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "factoryBootstrap", 'f', - additional_error)) + + + if (update_arg( (void *)&(args_info->factoryBootstrap_arg), + &(args_info->factoryBootstrap_orig), &(args_info->factoryBootstrap_given), + &(local_args_info.factoryBootstrap_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "factoryBootstrap", 'f', + additional_error)) goto failure; - + break; case 's': /* CoAP communications are secured with DTLS. */ - - + + if (update_arg((void *)&(args_info->secure_flag), 0, &(args_info->secure_given), - &(local_args_info.secure_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "secure", 's', - additional_error)) + &(local_args_info.secure_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "secure", 's', + additional_error)) goto failure; - + break; case 'c': /* Load client certificate from FILE. */ - - - if (update_arg( (void *)&(args_info->certificate_arg), - &(args_info->certificate_orig), &(args_info->certificate_given), - &(local_args_info.certificate_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "certificate", 'c', - additional_error)) + + + if (update_arg( (void *)&(args_info->certificate_arg), + &(args_info->certificate_orig), &(args_info->certificate_given), + &(local_args_info.certificate_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "certificate", 'c', + additional_error)) goto failure; - + break; case 't': /* Default content type to use when a request doesn't specify one (TLV=1542, JSON=50). */ - - - if (update_arg( (void *)&(args_info->defaultContentType_arg), - &(args_info->defaultContentType_orig), &(args_info->defaultContentType_given), - &(local_args_info.defaultContentType_given), optarg, 0, "0", ARG_INT, - check_ambiguity, override, 0, 0, - "defaultContentType", 't', - additional_error)) + + + if (update_arg( (void *)&(args_info->defaultContentType_arg), + &(args_info->defaultContentType_orig), &(args_info->defaultContentType_given), + &(local_args_info.defaultContentType_given), optarg, 0, "0", ARG_INT, + check_ambiguity, override, 0, 0, + "defaultContentType", 't', + additional_error)) goto failure; - + break; case 'o': /* Load object and resource definitions from FILE. */ - - if (update_multiple_arg_temp(&objDefs_list, + + if (update_multiple_arg_temp(&objDefs_list, &(local_args_info.objDefs_given), optarg, 0, 0, ARG_STRING, "objDefs", 'o', additional_error)) goto failure; - + break; case 'd': /* Detach process from terminal and run in the background. */ - - + + if (update_arg((void *)&(args_info->daemonize_flag), 0, &(args_info->daemonize_given), - &(local_args_info.daemonize_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "daemonize", 'd', - additional_error)) + &(local_args_info.daemonize_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "daemonize", 'd', + additional_error)) goto failure; - + break; case 'v': /* Generate verbose output. */ - - + + if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given), - &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verbose", 'v', - additional_error)) + &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "verbose", 'v', + additional_error)) goto failure; - + break; case 'l': /* Log output to FILE. */ - - - if (update_arg( (void *)&(args_info->logFile_arg), - &(args_info->logFile_orig), &(args_info->logFile_given), - &(local_args_info.logFile_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "logFile", 'l', - additional_error)) + + + if (update_arg( (void *)&(args_info->logFile_arg), + &(args_info->logFile_orig), &(args_info->logFile_given), + &(local_args_info.logFile_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "logFile", 'l', + additional_error)) goto failure; - + break; case 'V': /* Print version and exit. */ - - + + if (update_arg((void *)&(args_info->version_flag), 0, &(args_info->version_given), - &(local_args_info.version_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "version", 'V', - additional_error)) + &(local_args_info.version_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "version", 'V', + additional_error)) goto failure; - + break; case 0: /* Long option with no short option */ /* Default Identity of associated pre-shared key for DTLS. */ if (strcmp (long_options[option_index].name, "pskIdentity") == 0) { - - - if (update_arg( (void *)&(args_info->pskIdentity_arg), - &(args_info->pskIdentity_orig), &(args_info->pskIdentity_given), - &(local_args_info.pskIdentity_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "pskIdentity", '-', - additional_error)) + + + if (update_arg( (void *)&(args_info->pskIdentity_arg), + &(args_info->pskIdentity_orig), &(args_info->pskIdentity_given), + &(local_args_info.pskIdentity_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "pskIdentity", '-', + additional_error)) goto failure; - + } /* Default pre-shared key for DTLS as a hex string. */ else if (strcmp (long_options[option_index].name, "pskKey") == 0) { - - - if (update_arg( (void *)&(args_info->pskKey_arg), - &(args_info->pskKey_orig), &(args_info->pskKey_given), - &(local_args_info.pskKey_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "pskKey", '-', - additional_error)) + + + if (update_arg( (void *)&(args_info->pskKey_arg), + &(args_info->pskKey_orig), &(args_info->pskKey_given), + &(local_args_info.pskKey_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "pskKey", '-', + additional_error)) goto failure; - + } - + break; case '?': /* Invalid option. */ /* `getopt_long' already printed an error message. */ @@ -1821,13 +1821,13 @@ cmdline_parser_internal ( update_multiple_arg((void *)&(args_info->objDefs_arg), - &(args_info->objDefs_orig), args_info->objDefs_given, - local_args_info.objDefs_given, 0, - ARG_STRING, objDefs_list); + &(args_info->objDefs_orig), args_info->objDefs_given, + local_args_info.objDefs_given, 0, + ARG_STRING, objDefs_list); args_info->objDefs_given += local_args_info.objDefs_given; local_args_info.objDefs_given = 0; - + if (check_required) { error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error); @@ -1858,7 +1858,7 @@ cmdline_parser_internal ( failure: free_list (objDefs_list, 1 ); - + cmdline_parser_release (&local_args_info); return (EXIT_FAILURE); } diff --git a/daemon/src/client/awa_clientd_cmdline.h b/daemon/src/client/awa_clientd_cmdline.h index 2d346cf..4724f7b 100644 --- a/daemon/src/client/awa_clientd_cmdline.h +++ b/daemon/src/client/awa_clientd_cmdline.h @@ -38,9 +38,9 @@ extern "C" { struct gengetopt_args_info { const char *help_help; /**< @brief Print help and exit help description. */ - int port_arg; /**< @brief Use local port number PORT for CoAP communications (default='6000'). */ - char * port_orig; /**< @brief Use local port number PORT for CoAP communications original value given at command line. */ - const char *port_help; /**< @brief Use local port number PORT for CoAP communications help description. */ + int port_arg; /**< @brief Use local port number PORT for CoAP communications - zero will select random port (default='0'). */ + char * port_orig; /**< @brief Use local port number PORT for CoAP communications - zero will select random port original value given at command line. */ + const char *port_help; /**< @brief Use local port number PORT for CoAP communications - zero will select random port help description. */ int addressFamily_arg; /**< @brief Address family for network interface. AF=4 for IPv4, AF=6 for IPv6 (default='4'). */ char * addressFamily_orig; /**< @brief Address family for network interface. AF=4 for IPv4, AF=6 for IPv6 original value given at command line. */ const char *addressFamily_help; /**< @brief Address family for network interface. AF=4 for IPv4, AF=6 for IPv6 help description. */ @@ -84,7 +84,7 @@ struct gengetopt_args_info const char *logFile_help; /**< @brief Log output to FILE help description. */ int version_flag; /**< @brief Print version and exit (default=off). */ const char *version_help; /**< @brief Print version and exit help description. */ - + unsigned int help_given ; /**< @brief Whether help was given. */ unsigned int port_given ; /**< @brief Whether port was given. */ unsigned int addressFamily_given ; /**< @brief Whether addressFamily was given. */ @@ -192,7 +192,7 @@ void cmdline_parser_print_help(void); void cmdline_parser_print_version(void); /** - * Initializes all the fields a cmdline_parser_params structure + * Initializes all the fields a cmdline_parser_params structure * to their default values * @param params the structure to initialize */ diff --git a/daemon/src/client/lwm2m_client.c b/daemon/src/client/lwm2m_client.c index b41175a..7150e4c 100644 --- a/daemon/src/client/lwm2m_client.c +++ b/daemon/src/client/lwm2m_client.c @@ -205,6 +205,12 @@ static int Lwm2mClient_Start(Options * options) goto error_close_log; } + srandom((int)time(NULL)*getpid()); + if (options->CoapPort == 0) + { + options->CoapPort = 6000 + (rand() % 32768); + } + Lwm2m_SetLogLevel((options->Verbose) ? DebugLevel_Debug : DebugLevel_Info); Lwm2m_PrintBanner(); if (options->Verbose) @@ -222,8 +228,6 @@ static int Lwm2mClient_Start(Options * options) Lwm2mCore_SetDefaultContentType(options->DefaultContentType); - srandom((int)time(NULL)*getpid()); - CoapInfo * coap = coap_Init((options->AddressFamily == AF_INET) ? "0.0.0.0" : "::", options->CoapPort, false /* not a server */, (options->Verbose) ? DebugLevel_Debug : DebugLevel_Info); if (coap == NULL) { diff --git a/doc/docker.md b/doc/docker.md index 7ccd5de..cae336a 100644 --- a/doc/docker.md +++ b/doc/docker.md @@ -63,7 +63,7 @@ $ docker run --rm -p 5683:5683/udp -p 54321:54321/udp --name awa_serverd -it flo To run the client daemon, which will bootstrap and register with the server: ```sh -$ docker run --rm -p 6000:6000/udp -p 12345:12345/udp --link awa_bootstrapd:awa_bootstrapd --link awa_serverd:awa_serverd --name awa_clientd -it flowm2m/awalwm2m awa_clientd --endPointName Client1 --bootstrap coap://awa_bootstrapd:15685 +$ docker run --rm -p 6000:6000/udp -p 12345:12345/udp --link awa_bootstrapd:awa_bootstrapd --link awa_serverd:awa_serverd --name awa_clientd -it flowm2m/awalwm2m awa_clientd --port 6000 --endPointName Client1 --bootstrap coap://awa_bootstrapd:15685 ``` Awa tools may also be used: