diff options
Diffstat (limited to 'dhcpv4')
-rw-r--r-- | dhcpv4/utils.go | 14 | ||||
-rw-r--r-- | dhcpv4/utils_test.go | 17 |
2 files changed, 31 insertions, 0 deletions
diff --git a/dhcpv4/utils.go b/dhcpv4/utils.go new file mode 100644 index 0000000..d95f586 --- /dev/null +++ b/dhcpv4/utils.go @@ -0,0 +1,14 @@ +package dhcpv4 + +// IsRequested function takes a DHCPv4 message and an OptionCode, and returns +// true if that option is within the requested options of the DHCPv6 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 new file mode 100644 index 0000000..d722466 --- /dev/null +++ b/dhcpv4/utils_test.go @@ -0,0 +1,17 @@ +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)) +} |