diff options
Diffstat (limited to 'dhcpv4/bsdp/client.go')
-rw-r--r-- | dhcpv4/bsdp/client.go | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/dhcpv4/bsdp/client.go b/dhcpv4/bsdp/client.go index 255d54b..8131bec 100644 --- a/dhcpv4/bsdp/client.go +++ b/dhcpv4/bsdp/client.go @@ -8,16 +8,14 @@ import ( // Client represents a BSDP client that can perform BSDP exchanges via the // broadcast address. -type Client dhcpv4.Client +type Client struct { + dhcpv4.Client +} // NewClient constructs a new client with default read and write timeouts from // dhcpv4.Client. func NewClient() *Client { - c := dhcpv4.NewClient() - return &Client{ - ReadTimeout: c.ReadTimeout, - WriteTimeout: c.WriteTimeout, - } + return &Client{Client: dhcpv4.Client{}} } func castVendorOpt(ack *dhcpv4.DHCPv4) { @@ -37,8 +35,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) { - conversation := make([]*dhcpv4.DHCPv4, 1) - var err error + conversation := make([]*dhcpv4.DHCPv4, 0) // Get our file descriptor for the broadcast socket. sendFd, err := dhcpv4.MakeBroadcastSocket(ifname) @@ -57,10 +54,10 @@ func (c *Client) Exchange(ifname string, informList *dhcpv4.DHCPv4) ([]*dhcpv4.D return conversation, err } } - conversation[0] = informList + conversation = append(conversation, informList) // ACK[LIST] - ackForList, err := dhcpv4.BroadcastSendReceive(sendFd, recvFd, informList, c.ReadTimeout, c.WriteTimeout, dhcpv4.MessageTypeAck) + ackForList, err := c.Client.SendReceive(sendFd, recvFd, informList, dhcpv4.MessageTypeAck) if err != nil { return conversation, err } @@ -86,7 +83,7 @@ func (c *Client) Exchange(ifname string, informList *dhcpv4.DHCPv4) ([]*dhcpv4.D conversation = append(conversation, informSelect) // ACK[SELECT] - ackForSelect, err := dhcpv4.BroadcastSendReceive(sendFd, recvFd, informSelect, c.ReadTimeout, c.WriteTimeout, dhcpv4.MessageTypeAck) + ackForSelect, err := c.Client.SendReceive(sendFd, recvFd, informSelect, dhcpv4.MessageTypeAck) castVendorOpt(ackForSelect) if err != nil { return conversation, err |