---
name: "libipset"
section: "3"
platform: "linux"
package: "ipset"
version: "7.24-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libipset"
---

# libipset(3)

A library for using ipset

## NAME

libipset - A library for using ipset

## SYNOPSIS

```
#include <libipset/ipset.h>

void ipset_load_types(void)

struct ipset * ipset_init(void)
int ipset_parse_argv(struct ipset *ipset, int argc, char *argv[])

int ipset_parse_line(struct ipset *ipset, char *line)

int ipset_parse_stream(struct ipset *ipset, FILE *f)

int ipset_fini(struct ipset *ipset)

int ipset_custom_printf(struct ipset *ipset,
			ipset_custom_errorfn custom_error,
			ipset_standard_errorfn standard_error,
			ipset_print_outfn outfn,
			void *p)

struct ipset_session * ipset_session(struct ipset *ipset)

int ipset_session_full_io(struct ipset_session *session,
			  const char *filename,
			  enum ipset_io_type what)

int ipset_session_normal_io(struct ipset_session *session,
			    const char *filename,
			    enum ipset_io_type what)

FILE * ipset_session_io_stream(struct ipset_session *session,
			       enum ipset_io_type what)

int ipset_session_io_close(struct ipset_session *session,
			   enum ipset_io_type what)
```

## DESCRIPTION

libipset provides a library interface to  **[ipset(8)](/ipset/8.md).** The integer return valued functions return 0 on success and a negative value on failure.

- ipset\_load\_types

  Loads in the supported ipset types in the library and make them available for the ipset interface.

- ipset\_init

  Initializes the ipset interface: allocates and initializes the required internal structures, opens up the netlink channel. The function returns the library interface structure of type **struct ipset \*** or **NULL** on failure.

- ipset\_parse\_argv

  Parses the **argc** length of array of strings **argv** with the already initialized **ipset** library structure. If the command is successfully parsed, it is then submitted to the kernel to execute. In the case of error, the textual error message is printed and a negative number is returned.

- ipset\_parse\_line

  Parses the string **line** with the already initialized **ipset** library structure. The line is supposed to contain a single ipset command in restore format. If the command is successfully parsed, it is then submitted to the kernel to execute. In the case of error, the textual error message is printed and a negative number is returned.

- ipset\_parse\_stream

  Parses the stream **f** with the already initialized **ipset** library structure. The stream may contain multiple newline separated ipset commands in restore format. The commands are parsed and then submitted to the kernel in batches for efficiecy. In the case of error, the textual error message is printed and a negative number is returned.

- ipset\_fini

  Closes the netlink channel, closes opened streams and releases allocated structures holding by the **ipset** library structure.

The following functions makes possible to customize the interface.

- ipset\_custom\_printf

  Sets or resets the print functions for the **ipset** library structure, where **custom\_error** is the custom error print function for the internal library errors, **standard\_error** is the print function for the netlink/kernel related errors and **outfn** is the output function to print the result of list/save commands. The **p** pointer makes possible to pass arbitrary structure to the custom print functions. If **NULL** is passed instead of a function pointer, the default print function is set for the given task. If any of the print functions is non-default, then the *version,* *help,* *interactive* ipset commands are ignored.

- ipset\_session

  The function returns the session structure of the **ipset** library structure, in order to manipulate the IO parameters.

- ipset\_session\_full\_io

  You can control the full IO, i.e. input (restore) and output (save) separatedly by the function. The **session** parameter is the session structure of the library interface, **filename** is the filename you want to use for input or output and **what** tells the function you want to set input or output file. If there's an already opened file for the given IO mode, it is closed. The function returns an error if normal mode is in use. If **NULL** is passed instead of a filename, already opened file is closed and the normal stream is set for the given IO mode (stdin for input, stdout for output). Input/output files can be set separatedly.

- ipset\_session\_normal\_io

  You can control the normal IO, which corresponds to the interface provided by **[ipset(8)](/ipset/8.md)** itself. **session** parameter is the session structure of the library interface, **filename** is the filename you want to use for input or output and **what** tells the function you want to set input or output file. If there's an already opened file for input/output, it is closed. The function returns an error if full mode is in use. If **NULL** is passed instead of a filename, already opened file is closed and the normal stream is set for the given IO mode (stdin for input, stdout for output). Input/output files cannot be set separatedly.

- ipset\_session\_io\_stream

  The function returns the stream set for the **session** where **what** tells the function you want to get the input or the output stream.

- ipset\_session\_io\_close

  The function closes the stream for the **session** where **what** tells the function you want to close the input or the output stream. After closing, the standard streams are set: stdin for input, stdout for output.

## AUTHORS

ipset/libipset was designed and written by Jozsef Kadlecsik.

## SEE ALSO

**[ipset(8)](/ipset/8.md),**\
 /usr/include/libipset/ipset.h /usr/include/libipset/session.h
