From 6ad0519573600e05e0bed7682c1bba0ee823aeac Mon Sep 17 00:00:00 2001 From: maride Date: Thu, 28 Nov 2019 18:49:14 +0100 Subject: [PATCH] Log errors thrown by protocol submodules --- ethernet/ethernet.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ethernet/ethernet.go b/ethernet/ethernet.go index afb9863..d686b10 100644 --- a/ethernet/ethernet.go +++ b/ethernet/ethernet.go @@ -24,17 +24,17 @@ func Analyze(source *gopacket.PacketSource) error { if packet.Layer(layers.LayerTypeDNS) != nil { // Handle DNS packet - dns.ProcessDNSPacket(packet) + handleErr(dns.ProcessDNSPacket(packet)) } if packet.Layer(layers.LayerTypeARP) != nil { // Handle ARP packet - arp.ProcessARPPacket(packet) + handleErr(arp.ProcessARPPacket(packet)) } if packet.Layer(layers.LayerTypeDHCPv4) != nil { // Handle DHCP (v4) packet - dhcpv4.HandleDHCPv4Packet(packet) + handleErr(dhcpv4.HandleDHCPv4Packet(packet)) } } @@ -50,3 +50,11 @@ func printSummary() { dns.PrintDNSSummary() dhcpv4.PrintDHCPv4Summary() } + +// 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()) + } +}