Skip to content

Commit

Permalink
Merge pull request #10 from deepfence/feature-stdout
Browse files Browse the repository at this point in the history
Add reserved name 'stdout' for file output, referring to stdout
  • Loading branch information
vadorovsky authored Apr 8, 2022
2 parents 6966821 + 486fd19 commit d6d9a23
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ tail -c +1 -f /tmp/dump_file | tcpdump -r -
```

```bash
# Edit the configuration to write to /dev/stdout, and pipe output to tcpdump:
./packet-streamer receiver --config contrib/receiver-stdout.yaml | tcpdump -r -
# Edit the configuration to write to the special name 'stdout', and pipe output to tcpdump:
./packet-streamer receiver --config ./contrib/config/receiver-stdout.yaml | tcpdump -r -
```

## Run a PacketStreamer sensor
Expand Down Expand Up @@ -238,7 +238,7 @@ output:
address: _ip-address_
port: _listen-port_
file: # required in 'receiver' mode
path: _filename_
path: _filename_|stdout # 'stdout' is a reserved name. Receiver will write to stdout
tls: # optional
enable: _true_|_false_
certfile: _filename_
Expand Down
2 changes: 1 addition & 1 deletion contrib/config/receiver-stdout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ input:
port: 8081
output:
file:
path: /dev/stdout
path: stdout
10 changes: 7 additions & 3 deletions pkg/streamer/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ func InitOutput(config *config.Config, proto string) error {
if config.Output.File != nil {
var pcapBuffer bytes.Buffer
pcapWriter := pcapgo.NewWriter(&pcapBuffer)
fileFd, err := os.OpenFile(config.Output.File.Path, os.O_CREATE|os.O_RDWR, 0666)
if err != nil {
return err
fileFd := os.Stdout
if config.Output.File.Path != "stdout" {
var err error
fileFd, err = os.OpenFile(config.Output.File.Path, os.O_CREATE|os.O_RDWR, 0644)
if err != nil {
return err
}
}
pcapWriter.WriteFileHeader(uint32(config.InputPacketLen), layers.LinkTypeEthernet)
fileFd.Write(pcapBuffer.Bytes())
Expand Down

0 comments on commit d6d9a23

Please sign in to comment.