Skip to content

Commit

Permalink
add new flag: --print
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Apr 27, 2024
1 parent 2b93568 commit e750e34
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 1 addition & 3 deletions cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ type Options struct {
pcapFilter string
listInterfaces bool
version bool
print bool
}

func (o Options) WritePath() string {
if o.writeFilePath == "" || o.writeFilePath == "-" {
return ""
}
return o.writeFilePath
}
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func init() {
"Print the list of the network interfaces available on the system")
rootCmd.Flags().BoolVar(&opts.version, "version", false,
"Print the ptcpdump and libpcap version strings and exit")
rootCmd.Flags().BoolVar(&opts.print, "print", false,
"Print parsed packet output, even if the raw packets are being saved to a file with the -w flag")
}

func Execute() error {
Expand Down
3 changes: 2 additions & 1 deletion cmd/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func getWriters(opts Options, pcache *metadata.ProcessCache) ([]writer.PacketWri
return nil, err
}
writers = append(writers, pcapWriter)
} else {
}
if opts.writeFilePath == "" || opts.print {
stdoutWriter := writer.NewStdoutWriter(os.Stdout, pcache)
writers = append(writers, stdoutWriter)
}
Expand Down

0 comments on commit e750e34

Please sign in to comment.