aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/config/controlListRoutes.c
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/hicn/config/controlListRoutes.c')
-rw-r--r--hicn-light/src/hicn/config/controlListRoutes.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/hicn-light/src/hicn/config/controlListRoutes.c b/hicn-light/src/hicn/config/controlListRoutes.c
index 3dc8fa3a3..395251b94 100644
--- a/hicn-light/src/hicn/config/controlListRoutes.c
+++ b/hicn-light/src/hicn/config/controlListRoutes.c
@@ -32,10 +32,14 @@
static CommandReturn _controlListRoutes_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlListRoutes_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandListRoutes = "list routes";
static const char *_commandListRoutesHelp = "help list routes";
@@ -56,29 +60,30 @@ CommandOps *controlListRoutes_HelpCreate(ControlState *state) {
static CommandReturn _controlListRoutes_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("command: list routes\n");
- printf("\n");
- printf(
- "This command will fetch the prefix routing table. For each route, it "
- "will list:\n");
- printf(" iface: interface\n");
- printf(
- " protocol: the routing protocol, such as STATIC, CONNECTED, etc.\n");
- printf(
- " type: LMP or EXACT (longest matching prefix or exact match)\n");
- printf(" cost: The route cost, lower being preferred\n");
- printf(" next: List of next hops by interface id\n");
- printf(" prefix: name prefix\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "command: list routes\n"
+ "\n"
+ "This command will fetch the prefix routing table. For each route, it "
+ "will list:\n"
+ " iface: interface\n"
+ " protocol: the routing protocol, such as STATIC, CONNECTED, etc.\n"
+ " type: LMP or EXACT (longest matching prefix or exact match)\n"
+ " cost: The route cost, lower being preferred\n"
+ " next: List of next hops by interface id\n"
+ " prefix: name prefix\n"
+ "\n");
return CommandReturn_Success;
}
static CommandReturn _controlListRoutes_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 2) {
- _controlListRoutes_HelpExecute(parser, ops, args);
+ _controlListRoutes_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -107,11 +112,11 @@ static CommandReturn _controlListRoutes_Execute(CommandParser *parser,
char *addrString = NULL;
in_port_t port = htons(1234); // this is a random port number that is ignored
-
+ size_t output_offset = 0;
if (receivedHeader->length > 0) {
- printf("%6.6s %8.8s %70.70s %s\n", "iface", "cost", "prefix", "len");
+ output_offset = snprintf(output, output_size, "%6.6s %8.8s %70.70s %s\n", "iface", "cost", "prefix", "len");
} else {
- printf(" --- No entry in the list \n");
+ output_offset = snprintf(output, output_size, " --- No entry in the list \n");
}
for (int i = 0; i < receivedHeader->length; i++) {
@@ -136,7 +141,7 @@ static CommandReturn _controlListRoutes_Execute(CommandParser *parser,
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);
}