diff options
author | Angelo Mantellini <angelo.mantellini@cisco.com> | 2020-06-09 14:48:02 +0200 |
---|---|---|
committer | Angelo Mantellini <angelo.mantellini@cisco.com> | 2020-06-15 11:43:30 +0200 |
commit | 9e2c045d6118ef264d6cf8fc655b72d7c4c403dc (patch) | |
tree | d4156335f5ea69064e817b7c6536e0200c6421af /hicn-light/src/hicn/config/controlAddPunting.c | |
parent | a84ff82bb37ac53f20639d6e5e7f19d002459f31 (diff) |
[HICN-626] Return output from libhicnlight
Signed-off-by: Angelo Mantellini <angelo.mantellini@cisco.com>
Change-Id: I2351ce4dcefa1311fa09049f87e8317c8fe449f4
Diffstat (limited to 'hicn-light/src/hicn/config/controlAddPunting.c')
-rw-r--r-- | hicn-light/src/hicn/config/controlAddPunting.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/hicn-light/src/hicn/config/controlAddPunting.c b/hicn-light/src/hicn/config/controlAddPunting.c index e3fb57c6b..41d846d55 100644 --- a/hicn-light/src/hicn/config/controlAddPunting.c +++ b/hicn-light/src/hicn/config/controlAddPunting.c @@ -34,10 +34,14 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser, CommandOps *ops, - PARCList *args); + PARCList *args, + char *output, + size_t output_size); static CommandReturn _controlAddPunting_HelpExecute(CommandParser *parser, CommandOps *ops, - PARCList *args); + PARCList *args, + char *output, + size_t output_size); static const char *_commandAddPunting = "add punting"; static const char *_commandAddPuntingHelp = "help add punting"; @@ -59,24 +63,26 @@ CommandOps *controlAddPunting_HelpCreate(ControlState *state) { static CommandReturn _controlAddPunting_HelpExecute(CommandParser *parser, CommandOps *ops, - PARCList *args) { - printf("add punting <symbolic> <prefix>\n"); - printf(" <symbolic> : listener symbolic name\n"); - printf( - " <address> : prefix to add as a punting rule. (example " - "1234::0/64)\n"); - printf("\n"); - + PARCList *args, + char *output, + size_t output_size) { + snprintf(output, output_size, "add punting <symbolic> <prefix>\n" + " <symbolic> : listener symbolic name\n" + " <address> : prefix to add as a punting rule. (example " + "1234::0/64)\n" + "\n"); return CommandReturn_Success; } static CommandReturn _controlAddPunting_Execute(CommandParser *parser, CommandOps *ops, - PARCList *args) { + PARCList *args, + char *output, + size_t output_size) { ControlState *state = ops->closure; if (parcList_Size(args) != 4) { - _controlAddPunting_HelpExecute(parser, ops, args); + _controlAddPunting_HelpExecute(parser, ops, args, output, output_size); return CommandReturn_Failure; } @@ -84,7 +90,7 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser, if (!utils_ValidateSymbolicName(symbolicOrConnid) && !utils_IsNumber(symbolicOrConnid)) { - printf( + snprintf(output, output_size, "ERROR: Invalid symbolic or connid:\n" "symbolic name must begin with an alpha followed by alphanum;\nconnid " "must be an integer\n"); @@ -111,7 +117,7 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser, // check and set IP address if (inet_pton(AF_INET, addr, &addPuntingCommand->address.v4.as_u32) == 1) { if (len > 32) { - printf("ERROR: exceeded INET mask length, max=32\n"); + snprintf(output, output_size, "ERROR: exceeded INET mask length, max=32\n"); parcMemory_Deallocate(&addPuntingCommand); free(addr); return CommandReturn_Failure; @@ -119,14 +125,14 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser, addPuntingCommand->addressType = ADDR_INET; } else if (inet_pton(AF_INET6, addr, &addPuntingCommand->address.v6.as_in6addr) == 1) { if (len > 128) { - printf("ERROR: exceeded INET6 mask length, max=128\n"); + snprintf(output, output_size, "ERROR: exceeded INET6 mask length, max=128\n"); parcMemory_Deallocate(&addPuntingCommand); free(addr); return CommandReturn_Failure; } addPuntingCommand->addressType = ADDR_INET6; } else { - printf("Error: %s is not a valid network address \n", addr); + snprintf(output, output_size, "Error: %s is not a valid network address \n", addr); parcMemory_Deallocate(&addPuntingCommand); free(addr); return CommandReturn_Failure; |