Fix: dhcp client should request special interface

This commit is contained in:
Dreamacro
2021-10-05 13:31:19 +08:00
parent 4f1fac02ab
commit b9d470cf79
4 changed files with 21 additions and 11 deletions

View File

@ -15,9 +15,10 @@ import (
type client struct {
*D.Client
r *Resolver
port string
host string
r *Resolver
port string
host string
iface string
}
func (c *client) Exchange(m *D.Msg) (*D.Msg, error) {
@ -45,7 +46,11 @@ func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error)
network = "tcp"
}
conn, err := dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), c.port))
options := []dialer.Option{}
if c.iface != "" {
options = append(options, dialer.WithInterface(c.iface))
}
conn, err := dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), c.port), options...)
if err != nil {
return nil, err
}