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

How is SetDeadline supposed to work? #12

Closed
sbromberger opened this issue Sep 29, 2017 · 8 comments
Closed

How is SetDeadline supposed to work? #12

sbromberger opened this issue Sep 29, 2017 · 8 comments

Comments

@sbromberger
Copy link
Contributor

sbromberger commented Sep 29, 2017

My code:

	arpInterface, err := net.InterfaceByName("en0"); if err != nil {
		panic("Cannot open en0")
	}
	arpClient, err := arp.Dial(arpInterface); if err != nil {
		panic("sendArp: Cannot bind client to interface")
	}

	fmt.Println("ip = ", ip)
	timeout := time.Now().Add(3*time.Second)
	fmt.Println("timeout set to ", timeout )
	arpClient.SetDeadline(timeout)
	macaddr, err := arpClient.Resolve(ip); if err != nil {
		fmt.Println("Request error is ", err)
	} else {
		fmt.Println("Resolved ", ip, " to ", macaddr)
	}

When I try to resolve a nonexistent IP, arpClient.Resolve() hangs indefinitely. I'd like to specify a timeout, and I thought that SetDeadline or SetReadDeadline would work. Obviously I'm doing something wrong. Advice appreciated.

@mdlayher
Copy link
Owner

Are you running a Mac? If so, you should see an unimplemented error in the return value of SetDeadline. Definitely check the error return value.

@sbromberger
Copy link
Contributor Author

@mdlayher oh, yeah, I'm on a mac. I didn't realize there was an error return value. Sorry about that!

@sbromberger
Copy link
Contributor Author

Is there an alternative for us mac users that might also be portable to Linux?

@mdlayher
Copy link
Owner

No worries. The package itself works on Linux, Mac, and BSD, but timeouts are only implemented on Linux, and using a hack at that. If we could gain access to the runtime network poller, that would solve the problem, but it hasn't happened yet.

Unfortunately I don't have a better solution at this time, other than maybe using goroutines and select to close the raw socket on a timeout. It's a hack though.

@sbromberger
Copy link
Contributor Author

Is there any way to make an ARP request and return with the mac address or after a timeout? Could I do this with Request and Read somehow?

(Sorry for the basic questions. Still trying to get a feel for the language.)

@mdlayher
Copy link
Owner

That's basically how Resolve works, but since timeouts aren't implemented, it'll block indefinitely on the call to Read.

@sbromberger
Copy link
Contributor Author

ah, I understand now. Thanks. I appreciate the help.

@sbromberger
Copy link
Contributor Author

Perhaps beating a dead horse here, but I'm trying to run this in an Ubuntu docker container and it's not working. SetDeadline is not returning an error, but the call to Resolve is hanging. Any ideas?

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

No branches or pull requests

2 participants