package devicepath import ( "errors" "fmt" "strconv" "strings" ) const ipv4Prefix string = "IPv4" type Ipv4DevicePath struct { remoteIP string protocol string static bool } func (ip *Ipv4DevicePath) Type() DeviceNodeType { return MessagingDevicePath } func (ip *Ipv4DevicePath) SubType() DeviceNodeSubType { return IPv4MessagingSubType } func (ip *Ipv4DevicePath) Bytes() []byte { return nil } func (ip *Ipv4DevicePath) String() string { ipType := 0 if ip.static { ipType = 1 } return fmt.Sprintf("%s(%s,%s,%d)", ipv4Prefix, ip.remoteIP, ip.protocol, ipType) } func (ip *Ipv4DevicePath) ParseString(raw string) error { if !checkStringFormat(raw, ipv4Prefix, -1) { return ErrMalformedString } args := strings.Split(raw[len(ipv4Prefix)+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 }