diff options
author | Pablo Mazzini <pmazzini@gmail.com> | 2018-08-10 16:00:59 +0200 |
---|---|---|
committer | Pablo Mazzini <pmazzini@gmail.com> | 2018-08-10 16:00:59 +0200 |
commit | f55d67dc49bee6d6aa20913f070ed771b9ff725a (patch) | |
tree | 2e96a2f52ab0bac9f06e0560208ab21bb2c4bb51 /dhcpv4 | |
parent | cff664d4ac7fe61377195a9d439e17259ce5899e (diff) |
rename IsRequested to IsRequestedOption
Diffstat (limited to 'dhcpv4')
-rw-r--r-- | dhcpv4/dhcpv4.go | 14 | ||||
-rw-r--r-- | dhcpv4/dhcpv4_test.go | 10 | ||||
-rw-r--r-- | dhcpv4/utils.go | 14 | ||||
-rw-r--r-- | dhcpv4/utils_test.go | 17 |
4 files changed, 24 insertions, 31 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index d670de2..3847425 100644 --- a/dhcpv4/dhcpv4.go +++ b/dhcpv4/dhcpv4.go @@ -682,6 +682,20 @@ func (d *DHCPv4) ValidateOptions() { } } +// IsOptionRequested function takes a DHCPv4 message and an OptionCode, and +// returns true if that option is within the requested options of the DHCPv4 +// message. +func (d *DHCPv4) IsOptionRequested(requested OptionCode) bool { + for _, optprl := range d.GetOption(OptionParameterRequestList) { + for _, o := range optprl.(*OptParameterRequestList).RequestedOpts { + if o == requested { + return true + } + } + } + return false +} + // ToBytes encodes a DHCPv4 structure into a sequence of bytes in its wire // format. func (d *DHCPv4) ToBytes() []byte { diff --git a/dhcpv4/dhcpv4_test.go b/dhcpv4/dhcpv4_test.go index 1bce05d..a594890 100644 --- a/dhcpv4/dhcpv4_test.go +++ b/dhcpv4/dhcpv4_test.go @@ -401,6 +401,16 @@ func TestDHCPv4MessageTypeDiscovery(t *testing.T) { require.Equal(t, MessageTypeDiscover, *m.MessageType()) } +func TestIsOptionRequested(t *testing.T) { + pkt, err := New() + require.NoError(t, err) + require.False(t, pkt.IsOptionRequested(OptionDomainNameServer)) + + optprl := OptParameterRequestList{RequestedOpts: []OptionCode{OptionDomainNameServer}} + pkt.AddOption(&optprl) + require.True(t, pkt.IsOptionRequested(OptionDomainNameServer)) +} + // TODO // test broadcast/unicast flags // test Options setter/getter diff --git a/dhcpv4/utils.go b/dhcpv4/utils.go deleted file mode 100644 index fed0679..0000000 --- a/dhcpv4/utils.go +++ /dev/null @@ -1,14 +0,0 @@ -package dhcpv4 - -// IsRequested function takes a DHCPv4 message and an OptionCode, and returns -// true if that option is within the requested options of the DHCPv4 message. -func IsRequested(pkt *DHCPv4, requested OptionCode) bool { - for _, optprl := range pkt.GetOption(OptionParameterRequestList) { - for _, o := range optprl.(*OptParameterRequestList).RequestedOpts { - if o == requested { - return true - } - } - } - return false -} diff --git a/dhcpv4/utils_test.go b/dhcpv4/utils_test.go deleted file mode 100644 index d722466..0000000 --- a/dhcpv4/utils_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package dhcpv4 - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func TestIsRequetsed(t *testing.T) { - pkt, err := New() - require.NoError(t, err) - require.False(t, IsRequested(pkt, OptionDomainNameServer)) - - optprl := OptParameterRequestList{RequestedOpts: []OptionCode{OptionDomainNameServer}} - pkt.AddOption(&optprl) - require.True(t, IsRequested(pkt, OptionDomainNameServer)) -} |