x/net/icmp: Hogs CPU on Windows, doesn't capture packets #33117
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I would like to receive all incoming ICMP packets and their payload/message, and once I am able to do that I would like to filter said packets so only specific IP sources and/or payloads/messages are captured and logged.
I would like this to work on both Linux and Windows, but at the moment I am experiencing issues specifically on Windows (works as expected on Linux). Tested on a Window 7 64-bit virtual machine on VirtualBox (running on Arch Linux).
I'm using the code found in the accepted answer for this StackOverflow question, with slight alterations:
https://stackoverflow.com/questions/33345683/how-to-listen-for-icmp-packets
My code (running as Admin):
https://play.golang.org/p/RmuJmXgLKJk
I've replaced the IP address in
ListenPacket()
to the local address of the virtual machine on which I would like to log incoming ICMP packets (192.168.0.111
in Playground link, also tried0.0.0.0
).I've also added
if sourceIP == nil { continue }
so that only ICMP packets containing a source IP are displayed. Without this condition, I was seeing infinite logs displaying an empty message andnil
source address.When I ping the virtual machine on which this code is running, the program does not display any messages. Also, the program uses up a lot of CPU (%90-%99) and the machine almost freezes up.
What did you expect to see?
Logs of ICMP packets with source IP and message. Minimal CPU usage.
What did you see instead?
With
if sourceIP == nil { continue }
: No logs, program hogs CPU ~%98.Without
if sourceIP == nil { continue }
: Infinite logs, program uses %10-%20 CPU.The text was updated successfully, but these errors were encountered: