/*
 * Given a host name, check to see if it points to the local host.
 * If it does, return 1, else return 0.
 *
 * The strategy is this:  translate the host name argument to a list of
 * addresses.  Then compare each of those addresses to the addresses of
 * network interfaces on this host.
 */
int
is_local_host(char *host)
{
	struct hostent	*hp;
	int		err;
	int		flags = AI_DEFAULT;

	if (hp = getipnodebyname((const char *) host, AF_INET, flags, &err))
		if (is_local_if(hp))
			return (1);
	if (hp = getipnodebyname((const char *) host, AF_INET6, flags, &err))
		if (is_local_if(hp))
			return (1);

	return (0);
}
Exemple #2
0
/*
 * Given a host name, check to see if it points to the local host.
 * If it does, return 1, else return 0.
 *
 * The strategy is this:  translate the host name argument to a list of
 * addresses.  Then compare each of those addresses to the addresses of
 * network interfaces on this host.
 */
int
is_local_host(char *host)
{
#ifdef	__sun
	struct hostent	*hp;
	int		err;
#ifndef	AI_DEFAULT
#define	AI_DEFAULT	(AI_V4MAPPED | AI_ADDRCONFIG)
#endif
	int		flags = AI_DEFAULT;

	if (hp = getipnodebyname((const char *) host, AF_INET, flags, &err))
		if (is_local_if(hp))
			return (1);
	if (hp = getipnodebyname((const char *) host, AF_INET6, flags, &err))
		if (is_local_if(hp))
			return (1);

	return (0);
#else	/* !__sun */
	return (1);
#endif	/* !__sun */
}