Skip to content
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

Merged
merged 2 commits into from
Mar 20, 2024
Merged

Added experiential icmp based ping functionality #105

merged 2 commits into from
Mar 20, 2024

Conversation

ShocOne
Copy link
Contributor

@ShocOne ShocOne commented Mar 20, 2024

Change

Thank you for your contribution !
Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context.
List any dependencies that are required for this change.

Type of Change

Please DELETE options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update (Wiki)

Checklist

  • I'm sure there are no other open Pull Requests for the same update/change
  • My corresponding pipelines / checks run clean and green without any errors or warnings
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (readme)
  • I did format my code

@ShocOne ShocOne merged commit 371bf72 into main Mar 20, 2024
5 checks passed
}
} 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

Errors unhandled.
// 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

Errors unhandled.
// 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

Errors unhandled.
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

Errors unhandled.

// 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

Errors unhandled.

// 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

Errors unhandled.
// 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

Errors unhandled.
// 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

Errors unhandled.
// 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

Errors unhandled.
@ShocOne ShocOne deleted the dev branch March 25, 2024 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant