aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/config/controlListConnections.c
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/hicn/config/controlListConnections.c')
-rw-r--r--hicn-light/src/hicn/config/controlListConnections.c53
1 files changed, 29 insertions, 24 deletions
diff --git a/hicn-light/src/hicn/config/controlListConnections.c b/hicn-light/src/hicn/config/controlListConnections.c
index cbed8a79c..6406ba8c3 100644
--- a/hicn-light/src/hicn/config/controlListConnections.c
+++ b/hicn-light/src/hicn/config/controlListConnections.c
@@ -31,10 +31,14 @@
static CommandReturn _controlListConnections_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlListConnections_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandListConnections = "list connections";
static const char *_commandListConnectionsHelp = "help list connections";
@@ -56,30 +60,31 @@ CommandOps *controlListConnections_HelpCreate(ControlState *state) {
static CommandReturn _controlListConnections_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("list connections: displays a 1-line summary of each connection\n");
- printf("\n");
- printf("The columns are:\n");
- printf(" connection id : an integer index for the connection\n");
- printf(" state : UP or DOWN\n");
- printf(
- " local address : the local network address associated with the "
- "connection\n");
- printf(
- " remote address: the remote network address associated with the "
- "connection\n");
- printf(
- " protocol : the network protocol (tcp, udp, gre, mcast, "
- "ether)\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+snprintf(output, output_size, "%s", "list connections: displays a 1-line summary of each connection\n"
+ "\n"
+ "The columns are:\n"
+ " connection id : an integer index for the connection\n"
+ " state : UP or DOWN\n"
+ " local address : the local network address associated with the "
+ "connection\n"
+ " remote address: the remote network address associated with the "
+ "connection\n"
+ " protocol : the network protocol (tcp, udp, gre, mcast, "
+ "ether)\n"
+ "\n");
return CommandReturn_Success;
}
static CommandReturn _controlListConnections_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 2) {
- _controlListConnections_HelpExecute(parser, ops, args);
+ _controlListConnections_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
#ifdef WITH_POLICY
@@ -112,11 +117,12 @@ static CommandReturn _controlListConnections_Execute(CommandParser *parser,
commandOutputMain[j] = parcMemory_Allocate(sizeof(char) * 256);
}
}
+size_t output_offset = 0;
#ifdef WITH_POLICY
- printf("%5s %10s %12s %6s %40s %40s %5s %s %s\n", "id", "name", "admin_state", "state", "source", "destination", "type", "priority", "flags");
+ output_offset = snprintf(output, output_size, "%5s %10s %12s %6s %40s %40s %5s %s %s\n", "id", "name", "admin_state", "state", "source", "destination", "type", "priority", "flags");
#else
- printf("%5s %10s %12s %6s %40s %40s %5s\n", "id", "name", "admin_state", "state", "source", "destination", "type");
+ output_offset = snprintf(output, output_size, "%5s %10s %12s %6s %40s %40s %5s\n", "id", "name", "admin_state", "state", "source", "destination", "type");
#endif /* WITH_POLICY */
// Process/Print payload
@@ -171,8 +177,7 @@ foreach_policy_tag
if (!controlState_IsInteractive(state)) {
strcpy(commandOutputMain[i], result);
}
-
- puts(result);
+ output_offset += snprintf(output + output_offset, output_size - output_offset, "%s\n", result);
parcMemory_Deallocate((void **)&result);
parcBufferComposer_Release(&composer);
}