]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
examples/lib: replicate Suricata using the library
authorJason Ish <jason.ish@oisf.net>
Thu, 22 Feb 2024 20:27:50 +0000 (14:27 -0600)
committerVictor Julien <victor@inliniac.net>
Mon, 25 Mar 2024 16:36:28 +0000 (17:36 +0100)
With more functions exposed via the library, a library user can now
replicate the Suricata "main" function.

examples/lib/simple/main.c

index 0ebb125bf2ff2ceada629bfc48937f730406ac0b..c5775251164c7a4c4f3997b5a6dee506bdf3dbc9 100644 (file)
@@ -1,7 +1,35 @@
+/* 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"
 
 int main(int argc, char **argv)
 {
-    SuricataMain(argc, argv);
-    return 0;
+    SuricataPreInit(argv[0]);
+    SuricataInit(argc, argv);
+    SuricataPostInit();
+
+    /* Suricata is now running, but we enter a loop to keep it running
+     * until it shouldn't be running anymore. */
+    SuricataMainLoop();
+
+    /* Shutdown engine. */
+    SuricataShutdown();
+    GlobalsDestroy();
+
+    return EXIT_SUCCESS;
 }