COAP_INIT(3)

πŸŽ€ COAP_INIT(3) β€” the libcoap manual, bestie edition πŸŽ€

okay so we're diving into libcoap, specifically the initialization girlies. this is your COAP_INIT(3) page and honestly? it's short but it MATTERS. like, this is the "turn the lights on before you walk in the room" of the whole library. πŸ’‘


✨ NAME ✨

coap_init, coap_startup, coap_cleanup β€” the whole "work with CoAP initialization" situation. that's the vibe. that's the trio. 🫢


🌸 SYNOPSIS 🌸

#include <coap3/coap.h>

void coap_startup(void);

void coap_cleanup(void);

so for specific (D)TLS library support, you link with one of these besties:

  • -lcoap-3-notls
  • -lcoap-3-gnutls
  • -lcoap-3-openssl
  • -lcoap-3-mbedtls
  • -lcoap-3-wolfssl
  • -lcoap-3-tinydtls

otherwise (read: if you're just chilling and don't wanna pick), link with -lcoap-3 and you get the default (D)TLS library support. slay, no decisions required. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so the CoAP libcoap logic has to be initialized before you use literally any part of the libcoap public API. like, there's no skipping this. no cap. and the way you do it? you call coap_startup(). that's it. that's the whole thing. 🌟


πŸ”₯ FUNCTIONS πŸ”₯

⭐ Function: coap_startup()

okay so coap_startup() has to be called before you call any other coap_*() functions. periodt. it's out here initializing things like mutexes, random number generators, clocks, TLS libraries, etc. the whole backstage crew getting ready before the show. 🎬

NOTE: this should be called after any other lower layer is initialized. like, for example, for LwIP, lwip_init() must be called before coap_startup(). order matters bestie, don't come for me. πŸ™ˆ
NOTE: after that first call to coap_startup(), any subsequent calls are just ignored until coap_cleanup() gets called. so don't stress about spamming it, it's giving unbothered. πŸ’€

πŸ’œ Function: coap_cleanup()

coap_cleanup() is the cleanup girlie β€” it cleans up / frees any information that coap_startup() set up, and it should be the last coap_*() function you call. the only safe function you can call after coap_cleanup() is coap_startup(), and that's just to re-initialize the libcoap logic. it's giving "and we go again." πŸ”

NOTE: calling coap_cleanup() in one thread while you're still out here using other coap_*() function calls in a different thread is not supported β€” even if they're using a different coap_context_t. like, please don't. that's a no from me. 😭
NOTE: all other libcoap cleanups should be called prior to coap_cleanup(), e.g. coap_free_context(3). last one out turns off the lights, not the other way around. πŸ’‘

🌈 FURTHER INFORMATION 🌈

see

"RFC7252: The Constrained Application Protocol (CoAP)"

for further information. iykyk, go read it, it's iconic. πŸ‘‘


πŸ“ BUGS πŸ“

found a bug? please raise an issue on GitHub at https://github.com/obgm/libcoap/issues to report any bugs. we wanna know!! πŸ›

got a fix? please raise a Pull Request at https://github.com/obgm/libcoap/pulls for any fixes. main character energy, honestly. 🫢


🌸 AUTHORS 🌸

the libcoap project <libcoap-developers@lists.sourceforge.net> πŸ’–


and that's the page, bestie! this was coap_init from 4.3.5, dated 08/24/2026 β€” see you in the next manpage, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from