From 0aff95a78c91a2983a90e7c964120d480234babf Mon Sep 17 00:00:00 2001 From: Andrea Barberio Date: Tue, 17 Apr 2018 14:52:26 +0100 Subject: dhcpv6: added DHCPv6Message.UpdateOption --- dhcpv6/dhcpv6message.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'dhcpv6') diff --git a/dhcpv6/dhcpv6message.go b/dhcpv6/dhcpv6message.go index db29a44..e7e6bda 100644 --- a/dhcpv6/dhcpv6message.go +++ b/dhcpv6/dhcpv6message.go @@ -4,10 +4,11 @@ import ( "crypto/rand" "encoding/binary" "fmt" - "github.com/insomniacslk/dhcp/iana" "log" "net" "time" + + "github.com/insomniacslk/dhcp/iana" ) const MessageHeaderSize = 4 @@ -201,6 +202,16 @@ func (d *DHCPv6Message) AddOption(option Option) { d.options = append(d.options, option) } +func (d *DHCPv6Message) UpdateOption(option Option) { + for idx, opt := range d.options { + if opt.Code() == option.Code() { + d.options[idx] = option + // don't look further + break + } + } +} + func (d *DHCPv6Message) String() string { return fmt.Sprintf("DHCPv6Message(messageType=%v transactionID=0x%06x, %d options)", d.MessageTypeToString(), d.TransactionID(), len(d.options), -- cgit v1.2.3