dhcp4: fix portable Conn initialization and packet transmission.

Conn is supposed to accept "" to mean "listen for DHCP on all interfaces",
but portableConn didn't correctly handle that.

And I got the comparison wrong on ifidx in the portable send function, so
packets got sent out entirely the wrong interface :(.
This commit is contained in:
David Anderson 2016-07-16 22:22:42 -07:00
parent 684f93040b
commit c9ec51e475

View File

@ -167,6 +167,9 @@ type portableConn struct {
}
func newPortableConn(addr string) (conn, error) {
if addr == "" {
addr = ":67"
}
c, err := net.ListenPacket("udp4", addr)
if err != nil {
return nil, err
@ -192,7 +195,7 @@ func (c *portableConn) Recv(b []byte) (rb []byte, addr *net.UDPAddr, ifidx int,
}
func (c *portableConn) Send(b []byte, addr *net.UDPAddr, ifidx int) error {
if ifidx > 0 {
if ifidx <= 0 {
_, err := c.conn.WriteTo(b, nil, addr)
return err
}