summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6
diff options
context:
space:
mode:
authorinsomniac <insomniacslk@users.noreply.github.com>2018-05-25 15:41:44 +0100
committerGitHub <noreply@github.com>2018-05-25 15:41:44 +0100
commitf9c923d97b0774c209d9bc492499970b8d5a0ed8 (patch)
treed7f4f62c2baba198b9474fcdec7f07bd000c1858 /dhcpv6
parentd37b622d85bdf14bc0922833053419dece4df243 (diff)
OptBootFileURL fields are now public (#68)
Diffstat (limited to 'dhcpv6')
-rw-r--r--dhcpv6/option_bootfileurl.go28
-rw-r--r--dhcpv6/option_bootfileurl_test.go4
2 files changed, 14 insertions, 18 deletions
diff --git a/dhcpv6/option_bootfileurl.go b/dhcpv6/option_bootfileurl.go
index 5857af1..e4817cb 100644
--- a/dhcpv6/option_bootfileurl.go
+++ b/dhcpv6/option_bootfileurl.go
@@ -8,42 +8,38 @@ import (
"fmt"
)
+// OptBootFileURL implements the OPT_BOOTFILE_URL option
type OptBootFileURL struct {
- bootFileUrl []byte
+ BootFileURL []byte
}
+// Code returns the option code
func (op *OptBootFileURL) Code() OptionCode {
return OPT_BOOTFILE_URL
}
+// ToBytes serializes the option and returns it as a sequence of bytes
func (op *OptBootFileURL) ToBytes() []byte {
buf := make([]byte, 4)
binary.BigEndian.PutUint16(buf[0:2], uint16(OPT_BOOTFILE_URL))
- binary.BigEndian.PutUint16(buf[2:4], uint16(len(op.bootFileUrl)))
- buf = append(buf, op.bootFileUrl...)
+ binary.BigEndian.PutUint16(buf[2:4], uint16(len(op.BootFileURL)))
+ buf = append(buf, op.BootFileURL...)
return buf
}
-func (op *OptBootFileURL) BootFileURL() []byte {
- return op.bootFileUrl
-}
-
-func (op *OptBootFileURL) SetBootFileURL(bootFileUrl []byte) {
- op.bootFileUrl = bootFileUrl
-}
-
+// Length returns the option length in bytes
func (op *OptBootFileURL) Length() int {
- return len(op.bootFileUrl)
+ return len(op.BootFileURL)
}
func (op *OptBootFileURL) String() string {
- return fmt.Sprintf("OptBootFileURL{BootFileUrl=%s}", op.bootFileUrl)
+ return fmt.Sprintf("OptBootFileURL{BootFileUrl=%s}", op.BootFileURL)
}
-// build an OptBootFileURL structure from a sequence of bytes.
-// The input data does not include option code and length bytes.
+// ParseOptBootFileURL builds an OptBootFileURL structure from a sequence
+// of bytes. The input data does not include option code and length bytes.
func ParseOptBootFileURL(data []byte) (*OptBootFileURL, error) {
opt := OptBootFileURL{}
- opt.bootFileUrl = append([]byte(nil), data...)
+ opt.BootFileURL = append([]byte(nil), data...)
return &opt, nil
}
diff --git a/dhcpv6/option_bootfileurl_test.go b/dhcpv6/option_bootfileurl_test.go
index b42fd7c..6f7e077 100644
--- a/dhcpv6/option_bootfileurl_test.go
+++ b/dhcpv6/option_bootfileurl_test.go
@@ -14,7 +14,7 @@ func TestOptBootFileURL(t *testing.T) {
if optLen := opt.Length(); optLen != len(expected) {
t.Fatalf("Invalid length. Expected %v, got %v", len(expected), optLen)
}
- if url := opt.BootFileURL(); !bytes.Equal(url, expected) {
+ if url := opt.BootFileURL; !bytes.Equal(url, expected) {
t.Fatalf("Invalid boot file URL. Expected %v, got %v", expected, url)
}
}
@@ -24,7 +24,7 @@ func TestOptBootFileURLToBytes(t *testing.T) {
expected := []byte{00, 59, 00, byte(len(urlString))}
expected = append(expected, urlString...)
opt := OptBootFileURL{
- bootFileUrl: urlString,
+ BootFileURL: urlString,
}
toBytes := opt.ToBytes()
if !bytes.Equal(toBytes, expected) {