return r;
}
+char* call_list_cmd(struct ipset_session *session,
+ enum ipset_envopt envopt,
+ const char *setname, ...)
+{
+
+ enum ipset_cmd cmd = IPSET_CMD_LIST;
+ int r;
+
+ char* p = NULL;
+ char* sets = NULL;
+
+ // Check if an environment option has been passed.
+ if(envopt) {
+ // Set the environemt option.
+ ipset_envopt_set(session, envopt);
+ }
+
+ // Check if a setname has been given.
+ if(setname) {
+ r = ipset_session_data_set(session, IPSET_SETNAME, setname);
+ if (r < 0 ) {
+ goto ERROR;
+ }
+ }
+
+ // Use print_outfm_to_string function to put the output into a string which
+ // can be processed further.
+ ipset_session_print_outfn(session, print_outfm_to_string, &sets);
+
+ r = ipset_cmd(session, cmd, 0);
+ if (r < 0) {
+ goto ERROR;
+ }
+
+ goto END;
+
+ ERROR:
+ // Reset session data.
+ ipset_data_reset(ipset_session_data(session));
+ END:
+ // Remove environment option.
+ ipset_envopt_unset(session, envopt);
+
+ // Reset outfn to defaul.
+ ipset_session_print_outfn(session, NULL, NULL);
+
+ return sets;
+}
+
MODULE = IPSet PACKAGE = IPSet
struct ipset_session *