mdlayher / arp

Package arp implements the ARP protocol, as described in RFC 826. MIT Licensed.

Home Page:https://tools.ietf.org/html/rfc826

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linux (docker and raspberry pi): Resolve() not returning

sbromberger opened this issue · comments

I have the following code:

func sendArp(ip net.IP, arpClient *arp.Client, config chirpdconfig) (net.HardwareAddr, error) {

	l.Println("sendArp: in sendarp for ", ip)
	timeout := time.Now().Add(config.arpResponseTimeout)
	l.Println("sendArp: timeout = ", timeout)
	err := arpClient.SetDeadline(timeout)
	if  err != nil {
		panic(fmt.Sprintln("sendArp: cannot set deadline: ", err))
	}

	l.Println("sendArp: post SetDeadline")
	macaddr, err := arpClient.Resolve(ip)
	l.Println("sendArp: post Resolve")
	if err != nil {
		l.Println("sendArp: err = ", err)
	}
	l.Println("macaddr = ", macaddr)
	return macaddr, err
}

I get the following output:

2017/10/12 sendArp: in sendarp for  10.0.1.222
2017/10/12 sendArp: timeout =  2017-10-12 21:19:36.879028782 -0700 PDT m=+7.533864643
2017/10/12 sendArp: post SetDeadline

and then things just hang.

I understand from #12 that SetDeadline doesn't work on MacOS, so that might explain the linux/docker failure, but I tried this on a raspberry pi running raspbian and it's not working either. What am I doing wrong?

Update: this works as a standalone function, but when called from a goroutine that has the interface open for packet capture, it hangs as described.

I'm embarrassed. The problem was in SetDeadline - I was passing a value of 3 in to the duration, which was ns instead of seconds. It's working now that I got the units right. Sorry.