diff options
author | Andrea Barberio <insomniac@slackware.it> | 2018-09-30 11:48:25 +0000 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2018-09-30 22:51:55 +0200 |
commit | 884667ec282b43650c4d3a50530e2753f3919448 (patch) | |
tree | 6e7e61ee254a2e6f171e7b1ea17e47ed1f249ab3 | |
parent | 82aa6a6cc8ea2b0a7961383b3248ba4bad6a14f5 (diff) |
Added listener timeout to the dhcpv6 client
-rw-r--r-- | dhcpv6/client.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/dhcpv6/client.go b/dhcpv6/client.go index 24b6e0d..79653c8 100644 --- a/dhcpv6/client.go +++ b/dhcpv6/client.go @@ -1,6 +1,7 @@ package dhcpv6 import ( + "errors" "fmt" "net" "time" @@ -127,8 +128,12 @@ func (c *Client) sendReceive(ifname string, packet DHCPv6, expectedType MessageT return nil, err } defer conn.Close() - // wait for the listener to be ready + // wait for the listener to be ready, fail if it takes too much time + deadline := time.Now().Add(time.Second) for { + if now := time.Now(); now.After(deadline) { + return nil, errors.New("Timed out waiting for listener to be ready") + } if conn.LocalAddr() != nil { break } |