summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv4')
-rw-r--r--dhcpv4/dhcpv4.go13
-rw-r--r--dhcpv4/dhcpv4_test.go10
2 files changed, 23 insertions, 0 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go
index 5005375..ad6e319 100644
--- a/dhcpv4/dhcpv4.go
+++ b/dhcpv4/dhcpv4.go
@@ -682,6 +682,19 @@ func (d *DHCPv4) ValidateOptions() {
}
}
+// IsOptionRequested 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 6e3394c..eaa9266 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