---
name: "coap_init"
section: "3"
platform: "linux"
package: "libcoap3t64"
version: "4.3.4-1.1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/coap_init"
---

# coap\_init(3)

Work with CoAP initialization

## NAME

coap\_init, coap\_startup, coap\_cleanup - Work with CoAP initialization

## SYNOPSIS

**#include \<coap3/coap.h\>**

**void coap\_startup(void);**

**void coap\_cleanup(void);**

For specific (D)TLS library support, link with **-lcoap-3-notls**, **-lcoap-3-gnutls**, **-lcoap-3-openssl**, **-lcoap-3-mbedtls** or **-lcoap-3-tinydtls**. Otherwise, link with **-lcoap-3** to get the default (D)TLS library support.

## DESCRIPTION

The CoAP libcoap logic needs to be initialized before there is any use of the libcoap public API. This is done by calling **coap\_startup**().

## FUNCTIONS

**Function: coap\_startup()**

The **coap\_startup**() function must be called before any other **coap\_**\*() functions are called. It is used to initialize things like mutexes, random number gererators, clocks, TLS libraries etc.

**NOTE:** This should be called after any other lower layer is initialized. For example, for LwIP, lwip\_init() must be called before **coap\_startup**().

**NOTE:** After the inital call to **coap\_startup**(), subsequent calls are ignored until **coap\_cleanup**() is called.

**Function: coap\_cleanup()**

The **coap\_cleanup**() function is used to cleanup / free any information set up by the **coap\_startup**() function and should be the last **coap\_**\*() function called. It is possible to call **coap\_startup**() after **coap\_cleanup**() to re-initialize the libcoap logic.

**NOTE:** All other libcoap cleanups should called prior to **coap\_cleanup**(), e.g. [**coap\_free\_context**(3)](/coap_free_context/3.md).

## FURTHER INFORMATION

See

"RFC7252: The Constrained Application Protocol (CoAP)"

for further information.

## BUGS

Please report bugs on the mailing list for libcoap: libcoap-developers@lists.sourceforge.net or raise an issue on GitHub at https://github.com/obgm/libcoap/issues

## AUTHORS

The libcoap project \<libcoap-developers@lists.sourceforge.net\>
