examples/lib/cplusplus: simplfy, make more like the simple example

To prep for the removal of the lib runmode, simplify this C++ example
to match our simple example. We don't yet have the C++ compatible
headers to allow for a C++ app to register its own custom runmode.
pull/14961/head
Jason Ish 4 months ago committed by Victor Julien
parent 445de77c71
commit 7dd23392cc

@ -1,7 +1,21 @@
#include "suricata-common.h" /* Copyright (C) 2024 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include "suricata.h" #include "suricata.h"
#include "conf.h"
#include "util-device.h"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -11,24 +25,6 @@ int main(int argc, char **argv)
* directly configure Suricata through the Conf API. */ * directly configure Suricata through the Conf API. */
SCParseCommandLine(argc, argv); SCParseCommandLine(argc, argv);
/* Find our list of pcap files, after the "--". */
while (argc) {
bool end = strncmp(argv[0], "--", 2) == 0;
argv++;
argc--;
if (end) {
break;
}
}
if (argc == 0) {
fprintf(stderr, "ERROR: No PCAP files provided\n");
return 1;
}
/* Set the runmode to library mode. Perhaps in the future this
* should be done in some library bootstrap function. */
SCRunmodeSet(RUNMODE_LIB);
/* Validate/finalize the runmode. */ /* Validate/finalize the runmode. */
if (SCFinalizeRunMode() != TM_ECODE_OK) { if (SCFinalizeRunMode() != TM_ECODE_OK) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -51,20 +47,19 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* Set "offline" runmode to replay a pcap in library mode. */ /* Enable default signal handlers just like Suricata. */
if (!SCConfSetFromString("runmode=offline", 1)) { SCEnableDefaultSignalHandlers();
exit(EXIT_FAILURE);
}
/* Force logging to the current directory. */ SuricataInit();
SCConfSetFromString("default-log-dir=.", 1); SuricataPostInit();
if (LiveRegisterDevice("lib0") < 0) { /* Suricata is now running, but we enter a loop to keep it running
fprintf(stderr, "LiveRegisterDevice failed"); * until it shouldn't be running anymore. */
exit(1); SuricataMainLoop();
}
SuricataInit(); /* Shutdown engine. */
SuricataShutdown();
GlobalsDestroy();
return 0; return EXIT_SUCCESS;
} }

Loading…
Cancel
Save