CAP_NETDB(3)
π CAP_NETDB(3) π
okay so this is a page from the Library Functions Manual, and it's all about cap_getprotobyname β the little library that gets you a network proto entry while you're living inside capability mode. yes bestie, sandboxed and still looking up protocol names. we love to see it. β¨
πΈ NAME πΈ
cap_getprotobyname β library for getting network proto entry in capability mode π¦
π LIBRARY π
library βlibcap_netdbβ
β¨ SYNOPSIS β¨
#include <sys/nv.h>
#include <libcasper.h>
#include <casper/cap_netdb.h>
struct protoent *
cap_getprotobyname(const cap_channel_t *chan, const char *name);
π DESCRIPTION π
so cap_getprotobyname() is literally the same energy as getprotobyname(3), with one tiny plot twist: you gotta hand it a connection to the system.netdb service. that's the whole vibe. π₯
and listen β it's reentrant but not thread-safe. it's giving "i can hang, but not with everyone at once." the way this works is: you may call it from separate threads only if you're passing different cap_channel_t arguments, or if you've got synchronization going on. no cap. π«Ά
bestie pls respect the threading rule β same cap_channel_t from multiple threads without locking is a no-no. π
π§ EXAMPLES π§
the following example first opens a capability to casper and then uses this capability to create the system.netdb casper service and uses it to look up a protocol by name. iconic behavior, honestly. π
cap_channel_t *capcas, *capnetdb;
struct protoent *ent;
/* Open capability to Casper. */
capcas = cap_init();
if (capcas == NULL)
err(1, "Unable to contact Casper");
/* Enter capability mode sandbox. */
if (caph_enter() < 0)
err(1, "Unable to enter capability mode");
/* Use Casper capability to create capability to the system.netdb service. */
capnetdb = cap_service_open(capcas, "system.netdb");
if (capnetdb == NULL)
err(1, "Unable to open system.netdb service");
/* Close Casper capability, we don't need it anymore. */
cap_close(capcas);
ent = cap_getprotobyname(capnetdb, "http");
if (ent == NULL)
errx(1, "cap_getprotobyname failed to find http proto");
π SEE ALSO π
π AUTHORS π
the cap_netdb service was implemented by Ryan Moeller <freqlabs@FreeBSD.org>. absolute main character energy, we stan. π
and that's the whole page, bestie! this one's from the Debian folks, dated December 6, 2023, and it goes by the name CAP_NETDB(3). go forth and look up your protocols safely, ily ππ π¦
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2020 Ryan Moeller <freqlabs@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms