devicepath/ipv6.go

56 lines
1 KiB
Go
Raw Normal View History

2023-09-18 11:47:44 +00:00
package devicepath
import (
"errors"
"fmt"
"strconv"
"strings"
)
const ipv6Prefix string = "IPv6"
type Ipv6DevicePath struct {
remoteIP string
protocol string
static bool
}
func (ip *Ipv6DevicePath) Type() DeviceNodeType {
return MessagingDevicePath
}
func (ip *Ipv6DevicePath) SubType() DeviceNodeSubType {
2023-09-18 12:15:11 +00:00
return IPv6MessagingSubType
2023-09-18 11:47:44 +00:00
}
func (ip *Ipv6DevicePath) Bytes() []byte {
return nil
}
func (ip *Ipv6DevicePath) String() string {
ipType := 0
if ip.static {
ipType = 1
}
return fmt.Sprintf("%s(%s,%s,%d)", ipv6Prefix, ip.remoteIP, ip.protocol, ipType)
}
func (ip *Ipv6DevicePath) ParseString(raw string) error {
if !checkStringFormat(raw, ipv6Prefix, -1) {
return ErrMalformedString
}
args := strings.Split(raw[len(ipv6Prefix)+1:len(raw)-1], ",")
if len(args) != 3 {
return errors.New("unexpected number of arguments")
}
ip.remoteIP = args[0]
ip.protocol = args[1]
if ipType, err := strconv.Atoi(args[2]); err != nil {
return err
} else {
ip.static = ipType == 1
}
return nil
}