blob: 1f99196f0180e6a3fcbb8d8847ab56948f16cd5e (
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
52
53
|
package bsdp
import (
"strings"
"github.com/insomniacslk/dhcp/dhcpv4"
"github.com/u-root/u-root/pkg/uio"
)
// BootImageList contains a list of boot images presented by a netboot server.
//
// Implements the BSDP option listing the boot images.
type BootImageList []BootImage
// FromBytes deserializes data into bil.
func (bil *BootImageList) FromBytes(data []byte) error {
buf := uio.NewBigEndianBuffer(data)
for buf.Has(5) {
var image BootImage
if err := image.Unmarshal(buf); err != nil {
return err
}
*bil = append(*bil, image)
}
return nil
}
// ToBytes returns a serialized stream of bytes for this option.
func (bil BootImageList) ToBytes() []byte {
buf := uio.NewBigEndianBuffer(nil)
for _, image := range bil {
image.Marshal(buf)
}
return buf.Data()
}
// String returns a human-readable string for this option.
func (bil BootImageList) String() string {
s := make([]string, 0, len(bil))
for _, image := range bil {
s = append(s, image.String())
}
return strings.Join(s, ", ")
}
// OptBootImageList returns a new BSDP boot image list.
func OptBootImageList(b ...BootImage) dhcpv4.Option {
return dhcpv4.Option{
Code: OptionBootImageList,
Value: BootImageList(b),
}
}
|