diff options
author | Pablo Mazzini <pmazzini@gmail.com> | 2018-11-27 22:15:54 +0000 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2018-11-27 22:15:54 +0000 |
commit | 319e92b03a0b85eeaee17398b72ee759b2ccf905 (patch) | |
tree | 5c3427a22d5e293835b6f60f2d9c58187352eb33 /dhcpv4 | |
parent | ee4c6d2553989a433e4a13fb130616061558db48 (diff) |
simplify client interface (#181)
Diffstat (limited to 'dhcpv4')
-rw-r--r-- | dhcpv4/bsdp/client.go | 10 | ||||
-rw-r--r-- | dhcpv4/client.go | 10 | ||||
-rw-r--r-- | dhcpv4/server_test.go | 2 |
3 files changed, 9 insertions, 13 deletions
diff --git a/dhcpv4/bsdp/client.go b/dhcpv4/bsdp/client.go index 8131bec..dd9cbcd 100644 --- a/dhcpv4/bsdp/client.go +++ b/dhcpv4/bsdp/client.go @@ -34,7 +34,7 @@ func castVendorOpt(ack *dhcpv4.DHCPv4) { // Exchange runs a full BSDP exchange (Inform[list], Ack, Inform[select], // Ack). Returns a list of DHCPv4 structures representing the exchange. -func (c *Client) Exchange(ifname string, informList *dhcpv4.DHCPv4) ([]*dhcpv4.DHCPv4, error) { +func (c *Client) Exchange(ifname string) ([]*dhcpv4.DHCPv4, error) { conversation := make([]*dhcpv4.DHCPv4, 0) // Get our file descriptor for the broadcast socket. @@ -48,11 +48,9 @@ func (c *Client) Exchange(ifname string, informList *dhcpv4.DHCPv4) ([]*dhcpv4.D } // INFORM[LIST] - if informList == nil { - informList, err = NewInformListForInterface(ifname, dhcpv4.ClientPort) - if err != nil { - return conversation, err - } + informList, err := NewInformListForInterface(ifname, dhcpv4.ClientPort) + if err != nil { + return conversation, err } conversation = append(conversation, informList) diff --git a/dhcpv4/client.go b/dhcpv4/client.go index e9a9ff5..8ec1490 100644 --- a/dhcpv4/client.go +++ b/dhcpv4/client.go @@ -179,7 +179,7 @@ func (c *Client) getRemoteUDPAddr() (*net.UDPAddr, error) { // ordered as Discovery, Offer, Request and Acknowledge. In case of errors, an // error is returned, and the list of DHCPv4 objects will be shorted than 4, // containing all the sent and received DHCPv4 messages. -func (c *Client) Exchange(ifname string, discover *DHCPv4, modifiers ...Modifier) ([]*DHCPv4, error) { +func (c *Client) Exchange(ifname string, modifiers ...Modifier) ([]*DHCPv4, error) { conversation := make([]*DHCPv4, 0) raddr, err := c.getRemoteUDPAddr() if err != nil { @@ -220,11 +220,9 @@ func (c *Client) Exchange(ifname string, discover *DHCPv4, modifiers ...Modifier }() // Discover - if discover == nil { - discover, err = NewDiscoveryForInterface(ifname) - if err != nil { - return conversation, err - } + discover, err := NewDiscoveryForInterface(ifname) + if err != nil { + return conversation, err } for _, mod := range modifiers { discover = mod(discover) diff --git a/dhcpv4/server_test.go b/dhcpv4/server_test.go index d455786..ab426df 100644 --- a/dhcpv4/server_test.go +++ b/dhcpv4/server_test.go @@ -136,7 +136,7 @@ func TestServerActivateAndServe(t *testing.T) { WithHwAddr(hwaddr[:]), } - conv, err := c.Exchange(lo, nil, modifiers...) + conv, err := c.Exchange(lo, modifiers...) require.NoError(t, err) require.Equal(t, 4, len(conv)) for _, p := range conv { |