Ejemplo n.º 1
0
Archivo: network.c Proyecto: tcava/bx2
/*
 * NAME: one_to_another
 * USAGE: Convert a p-addr to a Hostname, or a Hostname to a p-addr.
 * PLAIN ENGLISH: Convert "A.B.C.D" to "foo.bar.com" or convert "foo.bar.com"
 *                into "A.B.C.D"
 * ARGS: family - The address family in which to convert (AF_INET/AF_INET6)
 *	 what - Either a Hostname or a p-addr.
 *       retval - If "what" is a Hostname, a place to store the p-addr
 *                If "what" is a p-addr, a place to store the Hostname
 *       size - The length of 'retval' in bytes
 * RETURN VALUE: "retval" is returned upon success
 *		 "empty_string" is returned for any error.
 *
 * NOTES: If "what" is a p-addr and there is no hostname associated with that 
 *        address, that is considered an error and empty_string is returned.
 */
int	one_to_another (int family, const char *what, char *retval, int size)
{
	if (inet_ptohn(family, what, retval, size))
	{
		if (inet_hntop(family, what, retval, size))
		{
			syserr(-1, "one_to_another: both inet_ptohn and "
					"inet_hntop failed (%d,%s)", 
					family, what);
			return -1;
		}
	}

	return 0;
}
Ejemplo n.º 2
0
/*
 * NAME: one_to_another
 * USAGE: Convert a p-addr to a Hostname, or a Hostname to a p-addr.
 * PLAIN ENGLISH: Convert "A.B.C.D" to "foo.bar.com" or convert "foo.bar.com"
 *                into "A.B.C.D"
 * ARGS: family - The address family in which to convert (AF_INET/AF_INET6)
 *	 what - Either a Hostname or a p-addr.
 *       retval - If "what" is a Hostname, a place to store the p-addr
 *                If "what" is a p-addr, a place to store the Hostname
 *       size - The length of 'retval' in bytes
 * RETURN VALUE: "retval" is returned upon success
 *		 "empty_string" is returned for any error.
 *
 * NOTES: If "what" is a p-addr and there is no hostname associated with that 
 *        address, that is considered an error and empty_string is returned.
 */
int	one_to_another (int family, const char *what, char *retval, int size)
{
	/* XXX I wish this wasn't necessary */
	int	old_window_display = window_display;
	window_display = 0;

	if (inet_ptohn(family, what, retval, size))
	{
		if (inet_hntop(family, what, retval, size))
		{
			window_display = old_window_display;
			syserr(-1, "one_to_another: both inet_ptohn and "
					"inet_hntop failed (%d,%s)", 
					family, what);
			return -1;
		}
	}

	window_display = old_window_display;
	return 0;
}
Ejemplo n.º 3
0
/*
 * NAME: one_to_another
 * USAGE: Convert a p-addr to a Hostname, or a Hostname to a p-addr.
 * PLAIN ENGLISH: Convert "A.B.C.D" to "foo.bar.com" or convert "foo.bar.com"
 *                into "A.B.C.D"
 * ARGS: family - The address family in which to convert (AF_INET/AF_INET6)
 *	 what - Either a Hostname or a p-addr.
 *       retval - If "what" is a Hostname, a place to store the p-addr
 *                If "what" is a p-addr, a place to store the Hostname
 *       size - The length of 'retval' in bytes
 * RETURN VALUE: "retval" is returned upon success
 *		 "empty_string" is returned for any error.
 *
 * NOTES: If "what" is a p-addr and there is no hostname associated with that 
 *        address, that is considered an error and empty_string is returned.
 */
char *	one_to_another (int family, const char *what, char *retval, int size)
{
	if (inet_ptohn(family, what, retval, size) == empty_string)
		inet_hntop(family, what, retval, size);
	return retval;
}