Create UDP address directly. Also dropped address zone from destination address as it wasn't needed.

This commit is contained in:
Dmitri Dolguikh 2018-01-02 18:51:50 -08:00 committed by Dave Anderson
parent 08daa9f0da
commit 24498fac2f

View File

@ -109,12 +109,11 @@ func (c *Conn) RecvDHCP() (*Packet, net.IP, error) {
// SendDHCP sends a dhcp packet to the specified ip address using Conn // SendDHCP sends a dhcp packet to the specified ip address using Conn
func (c *Conn) SendDHCP(dst net.IP, p []byte) error { func (c *Conn) SendDHCP(dst net.IP, p []byte) error {
dstAddr, err := net.ResolveUDPAddr("udp6", fmt.Sprintf("[%s]:%s", dst.String() + "%en0", "546")) dstAddr := &net.UDPAddr{
if err != nil { IP: dst,
return fmt.Errorf("Error resolving ipv6 address %s: %s", dst.String(), err) Port: 546,
} }
_, err = c.conn.WriteTo(p, nil, dstAddr) _, err := c.conn.WriteTo(p, nil, dstAddr); if err != nil {
if err != nil {
return fmt.Errorf("Error sending a reply to %s: %s", dst.String(), err) return fmt.Errorf("Error sending a reply to %s: %s", dst.String(), err)
} }
return nil return nil