---
name: "cap_netdb"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/cap_getprotobyname"
---

# cap\_netdb(3)

library for getting network proto entry in capability mode

Part of [cap\_getprotobyname(3)](/cap_getprotobyname/3.md).

## 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

The function **cap\_getprotobyname**() is equivalent to [getprotobyname(3)](/getprotobyname/3.md) 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");
```

## SEE ALSO

[cap\_enter(2)](/cap_enter/2.md), [caph\_enter(3)](/caph_enter/3.md), [err(3)](/err/3.md), [getprotobyname(3)](/getprotobyname/3.md), [capsicum(4)](/capsicum/4.md), [nv(9)](/nv/9.md)

## AUTHORS

The **cap\_netdb** service was implemented by Ryan Moeller ⟨*freqlabs@FreeBSD.org*⟩.
