Merge branch 'develop' into infinite-ka-fix

This commit is contained in:
Simon Duquennoy 2018-03-23 19:01:19 +01:00 committed by GitHub
commit 35bcaeb828
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 23 deletions

View File

@ -218,8 +218,11 @@ PT_THREAD(cmd_ping(struct pt *pt, shell_output_func output, char *args))
/* Get argument (remote IPv6) */
SHELL_ARGS_NEXT(args, next_args);
if(uiplib_ipaddrconv(args, &remote_addr) == 0) {
SHELL_OUTPUT(output, "Invalid IPv6: %s\n", args);
if(args == NULL) {
SHELL_OUTPUT(output, "Destination IPv6 address is not specified\n");
PT_EXIT(pt);
} else if(uiplib_ipaddrconv(args, &remote_addr) == 0) {
SHELL_OUTPUT(output, "Invalid IPv6 address: %s\n", args);
PT_EXIT(pt);
}

View File

@ -51,28 +51,28 @@
/* Helper macros to parse arguments */
#define SHELL_ARGS_INIT(args, next_args) (next_args) = (args);
#define SHELL_ARGS_NEXT(args, next_args) do { \
(args) = (next_args); \
if((args) != NULL) { \
if(*(args) == '\0') { \
(args) = NULL; \
} else { \
(next_args) = strchr((args), ' '); \
if((next_args) != NULL) { \
*(next_args) = '\0'; \
(next_args)++; \
} \
} \
} else { \
(next_args) = NULL; \
} \
} while(0)
#define SHELL_ARGS_NEXT(args, next_args) do { \
(args) = (next_args); \
if((args) != NULL) { \
if(*(args) == '\0') { \
(args) = NULL; \
} else { \
(next_args) = strchr((args), ' '); \
if((next_args) != NULL) { \
*(next_args) = '\0'; \
(next_args)++; \
} \
} \
} else { \
(next_args) = NULL; \
} \
} while(0)
/* Printf-formatted output via a given output function */
#define SHELL_OUTPUT(output_func, format, ...) do { \
char buffer[128]; \
snprintf(buffer, sizeof(buffer), format, ##__VA_ARGS__); \
(output_func)(buffer); \
#define SHELL_OUTPUT(output_func, format, ...) do { \
char buffer[192]; \
snprintf(buffer, sizeof(buffer), format, ##__VA_ARGS__); \
(output_func)(buffer); \
} while(0);
typedef void (shell_output_func)(const char *str);
@ -85,7 +85,7 @@ void shell_init(void);
/**
* \brief A protothread that is spawned by a Shell driver when receiving a new line.
*/
PT_THREAD(shell_input(struct pt *pt, shell_output_func output, const char *cmd));
PT_THREAD(shell_input(struct pt *pt, shell_output_func output, const char *cmd));
/**
* Prints an IPv6 address