From 040736b81ad567e5041035951f975e9f07103e07 Mon Sep 17 00:00:00 2001 From: mzack Date: Tue, 15 Oct 2024 10:55:12 +0200 Subject: [PATCH] making icmp non fatal --- v2/pkg/scan/icmp.go | 6 ++++++ v2/pkg/scan/scan_unix.go | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/v2/pkg/scan/icmp.go b/v2/pkg/scan/icmp.go index d174918f..8c2baec1 100644 --- a/v2/pkg/scan/icmp.go +++ b/v2/pkg/scan/icmp.go @@ -177,6 +177,9 @@ func PingIcmpTimestampRequestAsync(ip string) { if !iputil.IsIPv4(ip) { return } + if icmpConn4 == nil { + return + } destAddr := &net.IPAddr{IP: net.ParseIP(ip)} m := icmp.Message{ Type: ipv4.ICMPTypeTimestamp, @@ -264,6 +267,9 @@ func PingIcmpAddressMaskRequestAsync(ip string) { if !iputil.IsIPv4(ip) { return } + if icmpConn4 == nil { + return + } destAddr := &net.IPAddr{IP: net.ParseIP(ip)} m := icmp.Message{ Type: ipv4.ICMPType(17), diff --git a/v2/pkg/scan/scan_unix.go b/v2/pkg/scan/scan_unix.go index e6d25a63..9af69567 100644 --- a/v2/pkg/scan/scan_unix.go +++ b/v2/pkg/scan/scan_unix.go @@ -51,7 +51,7 @@ func init() { var err error icmpConn4, err = icmp.ListenPacket("ip4:icmp", "0.0.0.0") if err != nil { - panic(err) + gologger.Error().Msgf("could not setup ip4:icmp: %s", err) } icmpConn6, err = icmp.ListenPacket("ip6:icmp", "::") @@ -381,6 +381,9 @@ func sendAsyncUDP6(listenHandler *ListenHandler, ip string, p *port.Port, pkgFla func (l *ListenHandler) ICMPReadWorker4() { data := make([]byte, 1500) for { + if icmpConn4 == nil { + return + } n, addr, err := icmpConn4.ReadFrom(data) if err != nil { continue