summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_string.go
blob: 76a2db2614cebc36a304f1239dfcb093d0fb089a (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package dhcpv4

import (
	"fmt"
)

// OptDomainName implements the domain name option described in RFC 2132,
// Section 3.17.
type OptDomainName struct {
	DomainName string
}

// ParseOptDomainName returns a new OptDomainName from a byte stream, or error
// if any.
func ParseOptDomainName(data []byte) (*OptDomainName, error) {
	return &OptDomainName{DomainName: string(data)}, nil
}

// Code returns the option code.
func (o *OptDomainName) Code() OptionCode {
	return OptionDomainName
}

// ToBytes returns a serialized stream of bytes for this option.
func (o *OptDomainName) ToBytes() []byte {
	return []byte(o.DomainName)
}

// String returns a human-readable string.
func (o *OptDomainName) String() string {
	return fmt.Sprintf("Domain Name -> %v", o.DomainName)
}

// OptHostName implements the host name option described by RFC 2132, Section
// 3.14.
type OptHostName struct {
	HostName string
}

// ParseOptHostName returns a new OptHostName from a byte stream, or error if
// any.
func ParseOptHostName(data []byte) (*OptHostName, error) {
	return &OptHostName{HostName: string(data)}, nil
}

// Code returns the option code.
func (o *OptHostName) Code() OptionCode {
	return OptionHostName
}

// ToBytes returns a serialized stream of bytes for this option.
func (o *OptHostName) ToBytes() []byte {
	return []byte(o.HostName)
}

// String returns a human-readable string.
func (o *OptHostName) String() string {
	return fmt.Sprintf("Host Name -> %v", o.HostName)
}

// OptRootPath implements the root path option described by RFC 2132, Section
// 3.19.
type OptRootPath struct {
	Path string
}

// ParseOptRootPath constructs an OptRootPath struct from a sequence of  bytes
// and returns it, or an error.
func ParseOptRootPath(data []byte) (*OptRootPath, error) {
	return &OptRootPath{Path: string(data)}, nil
}

// Code returns the option code.
func (o *OptRootPath) Code() OptionCode {
	return OptionRootPath
}

// ToBytes returns a serialized stream of bytes for this option.
func (o *OptRootPath) ToBytes() []byte {
	return []byte(o.Path)
}

// String returns a human-readable string for this option.
func (o *OptRootPath) String() string {
	return fmt.Sprintf("Root Path -> %v", o.Path)
}

// OptBootfileName implements the bootfile name option described in RFC 2132,
// Section 9.5.
type OptBootfileName struct {
	BootfileName string
}

// Code returns the option code
func (op *OptBootfileName) Code() OptionCode {
	return OptionBootfileName
}

// ToBytes serializes the option and returns it as a sequence of bytes
func (op *OptBootfileName) ToBytes() []byte {
	return []byte(op.BootfileName)
}

func (op *OptBootfileName) String() string {
	return fmt.Sprintf("Bootfile Name -> %s", op.BootfileName)
}

// ParseOptBootfileName returns a new OptBootfile from a byte stream or error if any
func ParseOptBootfileName(data []byte) (*OptBootfileName, error) {
	return &OptBootfileName{BootfileName: string(data)}, nil
}

// OptTFTPServerName implements the TFTP server name option described by RFC
// 2132, Section 9.4.
type OptTFTPServerName struct {
	TFTPServerName string
}

// Code returns the option code
func (op *OptTFTPServerName) Code() OptionCode {
	return OptionTFTPServerName
}

// ToBytes serializes the option and returns it as a sequence of bytes
func (op *OptTFTPServerName) ToBytes() []byte {
	return []byte(op.TFTPServerName)
}

func (op *OptTFTPServerName) String() string {
	return fmt.Sprintf("TFTP Server Name -> %s", op.TFTPServerName)
}

// ParseOptTFTPServerName returns a new OptTFTPServerName from a byte stream or error if any
func ParseOptTFTPServerName(data []byte) (*OptTFTPServerName, error) {
	return &OptTFTPServerName{TFTPServerName: string(data)}, nil
}

// OptClassIdentifier implements the vendor class identifier option described
// in RFC 2132, Section 9.13.
type OptClassIdentifier struct {
	Identifier string
}

// ParseOptClassIdentifier constructs an OptClassIdentifier struct from a sequence of
// bytes and returns it, or an error.
func ParseOptClassIdentifier(data []byte) (*OptClassIdentifier, error) {
	return &OptClassIdentifier{Identifier: string(data)}, nil
}

// Code returns the option code.
func (o *OptClassIdentifier) Code() OptionCode {
	return OptionClassIdentifier
}

// ToBytes returns a serialized stream of bytes for this option.
func (o *OptClassIdentifier) ToBytes() []byte {
	return []byte(o.Identifier)
}

// String returns a human-readable string for this option.
func (o *OptClassIdentifier) String() string {
	return fmt.Sprintf("Class Identifier -> %v", o.Identifier)
}