-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_linux.go
More file actions
53 lines (44 loc) · 1.2 KB
/
main_linux.go
File metadata and controls
53 lines (44 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//go:build linux
package main
import (
"fmt"
"log"
"os"
"github.com/akamensky/argparse"
)
var activeInterfaces []listeningInterface
var err error
var blockingChannel = make(chan int)
var quitService chan struct{}
func main() {
// config file argument parsing
parser := argparse.NewParser("Local Packet Capture", "Listen to any interface and log traffic to a file or send it to an API endpoint.")
configFilePath := parser.String("c", "config", &argparse.Options{Required: true, Help: "YAML configuration file"})
err := parser.Parse(os.Args)
if err != nil {
fmt.Print(parser.Usage(err))
}
// load yaml configuration
err = LoadConfig(*configFilePath)
if err != nil {
log.Fatalln(fmt.Errorf("error loading configuration: %v", err))
}
// initialize logger
var APP_LOGLEVEL int
switch AppConfig.ApplicationLogLevel {
case "LOGLEVEL_DEBUG":
APP_LOGLEVEL = LOGLEVEL_DEBUG
case "LOGLEVEL_WARNING":
APP_LOGLEVEL = LOGLEVEL_WARNING
case "LOGLEVEL_ERROR":
APP_LOGLEVEL = LOGLEVEL_ERROR
default:
APP_LOGLEVEL = LOGLEVEL_INFO
}
InitLogger(APP_LOGLEVEL)
if AppConfig.ApplicationLogFile != "" {
SetLogToFile(AppConfig.ApplicationLogFile)
}
networkCaptureRoutine(quitService)
<-blockingChannel
}