Skip to content

Commit

Permalink
used -C flag instead of -G flag while saving tcp dump
Browse files Browse the repository at this point in the history
  • Loading branch information
avneesh-akto committed Apr 12, 2023
1 parent d243568 commit 0955052
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ RUN go build -o /mirroring-api-logging

EXPOSE 4789/udp

CMD ["/bin/sh", "-c", "mkdir /app/files | /mirroring-api-logging | tcpdump -i eth0 udp port 4789 -w /app/files/%s -W 720 -G 120 -K -n"]
CMD ["/bin/sh", "-c", "mkdir /app/files | /mirroring-api-logging | tcpdump -i eth0 udp port 4789 -w /app/files/file_ -W 720 -C 1m -K -n"]
29 changes: 19 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,11 @@ func main() {

for {

files, err := ioutil.ReadDir("/app/files/")
files, _ := os.ReadDir("/app/files/")
log.Println("reading files...")
if err != nil {
log.Fatal(err)
}
//if err != nil {
// log.Fatal(err)
//}

for _, file := range files {

Expand All @@ -511,23 +511,32 @@ func main() {
}

log.Println("file: ", file.Name())
fileCreationTs, _ := strconv.Atoi(file.Name())
timeNow := time.Now().Unix()

if timeNow-int64(fileCreationTs) < 120 {
continue
}
//fileCreationTs, _ := strconv.Atoi(file.Name())
//timeNow := time.Now().Unix()
//
//if timeNow-int64(fileCreationTs) < 120 {
// continue
//}

fileName := "/app/files/" + file.Name()
if handle, err := pcap.OpenOffline(fileName); err != nil {
log.Fatal(err)
} else {

epochTime := time.Now().Unix()
message := fmt.Sprintf("start %d", epochTime)
fmt.Println(message)

run(handle, -1, "MIRRORING")
flushAll()
e := os.Remove(fileName)
if e != nil {
log.Fatal(e)
}

epochTime = time.Now().Unix()
message = fmt.Sprintf("end %d", epochTime)
fmt.Println(message)
}

}
Expand Down

0 comments on commit 0955052

Please sign in to comment.