suricata
main.c
Go to the documentation of this file.
1 /* Copyright (C) 2024 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 #include "suricata.h"
19 
20 int main(int argc, char **argv)
21 {
22  SuricataPreInit(argv[0]);
23 
24  /* Parse command line options. This is optional, you could
25  * directly configure Suricata through the Conf API. */
26  SCParseCommandLine(argc, argv);
27 
28  /* Validate/finalize the runmode. */
29  if (SCFinalizeRunMode() != TM_ECODE_OK) {
30  exit(EXIT_FAILURE);
31  }
32 
33  /* Handle internal runmodes. Typically you wouldn't do this as a
34  * library user, however this example is showing how to replicate
35  * the Suricata application with the library. */
36  switch (SCStartInternalRunMode(argc, argv)) {
37  case TM_ECODE_DONE:
38  exit(EXIT_SUCCESS);
39  case TM_ECODE_FAILED:
40  exit(EXIT_FAILURE);
41  }
42 
43  /* Load configuration file, could be done earlier but must be done
44  * before SuricataInit, but even then its still optional as you
45  * may be programmatically configuration Suricata. */
46  if (SCLoadYamlConfig() != TM_ECODE_OK) {
47  exit(EXIT_FAILURE);
48  }
49 
50  SuricataInit();
52 
53  /* Suricata is now running, but we enter a loop to keep it running
54  * until it shouldn't be running anymore. */
56 
57  /* Shutdown engine. */
60 
61  return EXIT_SUCCESS;
62 }
SuricataMainLoop
void SuricataMainLoop(void)
Definition: suricata.c:2832
SuricataInit
void SuricataInit(void)
Definition: suricata.c:2921
TM_ECODE_DONE
@ TM_ECODE_DONE
Definition: tm-threads-common.h:86
SuricataPostInit
void SuricataPostInit(void)
Definition: suricata.c:3015
SCParseCommandLine
TmEcode SCParseCommandLine(int argc, char **argv)
Definition: suricata.c:1324
SuricataShutdown
void SuricataShutdown(void)
Definition: suricata.c:3004
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:85
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:84
main
int main(int argc, char **argv)
Definition: main.c:20
SCStartInternalRunMode
int SCStartInternalRunMode(int argc, char **argv)
Definition: suricata.c:2324
SCLoadYamlConfig
TmEcode SCLoadYamlConfig(void)
Definition: suricata.c:965
suricata.h
SuricataPreInit
void SuricataPreInit(const char *progname)
Definition: suricata.c:2912
SCFinalizeRunMode
int SCFinalizeRunMode(void)
Definition: suricata.c:2380
GlobalsDestroy
void GlobalsDestroy(void)
Definition: suricata.c:370