summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4
diff options
context:
space:
mode:
authorAndrea Barberio <insomniac@slackware.it>2018-02-02 11:17:24 +0000
committerAndrea Barberio <insomniac@slackware.it>2018-02-02 11:17:24 +0000
commit4c5035ac053ead7e58def7e6e5c67402eb910bca (patch)
tree785f3f3491554edb633dcf27528d7ddf0cc0fdaf /dhcpv4
parenta28d7b9f5dabbc4387ca744d54e2a57ef07a5bd6 (diff)
Changed API from NewDiscovery to NewDiscoveryForInterface
Diffstat (limited to 'dhcpv4')
-rw-r--r--dhcpv4/client.go10
-rw-r--r--dhcpv4/dhcpv4.go10
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,