diff options
-rw-r--r-- | dhcpv4/client.go | 14 | ||||
-rw-r--r-- | dhcpv4/dhcpv4.go | 4 | ||||
-rw-r--r-- | dhcpv4/dhcpv4_test.go | 8 | ||||
-rw-r--r-- | dhcpv4/option_bootfile_name.go | 2 | ||||
-rw-r--r-- | dhcpv4/option_bootfile_name_test.go | 5 | ||||
-rw-r--r-- | dhcpv4/option_tftp_server_name.go | 2 | ||||
-rw-r--r-- | dhcpv4/option_tftp_server_name_test.go | 5 |
7 files changed, 25 insertions, 15 deletions
diff --git a/dhcpv4/client.go b/dhcpv4/client.go index db7e71a..9fd8501 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, modifiers ...Modifier) ([]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. @@ -148,28 +148,28 @@ func (c *Client) Exchange(ifname string, discover *DHCPv4, modifiers ...Modifier for _, mod := range modifiers { discover = mod(discover) } - conversation[0] = *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, modifiers...) + 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 } diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index d670de2..5005375 100644 --- a/dhcpv4/dhcpv4.go +++ b/dhcpv4/dhcpv4.go @@ -187,8 +187,8 @@ func NewInformForInterface(ifname string, needsBroadcast bool) (*DHCPv4, error) return d, nil } -// RequestFromOffer builds a DHCPv4 request from an offer. -func RequestFromOffer(offer DHCPv4, modifiers ...Modifier) (*DHCPv4, error) { +// NewRequestFromOffer builds a DHCPv4 request from an offer. +func NewRequestFromOffer(offer *DHCPv4, modifiers ...Modifier) (*DHCPv4, error) { d, err := New() if err != nil { return nil, err diff --git a/dhcpv4/dhcpv4_test.go b/dhcpv4/dhcpv4_test.go index 1bce05d..6e3394c 100644 --- a/dhcpv4/dhcpv4_test.go +++ b/dhcpv4/dhcpv4_test.go @@ -342,24 +342,24 @@ func TestAddOption(t *testing.T) { require.Equal(t, options[3].Code(), OptionEnd) } -func TestDHCPv4RequestFromOffer(t *testing.T) { +func TestDHCPv4NewRequestFromOffer(t *testing.T) { offer, err := New() require.NoError(t, err) offer.AddOption(&OptMessageType{MessageType: MessageTypeOffer}) offer.AddOption(&OptServerIdentifier{ServerID: net.IPv4(192, 168, 0, 1)}) - req, err := RequestFromOffer(*offer) + req, err := NewRequestFromOffer(offer) require.NoError(t, err) require.NotEqual(t, (*MessageType)(nil), *req.MessageType()) require.Equal(t, MessageTypeRequest, *req.MessageType()) } -func TestDHCPv4RequestFromOfferWithModifier(t *testing.T) { +func TestDHCPv4NewRequestFromOfferWithModifier(t *testing.T) { offer, err := New() require.NoError(t, err) offer.AddOption(&OptMessageType{MessageType: MessageTypeOffer}) offer.AddOption(&OptServerIdentifier{ServerID: net.IPv4(192, 168, 0, 1)}) userClass := WithUserClass([]byte("linuxboot"), false) - req, err := RequestFromOffer(*offer, userClass) + req, err := NewRequestFromOffer(offer, userClass) require.NoError(t, err) require.NotEqual(t, (*MessageType)(nil), *req.MessageType()) require.Equal(t, MessageTypeRequest, *req.MessageType()) diff --git a/dhcpv4/option_bootfile_name.go b/dhcpv4/option_bootfile_name.go index 73ea625..ca9317b 100644 --- a/dhcpv4/option_bootfile_name.go +++ b/dhcpv4/option_bootfile_name.go @@ -28,7 +28,7 @@ func (op *OptBootfileName) Length() int { } func (op *OptBootfileName) String() string { - return fmt.Sprintf("OptBootfileName{BootfileName=%s}", op.BootfileName) + return fmt.Sprintf("Bootfile Name -> %s", op.BootfileName) } diff --git a/dhcpv4/option_bootfile_name_test.go b/dhcpv4/option_bootfile_name_test.go index 1f66807..0c7c200 100644 --- a/dhcpv4/option_bootfile_name_test.go +++ b/dhcpv4/option_bootfile_name_test.go @@ -58,3 +58,8 @@ func TestParseOptBootfileNameShortLength(t *testing.T) { require.NoError(t, err) require.Equal(t, []byte("linu"), opt.BootfileName) } + +func TestOptBootfileNameString(t *testing.T) { + o := OptBootfileName{BootfileName: []byte("testy test")} + require.Equal(t, "Bootfile Name -> testy test", o.String()) +} diff --git a/dhcpv4/option_tftp_server_name.go b/dhcpv4/option_tftp_server_name.go index b4029e1..19dde21 100644 --- a/dhcpv4/option_tftp_server_name.go +++ b/dhcpv4/option_tftp_server_name.go @@ -28,7 +28,7 @@ func (op *OptTFTPServerName) Length() int { } func (op *OptTFTPServerName) String() string { - return fmt.Sprintf("OptTFTPServerName{TFTPServerName=%s}", op.TFTPServerName) + return fmt.Sprintf("TFTP Server Name -> %s", op.TFTPServerName) } // ParseOptTFTPServerName returns a new OptTFTPServerName fomr a byte stream or error if any diff --git a/dhcpv4/option_tftp_server_name_test.go b/dhcpv4/option_tftp_server_name_test.go index caddf95..812210f 100644 --- a/dhcpv4/option_tftp_server_name_test.go +++ b/dhcpv4/option_tftp_server_name_test.go @@ -58,3 +58,8 @@ func TestParseOptTFTPServerNameShortLength(t *testing.T) { require.NoError(t, err) require.Equal(t, []byte("linu"), opt.TFTPServerName) } + +func TestOptTFTPServerNameString(t *testing.T) { + o := OptTFTPServerName{TFTPServerName: []byte("testy test")} + require.Equal(t, "TFTP Server Name -> testy test", o.String()) +} |