CAP_NETDB(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’… 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