diff options
-rw-r--r-- | dhcpv6/client.go | 7 | ||||
-rw-r--r-- | dhcpv6/server_test.go | 8 |
2 files changed, 13 insertions, 2 deletions
diff --git a/dhcpv6/client.go b/dhcpv6/client.go index 10a20c9..24b6e0d 100644 --- a/dhcpv6/client.go +++ b/dhcpv6/client.go @@ -127,6 +127,13 @@ func (c *Client) sendReceive(ifname string, packet DHCPv6, expectedType MessageT return nil, err } defer conn.Close() + // wait for the listener to be ready + for { + if conn.LocalAddr() != nil { + break + } + time.Sleep(10 * time.Millisecond) + } // send the packet out conn.SetWriteDeadline(time.Now().Add(c.WriteTimeout)) diff --git a/dhcpv6/server_test.go b/dhcpv6/server_test.go index 4fc919b..066fe3a 100644 --- a/dhcpv6/server_test.go +++ b/dhcpv6/server_test.go @@ -59,8 +59,12 @@ func TestNewServer(t *testing.T) { func TestServerActivateAndServe(t *testing.T) { handler := func(conn net.PacketConn, peer net.Addr, m DHCPv6) { - log.Printf("MESSAGE from %s, reply with %v", peer, m.ToBytes()) - if _, err := conn.WriteTo(m.ToBytes(), peer); err != nil { + adv, err := NewAdvertiseFromSolicit(m) + if err != nil { + log.Printf("NewAdvertiseFromSolicit failed: %v", err) + return + } + if _, err := conn.WriteTo(adv.ToBytes(), peer); err != nil { log.Printf("Cannot reply to client: %v", err) } } |