cap_netdb(3)

cap_netdb3

Library for getting network proto entry in capability mode

Usage

#include <sys/nv.h>

#include <libcasper.h>

#include <casper/cap_netdb.h>

struct protoent *

cap_getprotobyname(const cap_channel_t *chan, const char *name);

Library

library “libcap_netdb”

Overview

The function cap_getprotobyname() is equivalent to getprotobyname(3) except that the connection to the system.netdb service needs to be provided. It is reentrant but not thread-safe. That is, it may be called from separate threads only with different cap_channel_t arguments or with synchronization.

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.

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");

Releases

9 releases since FreeBSD 14.0-RELEASE; the text changed 1 time.

  1. 14.0
  2. 14.1–16.0

Authors

The cap_netdb service was implemented by Ryan Moeller ⟨[email protected]⟩.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.