suricata
main.cpp
Go to the documentation of this file.
1#include "suricata-common.h"
2#include "suricata.h"
3#include "conf.h"
4#include "util-device.h"
5
6int main(int argc, char **argv)
7{
8 SuricataPreInit(argv[0]);
9
10 /* Parse command line options. This is optional, you could
11 * directly configure Suricata through the Conf API. */
12 SCParseCommandLine(argc, argv);
13
14 /* Find our list of pcap files, after the "--". */
15 while (argc) {
16 bool end = strncmp(argv[0], "--", 2) == 0;
17 argv++;
18 argc--;
19 if (end) {
20 break;
21 }
22 }
23 if (argc == 0) {
24 fprintf(stderr, "ERROR: No PCAP files provided\n");
25 return 1;
26 }
27
28 /* Set the runmode to library mode. Perhaps in the future this
29 * should be done in some library bootstrap function. */
31
32 /* Validate/finalize the runmode. */
34 exit(EXIT_FAILURE);
35 }
36
37 /* Handle internal runmodes. Typically you wouldn't do this as a
38 * library user, however this example is showing how to replicate
39 * the Suricata application with the library. */
40 switch (SCStartInternalRunMode(argc, argv)) {
41 case TM_ECODE_DONE:
42 exit(EXIT_SUCCESS);
43 case TM_ECODE_FAILED:
44 exit(EXIT_FAILURE);
45 }
46
47 /* Load configuration file, could be done earlier but must be done
48 * before SuricataInit, but even then its still optional as you
49 * may be programmatically configuration Suricata. */
51 exit(EXIT_FAILURE);
52 }
53
54 /* Set "offline" runmode to replay a pcap in library mode. */
55 if (!SCConfSetFromString("runmode=offline", 1)) {
56 exit(EXIT_FAILURE);
57 }
58
59 /* Force logging to the current directory. */
60 SCConfSetFromString("default-log-dir=.", 1);
61
62 if (LiveRegisterDevice("lib0") < 0) {
63 fprintf(stderr, "LiveRegisterDevice failed");
64 exit(1);
65 }
66
68
69 return 0;
70}
int SCConfSetFromString(const char *input, int final)
Set a configuration parameter from a string.
Definition conf.c:264
int main(int argc, char **argv)
Definition main.cpp:6
@ RUNMODE_LIB
Definition runmodes.h:40
void SuricataInit(void)
Definition suricata.c:3012
TmEcode SCLoadYamlConfig(void)
Definition suricata.c:1012
int SCFinalizeRunMode(void)
Definition suricata.c:2451
int SCStartInternalRunMode(int argc, char **argv)
Definition suricata.c:2389
void SCRunmodeSet(SCRunMode run_mode)
Set the current run mode.
Definition suricata.c:284
TmEcode SCParseCommandLine(int argc, char **argv)
Definition suricata.c:1369
void SuricataPreInit(const char *progname)
Definition suricata.c:3003
@ TM_ECODE_FAILED
@ TM_ECODE_OK
@ TM_ECODE_DONE
int LiveRegisterDevice(const char *dev)
Add a pcap device for monitoring and create structure.