diff options
Diffstat (limited to 'dhcpv4')
-rw-r--r-- | dhcpv4/client.go | 10 | ||||
-rw-r--r-- | dhcpv4/dhcpv4.go | 10 |
2 files changed, 9 insertions, 11 deletions
diff --git a/dhcpv4/client.go b/dhcpv4/client.go index cc3a13f..145a7ef 100644 --- a/dhcpv4/client.go +++ b/dhcpv4/client.go @@ -55,15 +55,7 @@ func (c *Client) Exchange(ifname string, d *DHCPv4) ([]DHCPv4, error) { // Discovery if d == nil { - d, err = NewDiscovery() - if err != nil { - return conversation, err - } - iface, err := net.InterfaceByName(ifname) - if err != nil { - return conversation, err - } - d.SetClientHwAddr(iface.HardwareAddr) + d, err = NewDiscoveryForInterface(ifname) } conversation[0] = *d diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index 5f01952..0df8cc6 100644 --- a/dhcpv4/dhcpv4.go +++ b/dhcpv4/dhcpv4.go @@ -81,14 +81,20 @@ func New() (*DHCPv4, error) { // Will build a new DHCPv4 Discovery message, with a default Ethernet HW type // and a null hardware address. The caller needs to fill the remaining fields up -func NewDiscovery() (*DHCPv4, error) { +func NewDiscoveryForInterface(ifname string) (*DHCPv4, error) { d, err := New() if err != nil { return nil, err } + // get hw addr + iface, err := net.InterfaceByName(ifname) + if err != nil { + return nil, err + } d.SetOpcode(OpcodeBootRequest) d.SetHwType(iana.HwTypeEthernet) - d.SetHwAddrLen(6) + d.SetHwAddrLen(uint8(len(iface.HardwareAddr))) + d.SetClientHwAddr(iface.HardwareAddr) d.SetBroadcast() d.AddOption(Option{ Code: OptionDHCPMessageType, |