File: option.go

package info (click to toggle)
golang-github-d2g-dhcp4 0.0~git20150413-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 76 kB
  • sloc: makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,047 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package dhcp4

type OptionCode byte

type Option struct {
	Code  OptionCode
	Value []byte
}

// Map of DHCP options
type Options map[OptionCode][]byte

// SelectOrderOrAll has same functionality as SelectOrder, except if the order
// param is nil, whereby all options are added (in arbitary order).
func (o Options) SelectOrderOrAll(order []byte) []Option {
	if order == nil {
		opts := make([]Option, 0, len(o))
		for i, v := range o {
			opts = append(opts, Option{Code: i, Value: v})
		}
		return opts
	}
	return o.SelectOrder(order)
}

// SelectOrder returns a slice of options ordered and selected by a byte array
// usually defined by OptionParameterRequestList.  This result is expected to be
// used in ReplyPacket()'s []Option parameter.
func (o Options) SelectOrder(order []byte) []Option {
	opts := make([]Option, 0, len(order))
	for _, v := range order {
		if data, ok := o[OptionCode(v)]; ok {
			opts = append(opts, Option{Code: OptionCode(v), Value: data})
		}
	}
	return opts
}

type OpCode byte
type MessageType byte // Option 53