Log errors thrown by protocol submodules

This commit is contained in:
maride 2019-11-28 18:49:14 +01:00
parent a1281360cd
commit 6ad0519573

View File

@ -24,17 +24,17 @@ func Analyze(source *gopacket.PacketSource) error {
if packet.Layer(layers.LayerTypeDNS) != nil { if packet.Layer(layers.LayerTypeDNS) != nil {
// Handle DNS packet // Handle DNS packet
dns.ProcessDNSPacket(packet) handleErr(dns.ProcessDNSPacket(packet))
} }
if packet.Layer(layers.LayerTypeARP) != nil { if packet.Layer(layers.LayerTypeARP) != nil {
// Handle ARP packet // Handle ARP packet
arp.ProcessARPPacket(packet) handleErr(arp.ProcessARPPacket(packet))
} }
if packet.Layer(layers.LayerTypeDHCPv4) != nil { if packet.Layer(layers.LayerTypeDHCPv4) != nil {
// Handle DHCP (v4) packet // Handle DHCP (v4) packet
dhcpv4.HandleDHCPv4Packet(packet) handleErr(dhcpv4.HandleDHCPv4Packet(packet))
} }
} }
@ -50,3 +50,11 @@ func printSummary() {
dns.PrintDNSSummary() dns.PrintDNSSummary()
dhcpv4.PrintDHCPv4Summary() 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())
}
}