Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

Before this change, I encountered panics like this one:

  panic: runtime error: invalid memory address or nil pointer dereference
  [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6bf24f]

  goroutine 205 [running]:
  github.com/digineo/go-ping.(*multiRequest).handleReply.func1(0xc0003bfe00, 0x0, 0x0, 0x0, 0x0)
  	/home/michael/go/pkg/mod/github.com/digineo/go-ping@v1.0.0/request.go:96 +0x8f
  created by github.com/digineo/go-ping.(*multiRequest).handleReply
  	/home/michael/go/pkg/mod/github.com/digineo/go-ping@v1.0.0/request.go:89
	+0x67

With an example program like this one:

  func repro() (string, error) {
	bind6 := "::"
	addr, err := net.ResolveIPAddr("ip", "ff02::2%enp3s0f1")
	if err != nil {
		return "", err
	}
	p, err := ping.New("", bind6)
	if err != nil {
		return "", err
	}
	defer p.Close()
	const timeout = 5 * time.Second
	ctx, canc := context.WithTimeout(context.Background(), timeout)
	defer canc()

	log.Printf("ff02:: code path")
	replies, err := p.PingMulticastContext(ctx, addr)
	if err != nil {
		return "", err
	}
	addrs, err := net.InterfaceAddrs()
	if err != nil {
		return "", err
	}
	localAddr := make(map[string]bool)
	for _, addr := range addrs {
		ipnet, ok := addr.(*net.IPNet)
		if !ok {
			continue
		}
		localAddr[ipnet.IP.String()] = true
	}
	for reply := range replies {
		if localAddr[reply.Address.String()] {
			continue
		}
		go func() {
			for range replies {
				// drain channel
			}
		}()
		return fmt.Sprint(reply.Duration) + " from " + reply.Address.String(), nil
	}
	return "", fmt.Errorf("no responses to %s within %v", addr, timeout)
  }
538351b

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
cmd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

go-ping

GoDoc Build Status Codecov Go Report Card

A simple ICMP Echo implementation, based on golang.org/x/net/icmp.

Some sample programs are provided in cmd/:

  • ping-test is a really simple ping clone
  • multiping provides an interactive TUI to ping multiple hosts
  • ping-monitor pings multiple hosts in parallel, but just prints the summary every so often
  • pingnet allows to ping every host in a CIDR range (e.g. 0.0.0.0/0 :-))

Features

  • IPv4 and IPv6 support
  • Unicast and multicast support
  • configurable retry amount and timeout duration
  • configurable payload size (and content)
  • round trip time measurement

Contribute

Simply fork and create a pull-request. We'll try to respond in a timely fashion.

Software using this library

Please create a pull request to get your software listed.

License

MIT License, Copyright (c) 2018 Digineo GmbH

https://www.digineo.de