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
|
package dhcpv6
import (
"fmt"
"github.com/u-root/u-root/pkg/uio"
)
// OptRemoteID implemens the Remote ID option as defined by RFC 4649.
type OptRemoteID struct {
EnterpriseNumber uint32
RemoteID []byte
}
// Code implements Option.Code.
func (*OptRemoteID) Code() OptionCode {
return OptionRemoteID
}
// ToBytes serializes this option to a byte stream.
func (op *OptRemoteID) ToBytes() []byte {
buf := uio.NewBigEndianBuffer(nil)
buf.Write32(op.EnterpriseNumber)
buf.WriteBytes(op.RemoteID)
return buf.Data()
}
func (op *OptRemoteID) String() string {
return fmt.Sprintf("RemoteID: EnterpriseNumber %d RemoteID %v",
op.EnterpriseNumber, op.RemoteID,
)
}
// ParseOptRemoteId builds an OptRemoteId structure from a sequence of bytes.
// The input data does not include option code and length bytes.
func ParseOptRemoteID(data []byte) (*OptRemoteID, error) {
var opt OptRemoteID
buf := uio.NewBigEndianBuffer(data)
opt.EnterpriseNumber = buf.Read32()
opt.RemoteID = buf.ReadAll()
return &opt, buf.FinError()
}
|