This commit is contained in:
Unic-X
2023-06-19 20:50:45 +05:30
parent 9d2e668f86
commit 57645afebc
14 changed files with 28515 additions and 29121 deletions

View File

@@ -14,7 +14,7 @@ import (
)
// This go routine communicates through channels and computes flow stats
func FlowMeter(ch chan gopacket.Packet, done chan struct{}, maxNumPackets int, localIP string, ifLocalIPKnown bool, fname string) error {
func PacketBreeze(ch chan gopacket.Packet, done chan struct{}, maxNumPackets int, localIP string, ifLocalIPKnown bool, fname string) error {
flowDict := make(map[string][]interface{})
flowSave := make(map[string][]interface{})

View File

@@ -0,0 +1,36 @@
package packetAnalyzer
import (
"testing"
"github.com/google/gopacket"
"github.com/google/gopacket/pcap"
)
func TestPacket(t *testing.T) {
var Handle *pcap.Handle
filename := "foo"
maxNumPackets := 2
ifLocalIPKnown := false
localIP := "143.198.72.237"
ch := make(chan gopacket.Packet)
done := make(chan struct{})
go PacketBreeze(ch, done, maxNumPackets, localIP, ifLocalIPKnown, filename)
defer Handle.Close()
packetSource := gopacket.NewPacketSource(Handle, Handle.LinkType())
loop:
for packet := range packetSource.Packets() {
select {
case ch <- packet:
case <-done:
close(ch)
close(done)
break loop
}
}
}