Compare commits

..

No commits in common. 'master' and 'v0.0.1' have entirely different histories.

@ -40,8 +40,6 @@ type PacketInfo struct {
}
func (p *Packets) Key(key string) PacketInfo {
p.RLock()
defer p.RUnlock()
return p.cu[key]
}
@ -157,9 +155,7 @@ func (p *Packets) parseTcp(info PacketInfo, packet gopacket.Packet, layer gopack
info.finState = tcp.FIN
info.synState = tcp.SYN
info.tcpWindow = tcp.Window
p.RLock()
lastPacket := p.cu[info.Key]
p.RUnlock()
if lastPacket.Key != info.Key {
lastPacket = PacketInfo{
Key: info.Key,
@ -184,9 +180,7 @@ func (p *Packets) parseTcp(info PacketInfo, packet gopacket.Packet, layer gopack
p.cu[info.Key] = lastPacket
p.Unlock()
}
p.RLock()
lastReverse := p.cu[info.ReverseKey]
p.RUnlock()
if !lastPacket.isFirst {
info.comment = lastPacket.comment
if lastPacket.SrcMac != nil && len(info.SrcMac) == 0 {

@ -1,6 +1,6 @@
module b612.me/bcap
go 1.20
go 1.22.4
require (
github.com/florianl/go-nfqueue/v2 v2.0.0

@ -1,7 +1,6 @@
package libpcap
import (
"context"
"fmt"
"github.com/google/gopacket"
"github.com/google/gopacket/pcap"
@ -13,22 +12,12 @@ type NetCatch struct {
sentence string
fn func(gopacket.Packet)
*pcap.Handle
ctx context.Context
stopFn context.CancelFunc
}
func (n *NetCatch) Recall() func(gopacket.Packet) {
return n.fn
}
func (n *NetCatch) SetRecall(fn func(p gopacket.Packet)) {
n.fn = fn
}
func (n *NetCatch) Stop() {
n.stopFn()
}
func FindAllDevs() ([]pcap.Interface, error) {
return pcap.FindAllDevs()
}
@ -56,7 +45,6 @@ func NewCatch(host string, sentence string) (*NetCatch, error) {
nc.host = host
nc.eth = eth
nc.sentence = sentence
nc.ctx, nc.stopFn = context.WithCancel(context.Background())
return nc, nil
}
@ -64,7 +52,6 @@ func NewCatchEth(eth string, sentence string) (*NetCatch, error) {
nc := new(NetCatch)
nc.eth = eth
nc.sentence = sentence
nc.ctx, nc.stopFn = context.WithCancel(context.Background())
return nc, nil
}
@ -81,14 +68,10 @@ func (n *NetCatch) Run() error {
return err
}
pks := gopacket.NewPacketSource(handle, handle.LinkType())
for {
select {
case packet := <-pks.Packets():
if n.fn != nil {
n.fn(packet)
}
case <-n.ctx.Done():
return nil
for packet := range pks.Packets() {
if n.fn != nil {
n.fn(packet)
}
}
return nil
}

@ -17,10 +17,6 @@ type NfQueue struct {
recallFn func(id uint32, q *nfqueue.Nfqueue, p Packet)
}
func (n *NfQueue) RecallFn() func(id uint32, q *nfqueue.Nfqueue, p Packet) {
return n.recallFn
}
type Packet struct {
Packet gopacket.Packet
Attr nfqueue.Attribute
@ -42,12 +38,6 @@ func (n *NfQueue) SetRecall(fn func(id uint32, q *nfqueue.Nfqueue, p Packet)) {
n.recallFn = fn
}
func (n *NfQueue) Stop() {
if n.stopFn != nil {
n.stopFn()
}
}
func (n *NfQueue) Run() error {
cfg := nfqueue.Config{
NfQueue: n.queid,

Loading…
Cancel
Save