> ipset --version
ipset v7.1, protocol version: 7
Warning: Kernel support protocol versions 6-6 while userspace supports protocol versions 6-7
- this code will return more than version info
out, err := execCommand(ipsetPath, _version).CombinedOutput()
# out is like this
Warning: Kernel support protocol versions 6-6 while userspace supports protocol versions 6-7
ipset v7.1, protocol version: 7
- this code can not get real version
func getMajorVersion(version []byte) int {
vIndex := bytes.IndexByte(version, 'v')
dotIndex := bytes.IndexByte(version, '.')
var majorVersion int
for i := vIndex + 1; i < dotIndex; i++ {
if c := version[i]; c >= '0' && c <= '9' {
majorVersion = majorVersion*10 + int(c-'0')
} else {
return 0
}
}
return majorVersion
}
ipset utility version is not supported, requiring version >= 6.0
this code can replace by regexp
this code can replace by regexp