コード例 #1
0
ファイル: network.c プロジェクト: carriercomm/epic4
/*
 * NAME: inet_hntop
 * USAGE: Convert a Hostname into a "presentation address" (p-addr)
 * PLAIN ENGLISH: Convert "A.B.C.D" into "foo.bar.com"
 * ARGS: family - The family whose presesentation address format to use
 *	 host - The hostname to convert
 *       retval - A string to store the p-addr (RETURN VALUE)
 *       size - The length of 'retval' in bytes
 * RETURN VALUE: "retval" is returned upon success
 *		 "empty_string" is returned for any error.
 */
char *	inet_hntop (int family, const char *host, char *retval, int size)
{
	int	err;
	SS	buffer;

	((SA *)&buffer)->sa_family = family;
	if ((err = inet_strton(host, NULL, (SA *)&buffer, 0)))
		return empty_string;

	if (inet_ntostr((SA *)&buffer, retval, size, NULL, 0, NI_NUMERICHOST))
		return empty_string;

	return retval;
}
コード例 #2
0
ファイル: network.c プロジェクト: carriercomm/epic4
/*
 * NAME: inet_ptohn
 * USAGE: Convert a "presentation address" (p-addr) into a Hostname
 * PLAIN ENGLISH: Convert "foo.bar.com" into "A.B.C.D"
 * ARGS: family - The family whose presesentation address format to use
 *	 ip - The presentation-address to look up
 *       retval - A string to store the hostname (RETURN VALUE)
 *       size - The length of 'retval' in bytes
 * RETURN VALUE: "retval" is returned upon success
 *		 "empty_string" is returned for any error.
 */
char *	inet_ptohn (int family, const char *ip, char *retval, int size)
{
	int	err;
	SS	buffer;

	((SA *)&buffer)->sa_family = family;
	if ((err = inet_strton(ip, NULL, (SA *)&buffer, AI_NUMERICHOST)))
		return empty_string;

	if (inet_ntostr((SA *)&buffer, retval, size, NULL, 0, NI_NAMEREQD))
		return empty_string;

	return retval;
}
コード例 #3
0
ファイル: network.c プロジェクト: ailin-nemui/epic5
/*
 * NAME: inet_hntop
 * USAGE: Convert a Hostname into a "presentation address" (p-addr)
 * PLAIN ENGLISH: Convert "A.B.C.D" into "foo.bar.com"
 * ARGS: family - The family whose presesentation address format to use
 *	 host - The hostname to convert
 *       retval - A string to store the p-addr (RETURN VALUE)
 *       size - The length of 'retval' in bytes
 * RETURN VALUE: "retval" is returned upon success
 *		 "empty_string" is returned for any error.
 */
int	inet_hntop (int family, const char *host, char *retval, int size)
{
	SS	buffer;

	((SA *)&buffer)->sa_family = family;
	if (inet_strton(host, NULL, (SA *)&buffer, AI_ADDRCONFIG))
	{
		syserr(-1, "inet_hntop: inet_strton(%d,%s) failed", family, host);
		return -1;
	}

	if (inet_ntostr((SA *)&buffer, retval, size, NULL, 0, NI_NUMERICHOST))
	{
		syserr(-1, "inet_hntop: inet_ntostr(%d,%s) failed", family, host);
		return -1;
	}

	return 0;
}
コード例 #4
0
ファイル: network.c プロジェクト: tcava/bx2
/*
 * NAME: inet_ptohn
 * USAGE: Convert a "presentation address" (p-addr) into a Hostname
 * PLAIN ENGLISH: Convert "foo.bar.com" into "A.B.C.D"
 * ARGS: family - The family whose presesentation address format to use
 *	 ip - The presentation-address to look up
 *       retval - A string to store the hostname (RETURN VALUE)
 *       size - The length of 'retval' in bytes
 * RETURN VALUE: "retval" is returned upon success
 *		 "empty_string" is returned for any error.
 */
int	inet_ptohn (int family, const char *ip, char *retval, int size)
{
	SS	buffer;

	((SA *)&buffer)->sa_family = family;
	if (inet_strton(ip, NULL, (SA *)&buffer, AI_NUMERICHOST))
	{
		syserr(-1, "inet_ptohn: inet_strton(%d,%s) failed", family, ip);
		return -1;
	}

	if (inet_ntostr((SA *)&buffer, retval, size, NULL, 0, NI_NAMEREQD))
	{
		syserr(-1, "inet_ptohn: inet_ntostr(%d,%s) failed", family, ip);
		return -1;
	}

	return 0;
}