blob: d6547fe1fb8f2b64af13df2be7883f1595b6dcb7 (
plain)
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
41
42
43
44
45
46
47
48
49
50
51
|
package dhcpv4
import "fmt"
// This option implements the relay agent information option
// https://tools.ietf.org/html/rfc3046
// OptRelayAgentInformation is a "container" option for specific agent-supplied
// sub-options.
type OptRelayAgentInformation struct {
Options Options
}
// ParseOptRelayAgentInformation returns a new OptRelayAgentInformation from a
// byte stream, or error if any.
func ParseOptRelayAgentInformation(data []byte) (*OptRelayAgentInformation, error) {
options, err := OptionsFromBytesWithParser(data, ParseOptionGeneric, false /* don't check for OptionEnd tag */)
if err != nil {
return nil, err
}
return &OptRelayAgentInformation{Options: options}, nil
}
// Code returns the option code.
func (o *OptRelayAgentInformation) Code() OptionCode {
return OptionRelayAgentInformation
}
// ToBytes returns a serialized stream of bytes for this option.
func (o *OptRelayAgentInformation) ToBytes() []byte {
ret := []byte{byte(o.Code()), byte(o.Length())}
for _, opt := range o.Options {
ret = append(ret, opt.ToBytes()...)
}
return ret
}
// String returns a human-readable string for this option.
func (o *OptRelayAgentInformation) String() string {
return fmt.Sprintf("Relay Agent Information -> %v", o.Options)
}
// Length returns the length of the data portion (excluding option code and byte
// for length, if any).
func (o *OptRelayAgentInformation) Length() int {
l := 0
for _, opt := range o.Options {
l += 2 + opt.Length()
}
return l
}
|