示例#1
0
static unsigned int
runtest(cap_channel_t *capdns)
{
	unsigned int result;
	struct hostent *hps, *hpc;
	struct in_addr ip4;
	struct in6_addr ip6;

	result = 0;

	hps = gethostbyname("example.com");
	if (hps == NULL)
		fprintf(stderr, "Unable to resolve %s IPv4.\n", "example.com");
	hpc = cap_gethostbyname(capdns, "example.com");
	if (hostent_compare(hps, hpc))
		result |= GETHOSTBYNAME;

	hps = gethostbyname2("example.com", AF_INET);
	if (hps == NULL)
		fprintf(stderr, "Unable to resolve %s IPv4.\n", "example.com");
	hpc = cap_gethostbyname2(capdns, "example.com", AF_INET);
	if (hostent_compare(hps, hpc))
		result |= GETHOSTBYNAME2_AF_INET;

	hps = gethostbyname2("example.com", AF_INET6);
	if (hps == NULL)
		fprintf(stderr, "Unable to resolve %s IPv6.\n", "example.com");
	hpc = cap_gethostbyname2(capdns, "example.com", AF_INET6);
	if (hostent_compare(hps, hpc))
		result |= GETHOSTBYNAME2_AF_INET6;

	/*
	 * 8.8.178.135 is IPv4 address of freefall.freebsd.org
	 * as of 27 October 2013.
	 */
	inet_pton(AF_INET, "8.8.178.135", &ip4);
	hps = gethostbyaddr(&ip4, sizeof(ip4), AF_INET);
	if (hps == NULL)
		fprintf(stderr, "Unable to resolve %s.\n", "8.8.178.135");
	hpc = cap_gethostbyaddr(capdns, &ip4, sizeof(ip4), AF_INET);
	if (hostent_compare(hps, hpc))
		result |= GETHOSTBYADDR_AF_INET;

	/*
	 * 2001:1900:2254:206c::16:87 is IPv6 address of freefall.freebsd.org
	 * as of 27 October 2013.
	 */
	inet_pton(AF_INET6, "2001:1900:2254:206c::16:87", &ip6);
	hps = gethostbyaddr(&ip6, sizeof(ip6), AF_INET6);
	if (hps == NULL) {
		fprintf(stderr, "Unable to resolve %s.\n",
		    "2001:1900:2254:206c::16:87");
	}
	hpc = cap_gethostbyaddr(capdns, &ip6, sizeof(ip6), AF_INET6);
	if (hostent_compare(hps, hpc))
		result |= GETHOSTBYADDR_AF_INET6;

	return (result);
}
示例#2
0
struct hostent *
cap_gethostbyname(cap_channel_t *chan, const char *name)
{

	return (cap_gethostbyname2(chan, name, AF_INET));
}