Skip to content

Commit

Permalink
Make IsOptionRequested() work with GenericOptionCode
Browse files Browse the repository at this point in the history
Fixes #511

Signed-off-by: Brian Candler <[email protected]>
  • Loading branch information
candlerb committed Apr 14, 2024
1 parent c728f5d commit a328c9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dhcpv4/dhcpv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func (d *DHCPv4) IsOptionRequested(requested OptionCode) bool {
}

for _, o := range rq {
if o == requested {
if o.Code() == requested.Code() {
return true
}
}
Expand Down
13 changes: 13 additions & 0 deletions dhcpv4/dhcpv4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,19 @@ func TestIsOptionRequested(t *testing.T) {
require.True(t, pkt.IsOptionRequested(OptionDomainNameServer))
}

func TestIsGenericOptionRequested(t *testing.T) {
pkt, err := New()
require.NoError(t, err)

var genericOption224 = GenericOptionCode(224)
var genericOption225 = GenericOptionCode(225)
pkt.UpdateOption(OptParameterRequestList(OptionBroadcastAddress, genericOption224))
require.True(t, pkt.IsOptionRequested(OptionBroadcastAddress))
require.False(t, pkt.IsOptionRequested(OptionSwapServer))
require.True(t, pkt.IsOptionRequested(genericOption224), "Did not detect generic option 224 in <%v>", pkt.ParameterRequestList())
require.False(t, pkt.IsOptionRequested(genericOption225), "Detected generic option 225 in <%v>", pkt.ParameterRequestList())
}

// TODO
// test Summary() and String()
func TestSummary(t *testing.T) {
Expand Down

0 comments on commit a328c9d

Please sign in to comment.