Skip to content

Commit

Permalink
fixes for BSD
Browse files Browse the repository at this point in the history
  • Loading branch information
mosajjal committed Nov 7, 2022
1 parent 3ee252d commit 7cdb95c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions capture/livecap_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
)

type BsdHandle struct {
sniffer bsdbpf.BPFSniffer
sniffer bsdbpf.BPFSniffer
readCnt uint
droppedCnt uint
}

func initializeLivePcap(devName, filter string) *BsdHandle {
Expand Down Expand Up @@ -43,7 +45,7 @@ func initializeLivePcap(devName, filter string) *BsdHandle {
// }
// }
// h := livePcapHandle{handle}
return &BsdHandle{*handle}
return &BsdHandle{*handle, 0, 0}
}

func (h *BsdHandle) ReadPacketData() (data []byte, ci gopacket.CaptureInfo, err error) {
Expand All @@ -53,6 +55,12 @@ func (h *BsdHandle) ReadPacketData() (data []byte, ci gopacket.CaptureInfo, err
// with the default bsd capture setup. have to do this instead
if data == nil {
data = []byte{1}
h.droppedCnt++
}
if err != nil {
h.droppedCnt++
} else {
h.readCnt++
}
return data, ci, nil
}
Expand All @@ -66,9 +74,5 @@ func (h *BsdHandle) Close() {
}

func (h *BsdHandle) Stat() (uint, uint, error) {
stats, err := h.sniffer.Stats()
if err != nil {
return 0, 0, err
}
return uint(stats.Packets), uint(stats.Drops), nil
return h.readCnt, h.droppedCnt, nil
}

0 comments on commit 7cdb95c

Please sign in to comment.