diff options
author | Sean Karlage <skarlage@fb.com> | 2018-03-10 09:40:05 -0800 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2018-03-10 19:40:51 +0000 |
commit | abdd176f80b47882b4fb6982c035471ced6e50fd (patch) | |
tree | ab81ed09f719ed2173ec8b61817b07ab987e74a3 /dhcpv4/bsdp/client.go | |
parent | 1ad5e5b04af130aaf5477f746c09688973584d9e (diff) |
Move Exchange back to method on client, rebase
Diffstat (limited to 'dhcpv4/bsdp/client.go')
-rw-r--r-- | dhcpv4/bsdp/client.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/dhcpv4/bsdp/client.go b/dhcpv4/bsdp/client.go index 00e5ad5..f64f035 100644 --- a/dhcpv4/bsdp/client.go +++ b/dhcpv4/bsdp/client.go @@ -8,9 +8,23 @@ import ( "github.com/insomniacslk/dhcp/dhcpv4" ) +// Client represents a BSDP client that can perform BSDP exchanges via the +// broadcast address. +type Client 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, + } +} + // Exchange runs a full BSDP exchange (Inform[list], Ack, Inform[select], // Ack). Returns a list of DHCPv4 structures representing the exchange. -func Exchange(client *dhcpv4.Client, ifname string, informList *dhcpv4.DHCPv4) ([]dhcpv4.DHCPv4, error) { +func (c *Client) Exchange(ifname string, informList *dhcpv4.DHCPv4) ([]dhcpv4.DHCPv4, error) { conversation := make([]dhcpv4.DHCPv4, 1) var err error @@ -30,7 +44,7 @@ func Exchange(client *dhcpv4.Client, ifname string, informList *dhcpv4.DHCPv4) ( conversation[0] = *informList // ACK[LIST] - ackForList, err := dhcpv4.SendReceive(client, fd, informList) + ackForList, err := dhcpv4.BroadcastSendReceive(fd, informList, c.ReadTimeout, c.WriteTimeout) if err != nil { return conversation, err } @@ -53,7 +67,7 @@ func Exchange(client *dhcpv4.Client, ifname string, informList *dhcpv4.DHCPv4) ( conversation = append(conversation, *informSelect) // ACK[SELECT] - ackForSelect, err := dhcpv4.SendReceive(client, fd, informSelect) + ackForSelect, err := dhcpv4.BroadcastSendReceive(fd, informSelect, c.ReadTimeout, c.WriteTimeout) if err != nil { return conversation, err } |