---
name: "lber-sockbuf"
section: "3"
platform: "linux"
package: "libldap"
version: "2.7.2-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "macos"]
url: "https://new.carta.tech/lber-sockbuf"
---

# lber-sockbuf(3)

OpenLDAP LBER I/O infrastructure

## NAME

ber\_sockbuf\_alloc, ber\_sockbuf\_free, ber\_sockbuf\_ctrl, ber\_sockbuf\_add\_io, ber\_sockbuf\_remove\_io, Sockbuf\_IO - OpenLDAP LBER I/O infrastructure

## LIBRARY

OpenLDAP LBER (liblber, -llber)

## SYNOPSIS

**#include \<lber.h\>**

**Sockbuf \*ber\_sockbuf\_alloc( void );**

**void ber\_sockbuf\_free(Sockbuf \****sb***);**

**int ber\_sockbuf\_ctrl(Sockbuf \****sb***, int** *opt***, void \****arg***);**

**int ber\_sockbuf\_add\_io(Sockbuf \****sb***, Sockbuf\_IO \****sbio***, int** *layer***, void \****arg***);**

**int ber\_sockbuf\_remove\_io(Sockbuf \****sb***, Sockbuf\_IO \****sbio***, int** *layer***);**

```
typedef struct sockbuf_io_desc {
int sbiod_level;
Sockbuf *sbiod_sb;
Sockbuf_IO *sbiod_io;
void *sbiod_pvt;
struct sockbuf_io_desc *sbiod_next;
} Sockbuf_IO_Desc;
```

**typedef struct sockbuf\_io {** **int (\****sbi\_setup***)(Sockbuf\_IO\_Desc \****sbiod***, void \****arg***);** **int (\****sbi\_remove***)(Sockbuf\_IO\_Desc \****sbiod***);** **int (\****sbi\_ctrl***)(Sockbuf\_IO\_Desc \****sbiod***, int** *opt***, void \****arg***);** **ber\_slen\_t (\****sbi\_read***)(Sockbuf\_IO\_Desc \****sbiod***, void \****buf***, ber\_len\_t** *len***);** **ber\_slen\_t (\****sbi\_write***)(Sockbuf\_IO\_Desc \****sbiod***, void \****buf***, ber\_len\_t** *len***);** **int (\****sbi\_close***)(Sockbuf\_IO\_Desc \****sbiod***);** **} Sockbuf\_IO;**

## DESCRIPTION

These routines are used to manage the low level I/O operations performed by the Lightweight BER library. They are called implicitly by the other libraries and usually do not need to be called directly from applications. The I/O framework is modularized and new transport layers can be supported by appropriately defining a **Sockbuf\_IO** structure and installing it onto an existing **Sockbuf**. **Sockbuf** structures are allocated and freed by **ber\_sockbuf\_alloc**() and **ber\_sockbuf\_free**(), respectively. The **ber\_sockbuf\_ctrl**() function is used to get and set options related to a **Sockbuf** or to a specific I/O layer of the **Sockbuf**. The **ber\_sockbuf\_add\_io**() and **ber\_sockbuf\_remove\_io**() functions are used to add and remove specific I/O layers on a **Sockbuf**.

Options for **ber\_sockbuf\_ctrl**() include:

- **LBER\_SB\_OPT\_HAS\_IO**

  Takes a **Sockbuf\_IO \*** argument and returns 1 if the given handler is installed on the **Sockbuf**, otherwise returns 0.

- **LBER\_SB\_OPT\_GET\_FD**

  Retrieves the file descriptor associated to the **Sockbuf**; **arg** must be a **ber\_socket\_t \***. The return value will be 1 if a valid descriptor was present, -1 otherwise.

- **LBER\_SB\_OPT\_SET\_FD**

  Sets the file descriptor of the **Sockbuf** to the descriptor pointed to by **arg**; **arg** must be a **ber\_socket\_t \***. The return value will always be 1.

- **LBER\_SB\_OPT\_SET\_NONBLOCK**

  Toggles the non-blocking state of the file descriptor associated to the **Sockbuf**. **arg** should be NULL to disable and non-NULL to enable the non-blocking state. The return value will be 1 for success, -1 otherwise.

- **LBER\_SB\_OPT\_DRAIN**

  Flush (read and discard) all available input on the **Sockbuf**. The return value will be 1.

- **LBER\_SB\_OPT\_NEEDS\_READ**

  Returns non-zero if input is waiting to be read.

- **LBER\_SB\_OPT\_NEEDS\_WRITE**

  Returns non-zero if the **Sockbuf** is ready to be written.

- **LBER\_SB\_OPT\_GET\_MAX\_INCOMING**

  Returns the maximum allowed size of an incoming message; **arg** must be a **ber\_len\_t \***. The return value will be 1.

- **LBER\_SB\_OPT\_SET\_MAX\_INCOMING**

  Sets the maximum allowed size of an incoming message; **arg** must be a **ber\_len\_t \***. The return value will be 1.

Options not in this list will be passed down to each **Sockbuf\_IO** handler in turn until one of them processes it. If the option is not handled **ber\_sockbuf\_ctrl**() will return 0.

Multiple **Sockbuf\_IO** handlers can be stacked in multiple layers to provide various functionality. Currently defined layers include

- **LBER\_SBIOD\_LEVEL\_PROVIDER**

  the lowest layer, talking directly to a network

- **LBER\_SBIOD\_LEVEL\_TRANSPORT**

  an intermediate layer

- **LBER\_SBIOD\_LEVEL\_APPLICATION**

  a higher layer

Currently defined **Sockbuf\_IO** handlers in liblber include

- **ber\_sockbuf\_io\_tcp**

  The default stream-oriented provider

- **ber\_sockbuf\_io\_fd**

  A stream-oriented provider for local IPC sockets

- **ber\_sockbuf\_io\_dgram**

  A datagram-oriented provider. This handler is only present if the liblber library was built with LDAP\_CONNECTIONLESS defined.

- **ber\_sockbuf\_io\_readahead**

  A buffering layer, usually used with a datagram provider to hide the datagram semantics from upper layers.

- **ber\_sockbuf\_io\_debug**

  A generic handler that outputs hex dumps of all traffic. This handler may be inserted multiple times at arbitrary layers to show the flow of data between other handlers.

Additional handlers may be present in libldap if support for them was enabled:

- **ldap\_pvt\_sockbuf\_io\_sasl**

  An application layer handler for SASL encoding/decoding.

- **sb\_tls\_sbio**

  A transport layer handler for SSL/TLS encoding/decoding. Note that this handler is private to the library and is not exposed in the API.

The provided handlers are all instantiated implicitly by libldap, and applications generally will not need to directly manipulate them.

## SEE ALSO

[**lber-decode**(3)](/lber-decode/3.md), [**lber-encode**(3)](/lber-encode/3.md), [**lber-types**(3)](/lber-types/3.md), [**ldap\_get\_option**(3)](/ldap_get_option/3.md)

## ACKNOWLEDGEMENTS

**OpenLDAP Software** is developed and maintained by The OpenLDAP Project \<http://www.openldap.org/\>. **OpenLDAP Software** is derived from the University of Michigan LDAP 3.3 Release.
