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
6
int
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. */
30
SCRunmodeSet
(
RUNMODE_LIB
);
31
32
/* Validate/finalize the runmode. */
33
if
(
SCFinalizeRunMode
() !=
TM_ECODE_OK
) {
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. */
50
if
(
SCLoadYamlConfig
() !=
TM_ECODE_OK
) {
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
67
SuricataInit
();
68
69
return
0;
70
}
LiveRegisterDevice
int LiveRegisterDevice(const char *dev)
Add a pcap device for monitoring and create structure.
Definition:
util-device.c:131
SuricataInit
void SuricataInit(void)
Definition:
suricata.c:2927
TM_ECODE_DONE
@ TM_ECODE_DONE
Definition:
tm-threads-common.h:83
SCParseCommandLine
TmEcode SCParseCommandLine(int argc, char **argv)
Definition:
suricata.c:1320
main
int main(int argc, char **argv)
Definition:
main.cpp:6
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition:
tm-threads-common.h:82
RUNMODE_LIB
@ RUNMODE_LIB
Definition:
runmodes.h:40
TM_ECODE_OK
@ TM_ECODE_OK
Definition:
tm-threads-common.h:81
SCRunmodeSet
void SCRunmodeSet(SCRunMode run_mode)
Set the current run mode.
Definition:
suricata.c:271
util-device.h
conf.h
SCConfSetFromString
int SCConfSetFromString(const char *input, int final)
Set a configuration parameter from a string.
Definition:
conf.c:264
suricata-common.h
SCStartInternalRunMode
int SCStartInternalRunMode(int argc, char **argv)
Definition:
suricata.c:2327
SCLoadYamlConfig
TmEcode SCLoadYamlConfig(void)
Definition:
suricata.c:963
suricata.h
SuricataPreInit
void SuricataPreInit(const char *progname)
Definition:
suricata.c:2918
SCFinalizeRunMode
int SCFinalizeRunMode(void)
Definition:
suricata.c:2383
examples
lib
cplusplus
main.cpp
Generated on Thu May 8 2025 23:30:24 for suricata by
1.8.18