diff options
author | Christopher Koch <chrisko@google.com> | 2018-12-29 09:16:15 -0800 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2019-01-11 19:38:21 +0000 |
commit | 9492662dae0651fd4d6698d35b58ade7300e149e (patch) | |
tree | 77f53ebd6dfded05880c322005909b97a1cf140c /dhcpv4/dhcpv4.go | |
parent | 512011c2eb80a7c0316405ef7aaae6e0b5b09b1c (diff) |
dhcpv4: simplify marshaling options to binary.
- Consolidate writing the option code and length to Options.Marshal
rather than doing it in each individual option.
- Use uio in marshaling code.
Diffstat (limited to 'dhcpv4/dhcpv4.go')
-rw-r--r-- | dhcpv4/dhcpv4.go | 30 |
1 files changed, 2 insertions, 28 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index 98f0eae..0f2a5b4 100644 --- a/dhcpv4/dhcpv4.go +++ b/dhcpv4/dhcpv4.go @@ -5,7 +5,6 @@ import ( "encoding/binary" "errors" "fmt" - "log" "net" "strings" @@ -472,29 +471,6 @@ func (d *DHCPv4) Summary() string { return ret } -// ValidateOptions runs sanity checks on the DHCPv4 packet and prints a number -// of warnings if something is incorrect. -func (d *DHCPv4) ValidateOptions() { - // TODO find duplicate options - foundOptionEnd := false - for _, opt := range d.Options { - if foundOptionEnd { - if opt.Code() == OptionEnd { - log.Print("Warning: found duplicate End option") - } - if opt.Code() != OptionEnd && opt.Code() != OptionPad { - log.Printf("Warning: found option %v (%v) after End option", opt.Code(), opt.Code().String()) - } - } - if opt.Code() == OptionEnd { - foundOptionEnd = true - } - } - if !foundOptionEnd { - log.Print("Warning: no End option found") - } -} - // IsOptionRequested returns true if that option is within the requested // options of the DHCPv4 message. func (d *DHCPv4) IsOptionRequested(requested OptionCode) bool { @@ -553,9 +529,7 @@ func (d *DHCPv4) ToBytes() []byte { // The magic cookie. buf.WriteBytes(magicCookie[:]) - - for _, opt := range d.Options { - buf.WriteBytes(opt.ToBytes()) - } + d.Options.Marshal(buf) + buf.Write8(uint8(OptionEnd)) return buf.Data() } |