From: Stefan Schantl Date: Thu, 1 Sep 2022 17:38:14 +0000 (+0200) Subject: Add function to get all loaded sets from the kernel. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5d3439902c71cc4cc432a1a470f1ab16dd0fea54;p=people%2Fstevee%2Fperl-ipset.git Add function to get all loaded sets from the kernel. They will be returned as a perl array. Signed-off-by: Stefan Schantl --- diff --git a/IPSet.xs b/IPSet.xs index d44e8f6..2d8c862 100644 --- a/IPSet.xs +++ b/IPSet.xs @@ -334,6 +334,32 @@ setname_exists(session, setname) OUTPUT: RETVAL +void +get_sets(session) + struct ipset_session *session; + + PREINIT: + enum ipset_envopt envopt = IPSET_ENV_LIST_SETNAME; + + char* sets = NULL; + char* p = NULL; + + PPCODE: + sets = call_list_cmd(session, envopt, NULL); + + char* set = strtok_r(sets, "\n", &p); + + while (set) { + // Push the set to the perl array. + XPUSHs(sv_2mortal(newSVpv(set, strlen(set)))); + + // Move on to next set + set = strtok_r(NULL, "\n", &p); + } + + if(sets) { + free(sets); + } SV* get_error_message(session)