summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_ip_address_lease_time.go
blob: 4362419cfd78f6907e8e9f8ecd6ecf910a0fca50 (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"

	"github.com/u-root/u-root/pkg/uio"
)

// OptIPAddressLeaseTime implements the IP address lease time option described
// by RFC 2132, Section 9.2.
type OptIPAddressLeaseTime struct {
	LeaseTime uint32
}

// ParseOptIPAddressLeaseTime constructs an OptIPAddressLeaseTime struct from a
// sequence of bytes and returns it, or an error.
func ParseOptIPAddressLeaseTime(data []byte) (*OptIPAddressLeaseTime, error) {
	buf := uio.NewBigEndianBuffer(data)
	leaseTime := buf.Read32()
	return &OptIPAddressLeaseTime{LeaseTime: leaseTime}, buf.FinError()
}

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

// ToBytes returns a serialized stream of bytes for this option.
func (o *OptIPAddressLeaseTime) ToBytes() []byte {
	buf := uio.NewBigEndianBuffer(nil)
	buf.Write32(o.LeaseTime)
	return buf.Data()
}

// String returns a human-readable string for this option.
func (o *OptIPAddressLeaseTime) String() string {
	return fmt.Sprintf("IP Addresses Lease Time -> %v", o.LeaseTime)
}