"Decoding" ipset error codes
I am using libmnl to add entries to an IP set. (Code here[1] if anyone is interested.) I've got everything working, but I haven't yet found a way to "decode" any protocol-specific errors that may be returned, because the set is not of the correct type, for example.
I see that libipset has an ipset_errcode() function but it looks to be designed for use only when libipset is being used for the actual netlink communication. (I didn't do that in this case, because libipset looks to be targeted only on parsing and executing commands that are passed to the ipset command. It didn't make any sense to me to create a command string in a buffer just so libipset could parse it back into information that is already known.)
Is there any way that I can give users of my program something more helpful than "unknown error XXXX"?
Thanks!
[1] https://github.com/ipilcher/fdf/blob/main/src/filters/ipset.c
Signature · 3 lines
======================================================================== Google Where SkyNet meets Idiocracy ========================================================================
Hello Ian,
Quoted 5 lines · Ian Pilcher
I am using libmnl to add entries to an IP set. (Code here[1] if anyone is interested.) I've got everything working, but I haven't yet found a way to "decode" any protocol-specific errors that may be returned, because the set is not of the correct type, for example.
Quoted 7 lines
I see that libipset has an
ipset_errcode()function but it looks to be designed for use only when libipset is being used for the actual netlink communication. (I didn't do that in this case, because libipset looks to be targeted only on parsing and executing commands that are passed to the ipset command. It didn't make any sense to me to create a command string in a buffer just so libipset could parse it back into information that is already known.)
You can avoid parsing: it is possible to fill out the session data fields directly by calling ipset_data_set() and then issuing the required command.
Quoted 2 lines
Is there any way that I can give users of my program something more helpful than "unknown error XXXX"?
You can "copy" the errcode table from the libipset source tree. Or it could be extended with a new ipset_errcode_raw() command which would just translate the returned errcode into the appropriate error string.
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : https://wigner.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics
H-1525 Budapest 114, POB. 49, Hungary