Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F163374173
D16931.id47461.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D16931.id47461.diff
View Options
Index: lib/libcasper/services/cap_dns/cap_dns.3
===================================================================
--- lib/libcasper/services/cap_dns/cap_dns.3
+++ lib/libcasper/services/cap_dns/cap_dns.3
@@ -162,19 +162,22 @@
casper service and uses it to resolve an IP address.
.Bd -literal
cap_channel_t *capcas, *capdns;
-const char *typelimit = "ADDR";
-int familylimit;
+int familylimit, error;
const char *ipstr = "127.0.0.1";
-struct in_addr ip;
-struct hostent *hp;
+const char *typelimit = "ADDR";
+char hname[NI_MAXHOST];
+struct addrinfo hints, *res;
/* Open capability to Casper. */
capcas = cap_init();
if (capcas == NULL)
err(1, "Unable to contact Casper");
+/* Cache NLA for gai_strerror. */
+caph_cache_catpages();
+
/* Enter capability mode sandbox. */
-if (cap_enter() < 0 && errno != ENOSYS)
+if (caph_enter() < 0)
err(1, "Unable to enter capability mode");
/* Use Casper capability to create capability to the system.dns service. */
@@ -185,25 +188,30 @@
/* 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);
+/* Convert IP address in C-string to struct sockaddr. */
+memset(&hints, 0, sizeof(hints));
+hints.ai_family = familylimit;
+hints.ai_flags = AI_NUMERICHOST;
+error = cap_getaddrinfo(capdns, ipstr, NULL, &hints, &res);
+if (error != 0)
+ errx(1, "cap_getaddrinfo(): %s: %s", ipstr, gai_strerror(error));
+
+/* 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");
/* 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);
+error = cap_getnameinfo(capdns, res->ai_addr, res->ai_addrlen, hname, sizeof(hname),
+ NULL, 0, 0);
+if (error != 0)
+ errx(1, "cap_getnameinfo(): %s: %s", ipstr, gai_strerror(error));
-printf("Name associated with %s is %s.\\n", ipstr, hp->h_name);
+printf("Name associated with %s is %s.\\n", ipstr, hname);
.Ed
.Sh SEE ALSO
.Xr cap_enter 2 ,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jul 23, 3:24 PM (13 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35406467
Default Alt Text
D16931.id47461.diff (2 KB)
Attached To
Mode
D16931: Update example in man page to use cap_getnameinfo function.
Attached
Detach File
Event Timeline
Log In to Comment