-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added experiential icmp based ping functionality #105
Conversation
} | ||
} else { | ||
// Handle the case where the type assertion fails | ||
log.Error("Failed to assert ICMP message type") |
Check warning
Code scanning / gosec
Errors unhandled. Warning
// Check if the message is an ICMP Echo Reply | ||
if echoReply, ok := parsedMsg.Type.(*ipv4.ICMPType); ok { | ||
if *echoReply != ipv4.ICMPTypeEchoReply { | ||
log.Error("Did not receive ICMP Echo Reply", zap.String("received_type", echoReply.String())) |
Check warning
Code scanning / gosec
Errors unhandled. Warning
// Parse the ICMP message from the reply | ||
parsedMsg, err := icmp.ParseMessage(1, reply[:n]) | ||
if err != nil { | ||
log.Error("Failed to parse ICMP message", zap.Error(err)) |
Check warning
Code scanning / gosec
Errors unhandled. Warning
reply := make([]byte, 1500) | ||
n, _, err := conn.ReadFrom(reply) | ||
if err != nil { | ||
log.Error("Failed to receive ICMP reply", zap.Error(err)) |
Check warning
Code scanning / gosec
Errors unhandled. Warning
|
||
// Set read timeout | ||
if err := conn.SetReadDeadline(time.Now().Add(timeout)); err != nil { | ||
log.Error("Failed to set read deadline", zap.Error(err)) |
Check warning
Code scanning / gosec
Errors unhandled. Warning
|
||
// Send the ICMP Echo Request message | ||
if _, err := conn.WriteTo(msgBytes, dst); err != nil { | ||
log.Error("Failed to send ICMP message", zap.Error(err)) |
Check warning
Code scanning / gosec
Errors unhandled. Warning
// Marshal the message into bytes | ||
msgBytes, err := msg.Marshal(nil) | ||
if err != nil { | ||
log.Error("Failed to marshal ICMP message", zap.Error(err)) |
Check warning
Code scanning / gosec
Errors unhandled. Warning
// Resolve the IP address of the host | ||
dst, err := net.ResolveIPAddr("ip4", host) | ||
if err != nil { | ||
log.Error("Failed to resolve IP address", zap.String("host", host), zap.Error(err)) |
Check warning
Code scanning / gosec
Errors unhandled. Warning
// Listen for ICMP replies | ||
conn, err := icmp.ListenPacket("ip4:icmp", "0.0.0.0") | ||
if err != nil { | ||
log.Error("Failed to listen for ICMP packets", zap.Error(err)) |
Check warning
Code scanning / gosec
Errors unhandled. Warning
Change
Type of Change
Please DELETE options that are not relevant.
Checklist