Main index | Section 3 | Options |
#include <sys/nv.h>
#include <libcasper.h>
#include <casper/cap_dns.h>
The cap_dns_type_limit() function limits the functions allowed in the service. The types variable can be set to ADDR2NAME or NAME2ADDR. See the LIMITS section for more details. The ntpyes variable contains the number of types provided.
The cap_dns_family_limit() functions allows to limit address families. For details see LIMITS. The nfamilies variable contains the number of families provided.
type( NV_TYPE_STRING) | The type can have two values: ADDR2NAME or NAME2ADDR. The ADDR means that reverse DNS lookups are allowed with cap_getnameinfo() and cap_gethostbyaddr() functions. In case when type is set to NAME the name resolution is allowed with cap_getaddrinfo(), cap_gethostbyname(), and cap_gethostbyname2() functions. |
family( NV_TYPE_NUMBER) | The family limits service to one of the address families (e.g. AF_INET, AF_INET6, etc.). |
cap_channel_t *capcas, *capdns; const char *typelimit = "ADDR"; int familylimit; const char *ipstr = "127.0.0.1"; struct in_addr ip; struct hostent *hp;/* Open capability to Casper. */ capcas = cap_init(); if (capcas == NULL) err(1, "Unable to contact Casper");
/* Enter capability mode sandbox. */ if (cap_enter() < 0 && errno != ENOSYS) err(1, "Unable to enter capability mode");
/* Use Casper capability to create capability to the system.dns service. */ capdns = cap_service_open(capcas, "system.dns"); if (capdns == NULL) err(1, "Unable to open system.dns service");
/* Close Casper capability, we don't need it anymore. */ cap_close(capcas);
/* Limit system.dns to reverse DNS lookups. */ if (cap_dns_type_limit(capdns, &typelimit, 1) < 0) err(1, "Unable to limit access to the system.dns service");
/* Limit system.dns to reserve IPv4 addresses */ familylimit = AF_INET; if (cap_dns_family_limit(capdns, &familylimit, 1) < 0) err(1, "Unable to limit access to the system.dns service");
/* Convert IP address in C-string to in_addr. */ if (!inet_aton(ipstr, &ip)) errx(1, "Unable to parse IP address %s.", ipstr);
/* Find hostname for the given IP address. */ hp = cap_gethostbyaddr(capdns, (const void *)&ip, sizeof(ip), AF_INET); if (hp == NULL) errx(1, "No name associated with %s.", ipstr);
printf("Name associated with %s is %s. , ipstr, hp->h_name);
This manual page was written by Mariusz Zaborski <Mt oshogbo@FreeBSD.org>.
CAP_DNS (3) | May 5, 2020 |
Main index | Section 3 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | I think Unix and snowflakes are the only two classes of objects in the universe in which no two instances ever match exactly. | ” |
— Noel Chiappa |