Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 51 additions & 34 deletions src/runmodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,47 +252,64 @@ void RunModeRegisterRunModes(void)
}

/**
* \brief Lists all registered runmodes.
* \brief Lists all registered runmodes (optimized table output).
*/
void RunModeListRunmodes(void)
{
printf("------------------------------------- Runmodes -------------------"
"-----------------------\n");

printf("| %-17s | %-17s | %-10s \n",
"RunMode Type", "Custom Mode ", "Description");
printf("|-----------------------------------------------------------------"
"-----------------------\n");
int i = RUNMODE_UNKNOWN + 1;
int j = 0;
for ( ; i < RUNMODE_USER_MAX; i++) {
int mode_displayed = 0;
for (j = 0; j < runmodes[i].cnt; j++) {
if (mode_displayed == 1) {
printf("| ----------------------------------------------"
"-----------------------\n");
RunMode *runmode = &runmodes[i].runmodes[j];
printf("| %-17s | %-17s | %-27s \n",
"",
runmode->name,
runmode->description);
} else {
RunMode *runmode = &runmodes[i].runmodes[j];
printf("| %-17s | %-17s | %-27s \n",
RunModeTranslateModeToName(runmode->runmode),
runmode->name,
runmode->description);
}
if (mode_displayed == 0)
mode_displayed = 1;
int type_width = 12;
int mode_width = 10;
const int desc_width = 60;

/* Dynamically calculate max column widths */
for (int i = RUNMODE_UNKNOWN + 1; i < RUNMODE_USER_MAX; i++) {
for (int j = 0; j < runmodes[i].cnt; j++) {
RunMode *r = &runmodes[i].runmodes[j];
int tlen = strlen(RunModeTranslateModeToName(r->runmode));
int mlen = strlen(r->name);
if (tlen > type_width)
type_width = tlen;
if (mlen > mode_width)
mode_width = mlen;
}
if (mode_displayed == 1) {
printf("|-----------------------------------------------------------------"
"-----------------------\n");
}

/* Print header */
printf("\n%-*s\n", type_width + mode_width + desc_width + 10,
"--------------------------- Runmodes ---------------------------");
printf("| %-*s | %-*s | %-*s |\n",
type_width, "RunMode Type",
mode_width, "Custom Mode",
desc_width, "Description");

/* Separator function */
auto void PrintSeparator(void) {
printf("|-%.*s-|-%.*s-|-%.*s-|\n",
type_width + 2, "----------------------------------------",
mode_width + 2, "----------------------------------------",
desc_width + 2, "------------------------------------------------------------");
};
PrintSeparator();

/* Print runmodes */
for (int i = RUNMODE_UNKNOWN + 1; i < RUNMODE_USER_MAX; i++) {
int printed = 0;
for (int j = 0; j < runmodes[i].cnt; j++) {
RunMode *r = &runmodes[i].runmodes[j];
const char *type_name = RunModeTranslateModeToName(r->runmode);

printf("| %-*s | %-*s | %-*s |\n",
printed ? 0 : type_width,
printed ? "" : type_name,
mode_width, r->name,
desc_width, r->description);
printed = 1;
}
if (printed)
PrintSeparator();
}
}

printf("\n");
}
Comment on lines -255 to +312
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any proposed modification must first go in Discord/Redmine. So, let's stick to what's required by the ticket you're working on for now and remove these changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any proposed modification must first go in Discord/Redmine. So, let's stick to what's required by the ticket you're working on for now and remove these changes.

Ok. will do that.

static const char *RunModeGetConfOrDefault(int capture_mode, const char *capture_plugin_name)
{
const char *custom_mode = NULL;
Expand Down
3 changes: 3 additions & 0 deletions src/suricata.c
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,9 @@ int SCFinalizeRunMode(void)
SCInstance *suri = &suricata;
switch (suri->run_mode) {
case RUNMODE_UNKNOWN:
printf("\n[!] No capture/runmode specified.\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Victor's review comments from the previous PR must be addressed.

printf(" Please specify a runmode or capture option.\n");
printf(" Use --list-runmodes to see available runmodes.\n\n");
PrintUsage(suri->progname);
return TM_ECODE_FAILED;
default:
Expand Down
Loading