Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added cache to remember last pcapfile #12

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pcap/pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/lemorz56/repcap/commons"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated #10

)

var lastOpenedFile string

func WritePacketDelayed(handle *pcap.Handle, buf []byte, ci gopacket.CaptureInfo) {
if ci.CaptureLength != ci.Length {
return
Expand Down Expand Up @@ -89,6 +91,9 @@ func Infos(filename string) (start, end time.Time, packets, size int) {
}

func LoadPcap(filename string) {
if filename == lastOpenedFile {
return
}
var err error
commons.PcapHandle, err = pcap.OpenOffline(filename)
if err != nil {
Expand All @@ -98,6 +103,7 @@ func LoadPcap(filename string) {
commons.Start = time.Now()
commons.Pkt = 0
commons.TsStart, commons.TsEnd, commons.Packets, commons.Size = Infos(commons.PcapFile)
lastOpenedFile = filename
}

func OpenDest(netIntf string) *pcap.Handle {
Expand Down