2019-11-26 22:06:57 +00:00
|
|
|
package ethernet
|
|
|
|
|
2019-11-26 22:55:18 +00:00
|
|
|
import (
|
2019-11-28 12:45:32 +00:00
|
|
|
"git.darknebu.la/maride/pancap/ethernet/arp"
|
2019-11-28 16:16:22 +00:00
|
|
|
"git.darknebu.la/maride/pancap/ethernet/dhcpv4"
|
2019-11-28 18:30:54 +00:00
|
|
|
"git.darknebu.la/maride/pancap/ethernet/dns"
|
2019-11-26 22:55:18 +00:00
|
|
|
"github.com/google/gopacket"
|
|
|
|
"github.com/google/gopacket/layers"
|
|
|
|
"log"
|
|
|
|
)
|
2019-11-26 22:06:57 +00:00
|
|
|
|
|
|
|
func Analyze(source *gopacket.PacketSource) error {
|
2019-11-26 22:55:18 +00:00
|
|
|
// 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
|
2019-11-28 17:49:14 +00:00
|
|
|
handleErr(dns.ProcessDNSPacket(packet))
|
2019-11-27 19:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if packet.Layer(layers.LayerTypeARP) != nil {
|
|
|
|
// Handle ARP packet
|
2019-11-28 17:49:14 +00:00
|
|
|
handleErr(arp.ProcessARPPacket(packet))
|
2019-11-26 22:55:18 +00:00
|
|
|
}
|
2019-11-28 16:16:22 +00:00
|
|
|
|
|
|
|
if packet.Layer(layers.LayerTypeDHCPv4) != nil {
|
|
|
|
// Handle DHCP (v4) packet
|
2019-11-28 17:49:14 +00:00
|
|
|
handleErr(dhcpv4.HandleDHCPv4Packet(packet))
|
2019-11-28 16:16:22 +00:00
|
|
|
}
|
2019-11-26 22:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// After processing all packets, print summary
|
|
|
|
printSummary()
|
|
|
|
|
2019-11-26 22:06:57 +00:00
|
|
|
return nil
|
|
|
|
}
|
2019-11-26 22:55:18 +00:00
|
|
|
|
|
|
|
// Prints all the summaries.
|
|
|
|
func printSummary() {
|
2019-11-27 19:24:12 +00:00
|
|
|
arp.PrintARPSummary()
|
2019-11-27 16:10:55 +00:00
|
|
|
dns.PrintDNSSummary()
|
2019-11-28 16:16:22 +00:00
|
|
|
dhcpv4.PrintDHCPv4Summary()
|
2019-11-26 22:55:18 +00:00
|
|
|
}
|
2019-11-28 17:49:14 +00:00
|
|
|
|
|
|
|
// Handles an error, if err is not nil.
|
|
|
|
func handleErr(err error) {
|
|
|
|
// (hopefully) most calls to this function will contain a nil error, so we need to check if we really got an error
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Encountered error while examining packets, continuing anyway. Error: %s", err.Error())
|
|
|
|
}
|
|
|
|
}
|