Skip to content

Instantly share code, notes, and snippets.

@dnaeon
Created December 30, 2012 09:56
Show Gist options
  • Save dnaeon/4411851 to your computer and use it in GitHub Desktop.
Save dnaeon/4411851 to your computer and use it in GitHub Desktop.
#include <sys/param.h>
#include <sys/jail.h>
#include <sys/uio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
int
main(void)
{
struct iovec fbsd_jparams[10];
struct in_addr ip4;
int fbsd_lastjid = 0;
char path[MAXPATHLEN], hostname[MAXHOSTNAMELEN], name[MAXHOSTNAMELEN];
*(const void **) &fbsd_jparams[0].iov_base = "lastjid";
fbsd_jparams[0].iov_len = sizeof("lastjid");
fbsd_jparams[1].iov_base = &fbsd_lastjid;
fbsd_jparams[1].iov_len = sizeof(fbsd_lastjid);
*(const void **) &fbsd_jparams[2].iov_base = "path";
fbsd_jparams[2].iov_len = sizeof("path");
fbsd_jparams[3].iov_base = &path;
fbsd_jparams[3].iov_len = MAXPATHLEN;
*(const void **) &fbsd_jparams[4].iov_base = "host.hostname";
fbsd_jparams[4].iov_len = sizeof("host.hostname");
fbsd_jparams[5].iov_base = &hostname;
fbsd_jparams[5].iov_len = MAXHOSTNAMELEN;
*(const void **) &fbsd_jparams[6].iov_base = "name";
fbsd_jparams[6].iov_len = sizeof("name");
fbsd_jparams[7].iov_base = &name;
fbsd_jparams[7].iov_len = MAXHOSTNAMELEN;
*(const void **) &fbsd_jparams[8].iov_base = "ip4.addr";
fbsd_jparams[8].iov_len = sizeof("ip4.addr");
fbsd_jparams[9].iov_base = &ip4;
fbsd_jparams[9].iov_len = sizeof(struct in_addr);
while ((fbsd_lastjid = jail_get(fbsd_jparams, 10, 0)) > 0) {
printf("JID: %-5d Name: %-20s IP: %-20s Path: %-20s Hostname: %-20s\n", fbsd_lastjid, name, inet_ntoa(ip4), path, hostname);
}
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment