]> git.ipfire.org Git - people/stevee/perl-ipset.git/commitdiff
Add function to get all loaded sets from the kernel.
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 1 Sep 2022 17:38:14 +0000 (19:38 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Thu, 1 Sep 2022 17:38:14 +0000 (19:38 +0200)
They will be returned as a perl array.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
IPSet.xs

index d44e8f63b4a8587b5250b2feb08427463109be4a..2d8c8622b507b423d1d76798fcb86eb4e534f163 100644 (file)
--- 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)