troglobit/netcalc

Message error is missing

Diogofornazari opened this issue · 5 comments

Tool doesn't return error if IP is invalid ( you can put any value, invalid values (zxvf:mlpr9:...) and the return is always 0, like if it was okay); if block 8 is suppressed it doesn't show ip address and it doesn't show any error (abff:0:ed4a:123f:ddd:3e4f:104f::);

Examples
#: netcalc zxvm:lçvd:: && echo Ok
#: Ok

#: netcalc 2fe1:d200:0:0:0:c801:a68:: 64
#: echo $?
#: 0

According to netcalc -h

Global options:
  -c          Validate the IPv4/IPv6 address, no output if invalid

So, validating can be performed as:

# test -n "$(netcalc -c 2fe1:d200:0:0:0:c801:a68::)"
# echo $?
1
# test -n "$(netcalc -c 2fe1:d200:0:0:0:c801:a68:0)"
# echo $?
0

I agree a return code would be nice, but IIRC the long history of the netcalc code does not easily lend itself to adding that.

I agree a return code would be nice, but IIRC the long history of the netcalc code does not easily lend itself to adding that.

Well we could change it but anyone scripting with netcalc would possibly start experiencing regressions after upgrading. Making sure the -c option works is imo the least intrusive way forward.

Completely agree with You Mr. Wiberg.
I've done some more tests and, even using the -c option, the validation doesn't work well when the 8 block is suppressed.
Totally understand if it's not possible to make changes now, could be a big risk, while that, I'll try to find a way to treat it otherwise.

Thanks for your attention.

@Diogofornazari any help or input on improving -c would be great, thank you for taking the time to report this!