blob: 4b1a828f1c2eab54fe749f1e83688804dd0ccef4 (
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
|
package dhcpv6
import (
"fmt"
"github.com/u-root/u-root/pkg/uio"
)
// OptServerId represents a Server ID option
//
// This module defines the OptServerId and DUID structures.
// https://www.ietf.org/rfc/rfc3315.txt
type OptServerId struct {
Sid Duid
}
func (op *OptServerId) Code() OptionCode {
return OptionServerID
}
// ToBytes serializes this option.
func (op *OptServerId) ToBytes() []byte {
buf := uio.NewBigEndianBuffer(nil)
buf.Write16(uint16(OptionServerID))
buf.Write16(uint16(op.Length()))
buf.WriteBytes(op.Sid.ToBytes())
return buf.Data()
}
func (op *OptServerId) Length() int {
return op.Sid.Length()
}
func (op *OptServerId) String() string {
return fmt.Sprintf("OptServerId{sid=%v}", op.Sid.String())
}
// ParseOptServerId builds an OptServerId structure from a sequence of bytes.
// The input data does not include option code and length bytes.
func ParseOptServerId(data []byte) (*OptServerId, error) {
var opt OptServerId
sid, err := DuidFromBytes(data)
if err != nil {
return nil, err
}
opt.Sid = *sid
return &opt, nil
}
|