func (p *Pinger) AddIPAddr(ip *net.IPAddr) {
	p.mu.Lock()
	p.addrs[ip.String()] = ip
	if isIPv4(ip.IP) {
		p.hasIPv4 = true
	} else if isIPv6(ip.IP) {
		p.hasIPv6 = true
	}
	p.mu.Unlock()
}
AddIPAddr adds an IP address to Pinger. ip arg should be a net.IPAddr
pointer.
package fastping
import (
	"errors"
	"fmt"
	"log"
	"math/rand"
	"net"
	"sync"
	"syscall"
	"time"
)
const TimeSliceLength = 8
func byteSliceOfSize(n int) []byte {
	b := make([]byte, n)
	for i := 0; i < len(b); i++ {
		b[i] = 1
	}
	return b
}
func timeToBytes(t time.Time) []byte {
	nsec := t.UnixNano()
	b := make([]byte, 8)
	for i := uint8(0); i < 8; i++ {
		b[i] = byte((nsec >> ((7 - i) * 8)) & 0xff)
	}
	return b
}
func bytesToTime(b []byte) time.Time {
	var nsec int64
	for i := uint8(0); i < 8; i++ {
		nsec += int64(b[i]) << ((7 - i) * 8)
	}
	return time.Unix(nsec/1000000000, nsec%1000000000)
}
func isIPv4(ip net.IP) bool {
	return len(ip.To4()) == net.IPv4len
}
func isIPv6(ip net.IP) bool {
	return len(ip) == net.IPv6len
}
type packet struct {
	bytes []byte
	addr  *net.IPAddr
}
type context struct {
	stop chan bool
	done chan bool
	err  error
}
func newContext() *context {
	return &context{
		stop: make(chan bool),
		done: make(chan bool),
	}
}
type Pinger struct {
	id  int
	seq int
	addrs   map[string]*net.IPAddr
	hasIPv4 bool
	hasIPv6 bool
	ctx     *context
	mu      sync.Mutex
	Size int
	MaxRTT time.Duration
	ListenAddr *net.IPAddr
	OnRecv func(*net.IPAddr, time.Duration)
	OnIdle func()
	OnErr  func(*net.IPAddr, int)
	Debug bool
}
func NewPinger() *Pinger {
	rand.Seed(time.Now().UnixNano())
	return &Pinger{
		id:      rand.Intn(0xffff),
		seq:     rand.Intn(0xffff),
		addrs:   make(map[string]*net.IPAddr),
		hasIPv4: false,
		hasIPv6: false,
		Size:    TimeSliceLength,
		MaxRTT:  time.Second,
		OnRecv:  nil,
		OnIdle:  nil,
		Debug:   false,
	}
}
func (p *Pinger) AddIP(ipaddr string) error {
	addr := net.ParseIP(ipaddr)
	if addr == nil {
		return fmt.Errorf("%s is not a valid textual representation of an IP address", ipaddr)
	}
	p.mu.Lock()
	p.addrs[addr.String()] = &net.IPAddr{IP: addr}
	if isIPv4(addr) {
		p.hasIPv4 = true
	} else if isIPv6(addr) {
		p.hasIPv6 = true
	}
	p.mu.Unlock()
	return nil
}