---
name: "libopeniscsiusr.h"
section: "3"
platform: "linux"
package: "open-iscsi"
version: "2.1.13-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libopeniscsiusr.h"
---

# libopeniscsiusr.h(3)

iSCSI userspace API.

## NAME

libopeniscsiusr.h - iSCSI userspace API.

## SYNOPSIS

\#include \<libopeniscsiusr/libopeniscsiusr.h\>

## DESCRIPTION

All the libopeniscsiusr public functions ship their own man pages. You may use 'man -k iscsi' to find out and use 'man 3 \<function\_name\>' to check the detail usage.

## USAGE

To use libopeniscsiusr in your project, we suggest to use the 'pkg-config' way:

 \* Add this line into your configure.ac:

    PKG\_CHECK\_MODULES(\[LIBISCSIUSR\], \[libopeniscsiusr\])

 \* Add these lines into your Makefile.am:

    foo\_LDFLAGS += $(LIBISCSIUSR\_LIBS)\
     foo\_CFLAGS += $(LIBISCSIUSR\_CFLAGS)

## LOG HANDLING

The log handler function could be set via 'iscsi\_context\_log\_func\_set()'. The log priority could be set via 'iscsi\_context\_log\_priority\_set()'.

By default, the log priorities is 'LIBISCSI\_LOG\_PRIORITY\_WARNING'. By default, the log handler is print log to STDERR, and its code is listed below in case you want to take it as an example to create your own log handler.

        \#define \_ISCSI\_LOG\_STRERR\_ALIGN\_WIDTH   80

        void \_iscsi\_log\_stderr(struct iscsi\_context \*ctx, int priority,\
                                const char \*file, int line,\
                                const char \*func\_name,\
                                const char \*format, va\_list args)\
         {\
                 int printed\_bytes = 0;

                printed\_bytes += fprintf(stderr, "iSCSI %s: ",\
                                          iscsi\_log\_priority\_str(priority));\
                 printed\_bytes += vfprintf(stderr, format, args);

                if (printed\_bytes \< \_ISCSI\_LOG\_STRERR\_ALIGN\_WIDTH) {\
                         fprintf(stderr, "%\*s # %s:%s():%d0,\
                                 \_ISCSI\_LOG\_STRERR\_ALIGN\_WIDTH - printed\_bytes,\
                                 "", file, func\_name, line);\
                 } else {\
                         fprintf(stderr, " # %s:%s():%d0, file, func\_name,\
                                 line);\
                 }\
         }

## SAMPLE CODE

        struct iscsi\_context \*ctx = NULL;\
         struct iscsi\_session \*\*ses = NULL;\
         uint32\_t se\_count = 0;\
         uint32\_t i = 0;\
         int rc = EXIT\_SUCCESS;

        ctx = iscsi\_context\_new();\
         iscsi\_context\_log\_priority\_set(ctx, LIBISCSI\_LOG\_PRIORITY\_DEBUG);

        if (iscsi\_sessions\_get(ctx, &ses, &se\_count) != LIBISCSI\_OK) {\
                 printf("FAILED0);\
                 rc = EXIT\_FAILURE;\
         } else {\
                 printf("0ot %" PRIu32 " iSCSI sessions0, se\_count);\
                 for (i = 0; i \< se\_count; ++i)\
                         printf("SID is %" PRIu32 "0,\
                                iscsi\_session\_sid\_get(ses\[i\]));\
                 iscsi\_sessions\_free(ses, se\_count);\
         }\
         iscsi\_context\_free(ctx);\
         exit(rc);

## LICENSE

LGPLv3+

## BUG

Please report bug to https://github.com/open-iscsi/open-iscsi/issues
