summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/client.go
diff options
context:
space:
mode:
authorSean Karlage <skarlage@fb.com>2018-08-11 14:30:48 -0700
committerSean Karlage <skarlage@fb.com>2018-08-11 14:32:26 -0700
commit8ea2525c898436a2a935580de67727bbe7035c85 (patch)
tree69d35d17c238feabb07ef07a907aae5520104911 /dhcpv4/client.go
parent2b05c7d03724d31529886d98f738499ac06ead7e (diff)
parenta6212f1f72e94821a29894fb66656a981bd035d0 (diff)
Merge branch 'master' into dhcpv4-moar-tests
Diffstat (limited to 'dhcpv4/client.go')
-rw-r--r--dhcpv4/client.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/dhcpv4/client.go b/dhcpv4/client.go
index 4b10240..8a44338 100644
--- a/dhcpv4/client.go
+++ b/dhcpv4/client.go
@@ -124,8 +124,8 @@ func MakeListeningSocket(ifname string) (int, 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) ([]DHCPv4, error) {
- conversation := make([]DHCPv4, 1)
+func (c *Client) Exchange(ifname string, discover *DHCPv4, modifiers ...Modifier) ([]*DHCPv4, error) {
+ conversation := make([]*DHCPv4, 1)
var err error
// Get our file descriptor for the broadcast socket.
@@ -149,28 +149,31 @@ func (c *Client) Exchange(ifname string, discover *DHCPv4) ([]DHCPv4, error) {
return conversation, err
}
}
- conversation[0] = *discover
+ for _, mod := range modifiers {
+ discover = mod(discover)
+ }
+ conversation[0] = discover
// Offer
offer, err := BroadcastSendReceive(sfd, rfd, discover, c.ReadTimeout, c.WriteTimeout, MessageTypeOffer)
if err != nil {
return conversation, err
}
- conversation = append(conversation, *offer)
+ conversation = append(conversation, offer)
// Request
- request, err := RequestFromOffer(*offer)
+ request, err := NewRequestFromOffer(offer, modifiers...)
if err != nil {
return conversation, err
}
- conversation = append(conversation, *request)
+ conversation = append(conversation, request)
// Ack
ack, err := BroadcastSendReceive(sfd, rfd, request, c.ReadTimeout, c.WriteTimeout, MessageTypeAck)
if err != nil {
return conversation, err
}
- conversation = append(conversation, *ack)
+ conversation = append(conversation, ack)
return conversation, nil
}