-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
42 lines (34 loc) · 1.05 KB
/
config.go
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
package main
import (
"fmt"
log "log/slog"
"os"
"strings"
"github.com/spf13/pflag"
)
type Config struct {
Pcapfilter string
Targets []string
PcapFilename string
Verbose bool
DbgImagePath string
}
var config Config
func init() {
var help bool
pflag.BoolVarP(&help, "help", "h", false, "")
pflag.StringSliceVarP(&config.Targets, "i", "i", []string{"__netif_receive_skb_core", "__dev_queue_xmit"}, "symbol|symbol+offset|address")
pflag.StringVarP(&config.PcapFilename, "w", "w", "/tmp/a.pcap", "write packets to a file")
pflag.BoolVarP(&config.Verbose, "v", "v", false, "verbose output")
pflag.StringVarP(&config.DbgImagePath, "d", "d", "", "path to debug image")
pflag.Parse()
config.Pcapfilter = strings.Join(pflag.Args(), " ")
if help || len(config.Pcapfilter) == 0 {
fmt.Fprintf(os.Stderr, "ktcpdump [ -i kfunc ] [ -w file ] [ -d vmlinux-dbg ] [ -v ] expresssion\n")
pflag.PrintDefaults()
os.Exit(1)
}
if config.Verbose {
log.SetDefault(log.New(log.NewTextHandler(os.Stdout, &log.HandlerOptions{Level: log.LevelDebug})))
}
}