pancap/ethernet/ethernet.go

46 lines
976 B
Go
Raw Normal View History

package ethernet
import (
2019-11-28 12:45:32 +00:00
"git.darknebu.la/maride/pancap/ethernet/arp"
"git.darknebu.la/maride/pancap/ethernet/dns"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"log"
)
func Analyze(source *gopacket.PacketSource) error {
// Loop over all packets now
for {
packet, packetErr := source.NextPacket()
if packet == nil {
// We iterated over all packets, we're done here
break
} else if packetErr != nil {
// encountered some problem, report it
log.Printf("Encountered a problem with a packet: %s", packetErr.Error())
continue
}
2019-11-27 19:24:12 +00:00
if packet.Layer(layers.LayerTypeDNS) != nil {
// Handle DNS packet
dns.ProcessDNSPacket(packet)
}
if packet.Layer(layers.LayerTypeARP) != nil {
// Handle ARP packet
arp.ProcessARPPacket(packet)
}
}
// After processing all packets, print summary
printSummary()
return nil
}
// Prints all the summaries.
func printSummary() {
2019-11-27 19:24:12 +00:00
arp.PrintARPSummary()
dns.PrintDNSSummary()
}