summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_host_name.go
blob: 77ed17cdcc93a536ae7ce183f1eec490279e75ea (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
package dhcpv4

import "fmt"

// This option implements the host name option
// https://tools.ietf.org/html/rfc2132

// OptHostName represents an option encapsulating the host name.
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)
}

// Length returns the length of the data portion (excluding option code an byte
// length).
func (o *OptHostName) Length() int {
	return len(o.HostName)
}