opts.IPVal returns an error on incorrect input
package opts
import (
+ "fmt"
"net"
)
@@ -17,8 +18,10 @@ func NewIpOpt(ref *net.IP, defaultVal string) *IpOpt {
}
func (o *IpOpt) Set(val string) error {
- // FIXME: return a parse error if the value is not a valid IP?
- // We are not changing this now to preserve behavior while refactoring.
+ ip := net.ParseIP(val)
+ if ip == nil {
+ return fmt.Errorf("incorrect IP format")
+ }
(*o.IP) = net.ParseIP(val)
return nil
}
