blob: e67cb4609eef6f699aa6095e9523cc60b098252c (
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
54
|
package bsdp
import (
"github.com/insomniacslk/dhcp/dhcpv4"
"github.com/u-root/u-root/pkg/uio"
)
// Implements the BSDP option listing the boot images.
// OptBootImageList contains the list of boot images presented by a netboot
// server.
type OptBootImageList struct {
Images []BootImage
}
// ParseOptBootImageList constructs an OptBootImageList struct from a sequence
// of bytes and returns it, or an error.
func ParseOptBootImageList(data []byte) (*OptBootImageList, error) {
buf := uio.NewBigEndianBuffer(data)
var bootImages []BootImage
for buf.Has(5) {
var image BootImage
if err := (&image).Unmarshal(buf); err != nil {
return nil, err
}
bootImages = append(bootImages, image)
}
return &OptBootImageList{bootImages}, nil
}
// Code returns the option code.
func (o *OptBootImageList) Code() dhcpv4.OptionCode {
return OptionBootImageList
}
// ToBytes returns a serialized stream of bytes for this option.
func (o *OptBootImageList) ToBytes() []byte {
buf := uio.NewBigEndianBuffer(nil)
for _, image := range o.Images {
image.Marshal(buf)
}
return buf.Data()
}
// String returns a human-readable string for this option.
func (o *OptBootImageList) String() string {
s := "BSDP Boot Image List ->"
for _, image := range o.Images {
s += "\n " + image.String()
}
return s
}
|